https://github.com/marteinn/lua-interpreter-in-python
A Lua interpreter written in python.
https://github.com/marteinn/lua-interpreter-in-python
lua mypy python
Last synced: 10 months ago
JSON representation
A Lua interpreter written in python.
- Host: GitHub
- URL: https://github.com/marteinn/lua-interpreter-in-python
- Owner: marteinn
- Created: 2019-09-09T18:44:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-26T19:26:16.000Z (over 6 years ago)
- Last Synced: 2025-03-24T12:21:37.480Z (10 months ago)
- Topics: lua, mypy, python
- Language: Python
- Homepage:
- Size: 116 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lua interpreter in Python
This is my second take on writing a Lua-To-Python compiler, it includes:
- [x] Lexer
- [x] Parser
- [x] A internal AST representation
- [x] Repl
- [x] Interpeter
## Running repl
- `python repl.py`
## TODO
- [x] Introduce `;` as a separator
- [x] Named functions
- [x] Not defined variables should return `nil`
- [x] Modulo operator
- [x] `and` operator
- [x] `or` operator
- [ ] `elseif` statement
- [x] 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
## Supports
- 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
## References
- A lot of the work here is based on the book [Writing A Compiler In Go](https://compilerbook.com/)
- [My first take](https://github.com/marteinn/Lua-To-Python)
- [A Python Interpreter Written in Python](https://www.aosabook.org/en/500L/a-python-interpreter-written-in-python.html)
- [Let’s Build A Simple Interpreter. Part 7: Abstract Syntax Trees](https://ruslanspivak.com/lsbasi-part7/)