Giter VIP home page Giter VIP logo

lua_interpreter's Introduction

LUA Interpreter

A small interpreter supporting a subset of the LUA programming language.

Tools

This project is using flex for lexing and Bison for parsing.

Build

Dependencies

apt-get install bison
apt-get install flex

Building the project

make

Run

./int file.lua

Visualizing the parse tree

The parse tree can be visualized with Graphviz (apt-get install graphviz), by using the following command:

dot -Tpdf tree.dot -otree.pdf

Supported features

  • Affectation a, b = 3, 4, array[i], array[i+1] = array[i+1], array[i]
  • Control flow if ... then ... elseif ... then ... else ..., while, for
  • Input & output io.write(), print(), io.read()
  • Numerical Arrays a = {1,2,3}
  • Function definition and (recursive) function calls

Examples

Bubble sort:

list = { 5, 6, 1, 2, 14, 2, 15, 6, 7, 8, 97 }
itemCount=#list
repeat
  hasChanged = false
  itemCount=itemCount - 1
  for i = 1, itemCount do
    if list[i] > list[i + 1] then
      list[i], list[i + 1] = list[i + 1], list[i]
      hasChanged = true
    end
  end
until hasChanged == false
for i = 1,#list do
  print (list[i])
end

Fibonacci Sequence:

function fibonacci(n)
    if n<3 then
        return 1
    else
        return fibonacci(n-1) + fibonacci(n-2)
    end
end

io.write(fibonacci(16))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.