Losos is implementation of Lox language in Python 3.
-
Python implementation should be as close as possible to Java version in book (see below)
-
Losos 1.0 - working Python implementation of tree-walk interpreter
-
Losos 1.x - extend Losos so next goals are possible
-
Losos 2.0 - bytecode compiler written in Lox itself
-
Use v1.x to run v2.0 to compile v2.0 source to bytecode
-
Losos VM written in C++
- No tool for generating syntax tree classes (tool/GenerateAst.java).
- [expr.py]
Visitor
abstract class and all expression classes are not nested insideExpr
:BinaryExpr
instead ofExpr.Binary
,ExprVisitor
instead ofExpr.Visitor
, etc. - [parser.py]
_ParseError
class is not nested insideParser
class. - [helpers.py] Whole new file with handy helpers.
- [losos.py]
Losos
class is instantiable and all methods are non-static. - [losos.py]
Reporter
instance instead of_had_error
property (see below). - [losos.py]
main
responsibility is to parse args and callrun_*
methods, so I made them public and movedmain
to__main__.py
. - [losos.py]
run_prompt
method prints welcome message and will exit afterCTRL+Z
followed byRETURN
. - [losos.py]
error
,_report
,runtimeError
, etc moved toReporter
(see below). - [reporter.py] In book, there was
hadError
static boolean flag inside top-levelLox
class. We have instantiableLosos
class, and we just cannot call static error method from it. This is minimal error reporter class. It's instance will be passed around, so classes used insideLosos
(likeParser
andScanner
) can report errors back. Later it may be turned into interface for swapping different error-reporting implementations. For now it's just a way to pass around basic information about encountered errors (just like mentioned flag in book). - Java's
char
type: I added classChar
(inhelpers.py
) for type-hinting single character (see #2 for reasoning). - [runtimeerror.py]
RuntimeError
in Losos is namedLososRuntimeError
to avoid name collision with Python's built-in exception. - Possibly other minor differences.