Follow the assignment workflow: fork to GitHub, then clone to your machine.
Alternatively, you can download the code and work locally.
Extend the code to implement the following grammar:
n ∈ 𝒵
e ∈ Expr ::= e + t | e - t | t
t ∈ Term ::= t * f | t / f | f
f ∈ Fact ::= n | ( e )
It's best to add features in the following order:
- subtraction
- multiplication
- division
- parenthetical expressions
When you add a new feature to a language, extend the implemention in the following order:
- Intermediate representation
- Data structures
- Sugar (if you want)
- Parser
- Tests
- Implementation
- Semantics
- Tests
- Implementation
If you finish (or just want to explore things more), here are some options.
Can you give better error-checking and error messages for the parser? For the read-eval-print loop? You could also write one or more semantic checks: a pass over the AST to check for errors, e.g., divide by literal 0.
You could add more features to the language, including
- comparisons, e.g.,
<
,>
,=
, etc. - constants, e.g., built-in names such as
π
ore