https://github.com/hereisjohnny2/lox-lang
https://github.com/hereisjohnny2/lox-lang
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hereisjohnny2/lox-lang
- Owner: hereisjohnny2
- Created: 2025-02-23T23:54:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-24T00:00:33.000Z (over 1 year ago)
- Last Synced: 2025-02-24T00:27:33.206Z (over 1 year ago)
- Language: Python
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lox Language Implementation
This is an implementation in python of the Lox Language, a basic programming language described in the book [Crafiting Interpreters](https://craftinginterpreters.com/).
## Usage
```shell
# Create new venv (for runing the tests)
$ python3 -m venv venv
# Running the REPL
$ python3 main.py
# Running a .lox script
$ python3 main.py
```
## Lox Language Grammar Rules
```
expression -> equality;
equality -> comparison (("!=" | "==") | comparison)*
comparison -> term ((">" | "<" | ">=" | "<=") | term)*
term -> factor (("+" | "-") | factor)*
factor -> unary (("*" | "/") | unary)*
unary -> ("!" | "-") unary | primary;
primary -> NUMBER | STRING | "true" | "false" | "nil" | "(" expression ")";
```
```shell
# AST can be recreated with:
$ python tools/ast_generator.py ./lox
```
## Script Example
```csharp
var str = "lox";
var number = 1234.67;
fun do_something(a, b) {
return a * b;
}
print do_something(number, 2);
print str;
```
## Tests
```shell
$ pytest
```