Expression → AST → code 3 adresses
Analysez une expression arithmétique ou booléenne en AST, émettez du code à trois adresses avec pliage de constantes optionnel, et montrez le programme machine à pile équivalent.
About this tool
A miniature compiler front-end for expressions. Type something like (a + b) * c, press Compile, and read the pipeline: tokens → AST → three-address code → stack machine.
Grammar. Numbers, identifiers, unary +/-/!, binary + - * / %, comparisons == != < > <= >=, and boolean && ||, with the usual precedence (|| lowest, * / % highest). Parentheses override precedence. true/false are 1 and 0.
Three-address code is the classic intermediate form: every instruction is t := a op b (or a unary). Temporaries are fresh t1, t2, …. Constant folding, when enabled, evaluates pure-number subtrees before emission — try (2 + 3) * x + 4 * 5 with folding on and off.
Stack machine is what a bytecode VM or a postfix calculator would run: LOAD/PUSH then operators that pop operands and push the result. The AST is walked post-order, so the stack program is exactly Reverse Polish Notation of the expression.
Why this matters. Real compilers (LLVM, GCC, JVM javac) all go through some form of AST and then a linear IR before register allocation. Seeing the tree and the TAC side by side makes precedence, associativity and temporary naming concrete.
Limits. Expressions only — no statements, assignments, calls, arrays or short-circuit control-flow lowering. Division by zero in folding yields no fold for that node. The AST layout is a simple inorder placement, fine up to a few dozen nodes.