My attempt at crafting an interpreter for the Lox programming language in Python, following the wonderful Crafting Interpreters (full-text website, GitHub repository) by Robert Nystrom.
For this first implementation, I've decided to keep the code as close as possible to the Java code that Nystrom originally used.
When I get stuck or need inspiration, I'm referring to:
- FallenDeity's LoxInterpreter
- ImAKappa's pylox
- MtScience's PyLox
- plus lots of other Lox implementations
-
- 4.1: The Interpreter Framework
- 4.2: Lexemes and Tokens
- 4.3 Regular Languages and Expressions (no code)
- 4.4: The Scanner Class
- 4.5: Recognizing Lexemes
- 4.6: Longer Lexemes
- 4.7: Reserved Words and Identifiers
-
- 5.1: Context-Free Grammers (no code)
- 5.2: Implementing Syntax Trees
- 5.3: Working with Trees
- 5.4: A (Not Very) Pretty Printer
-
Chapter 6: Parsing Expressions
- 6.1: Ambiguity and the Parsing Game
- 6.2: Recursive Descent Parsing
- 6.3: Syntax Errors
- 6.4: Wiring up the Parser
-
Chapter 7: Evaluating Expressions
- 7.1: Representing Values
- 7.2: Evaluating Expressions
- 7.3: Runtime Errors
- 7.4: Hooking Up the Interpreter
-
Chapter 8: Statements and State
- 8.1: Statements
- 8.2: Global Variables
- 8.3: Environments
- 8.4: Assignment
- 8.5: Scope
-
- 9.1: Turing Machines (Briefly)
- 9.2: Conditional Execution
- 9.3: Logical Operators
- 9.4: While Loops
- 9.5: For Loops
-
- 10.1: Function Calls
- 10.2: Native Functions
- 10.3: Function Declarations
- 10.4: Function Objects
- 10.5: Return Statements
- 10.6: Local Functions and Closures
-
Chapter 11: Resolving and Binding
- 11.1: Static Scope
- 11.2: Semantic Analysis
- 11.3: A Resolver Class
- 11.4: Interpreting Resolved Variables
- 11.5: Resolution Errors
-
- 12.1: OOP and Classes
- 12.2: Class Declarations
- 12.3: Creating Instances
- 12.4: Properties on Instances
- 12.5: Methods on Classes
- 12.6: This
- 12.7: Constructors and Initializers
-
- 13.1: Superclasses and Subclasses
- 13.2: Inheriting Methods
- 13.3: Calling Superclass Methods
- 13.4: Conclusion