This is a python implemenation of the lox langauge as described in the book Crafting Interpreters by Robert Nystrom. In particular the first version from part 2.
- Line comments implemented (
// comment) - Expressions implemented
- Assignment (
IDENTIFIER = Expr) - Binary
- Addition or Concatenation (
Expr + Expr) - Subtraction (
Expr - Expr) - Multiplication (
Expr * Expr) - Division (
Expr / Expr) - Comparisons
- Equality (
Expr == Expr) - Inequality (
Expr != Expr) - Greater (
Expr > Expr) - Greater or Equal (
Expr >= Expr) - Less (
Expr < Expr) - Less or Equal (
Expr <= Expr)
- Equality (
- Addition or Concatenation (
- Call (
Expr()) - Get (
IDENTIFIER.IDENTIFIER) - Groupings (
(Expr)) - Literals (
NUMBER,STRING,IDENTIFIER,true,false,"nil") - Logical
- And (
Expr and Expr) - Or (
Expr or Expr)
- And (
- Set (
Expr = Expr) - Super (
super.IDENTIFIER) - This (
this.IDENTIFIER) - Unary
- Negation (
-Expr) - Logical Inverse (
!Expr)
- Negation (
- Variable (
IDENTIFIER)
- Assignment (
- Statements implemented
- Block (
{Stmt}) - Class (
class IDENTIFIER {Stmt}) - Expression (
Expr;) - Function (
fun IDENTIFIER {Stmt}) - If (
if (Expr) {Stmt} else {Stmt}) - Print (
print Expr;) - Return (
return Expr;) - Var (
var IDENTIFIER;) - While (
while (Expr) {Stmt})- For (
for (INITIALIZER;CONDITION;INCREMENT) {Stmt}) (Syntactic sugar around a while loop)
- For (
- Block (
- Scopes implemented
- Global
- Dynamic
- Local
- Closure
plox: a lox interpreter written in python
Usage:
$ plox [OPTIONS] COMMAND [ARGS]...Options:
--install-completion: Install completion for the current shell.--show-completion: Show completion for the current shell, to copy it or customize the installation.--help: Show this message and exit.
Commands:
interpret: Execute a lox script.parse: Parse a lox script and display the...repl: Enter an interactive REPL for lox scripting.tokenize: Tokenize a lox script and display the...
Execute a lox script.
Usage:
$ plox interpret [OPTIONS] FILENAMEArguments:
FILENAME: File containing the lox script to be executed. [required]
Options:
--help: Show this message and exit.
Parse a lox script and display the abstract syntax tree produced from the parsing pass.
Usage:
$ plox parse [OPTIONS] FILENAMEArguments:
FILENAME: File containing the lox script to be parsed. [required]
Options:
--help: Show this message and exit.
Enter an interactive REPL for lox scripting.
Usage:
$ plox repl [OPTIONS]Options:
--help: Show this message and exit.
Tokenize a lox script and display the results of the lexing pass.
Usage:
$ plox tokenize [OPTIONS] FILENAMEArguments:
FILENAME: File containing the lox script to be tokenized. [required]
Options:
--help: Show this message and exit.