In this lab you will add semantic actions to create an abstract syntax tree.
The yacc (bison) program is in the left box and input to that program is in the right box. The lex code is the bottom box.
When you press the button Edit the text and click me, the following will happen.
Step 1 Edit the input, removing all but the first statement, 1 + 1;
.
Click on the button and examine the output. Now (on paper), show a trace of how
the bottom-up parse creates the abstract syntax tree:
The printtree function prints this as: (+ 1 1)
Step 2 Change the yacc/bison grammar so that it recognizes division and add that node to the AST tree.
Run an expression as input to show that the division works.
Step 3
Add the pow()
function (^) to compute the
power of two numbers; include both the syntax (the yacc productions) and semantics (the $$ = stuff)
Again, run an example to show power works.
Step 4 Now read (yes, read it first!) and begin Project Part 3. Have fun!