A small interpreter supporting a subset of the LUA programming language.
This project is using flex for lexing and Bison for parsing.
apt-get install bison
apt-get install flex
make
./int file.lua
The parse tree can be visualized with Graphviz (apt-get install graphviz
), by using the following command:
dot -Tpdf tree.dot -otree.pdf
- 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
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
function fibonacci(n)
if n<3 then
return 1
else
return fibonacci(n-1) + fibonacci(n-2)
end
end
io.write(fibonacci(16))