Book Examples Modified for Python
The code snippets below are my adaptations of the tree walking example files from chapter 3 in The Book
to make them work with Python.
Notes
- Set language=Python option in both .g files
- In Eval.g I had to change references to $INT.text and $ID.text to $INT.getText() and $ID.getText() respectively
- In Eval.g I had to use @init{} instead of @members{} action to initialize memory variable
- In Expr.g I had to use self.skip() instead of just skip()
- Based Test.py on example from Antlr3PythonTarget
Expr.g
Eval.g
Test.py