This is my second take on writing a Lua-To-Python compiler, it includes:
- Lexer
- Parser
- A internal AST representation
- Repl
- Interpeter
python repl.py
- Introduce
;
as a separator - Named functions
- Not defined variables should return
nil
- Modulo operator
-
and
operator -
or
operator -
elseif
statement - Variables with numbers in name
- Iterator for Table using
pairs
/ipairs
-
_G
for globals access -
for
loop -
while
loop -
repeat
loop - Short circuit / tenary operator
- Dot property syntax in Table for string keys
- Numbers beginning with
.
(Ex.5
) - Handle global vs local variables in lua style
- Function calls with single params should not require parens
- Metatable support for tables
- Single and multiline comments
- Variable assignments
- Numbers
- Strings
- Tables
- Addition, multiplication and division
- If statements
- Comparison operators (
==
,>=
,>
,<
,<≠
,~=
) - String concat
..
return
function
declarations (both named and anymous with closures)not
logical operator- Negative values
- Table indexing
- Table count with
#
- Non existing identifiers return nil
- Modulo operator
- A lot of the work here is based on the book Writing A Compiler In Go
- My first take
- A Python Interpreter Written in Python
- Let’s Build A Simple Interpreter. Part 7: Abstract Syntax Trees