This question evaluates understanding of language design and implementation skills, including lexical analysis, parsing into an AST, expression evaluation with operator precedence and unary operators, variable assignment semantics, and runtime error reporting.
Design and implement a mini compiler / interpreter for a small expression language.
You are given a program as a string (possibly multiple lines). The language supports:
42
x = 3 + 4
+ - * /
with standard precedence and parentheses
-x
print(expr)
statement that outputs an integer
Build a pipeline that:
Program:
x = 10
print(x + 2 * 3)
print(-(x - 7))
Output:
16
-3