Add tree-building code to your C- parser so that it builds an abstract syntax tree (AST). Use the tree design we discussed in class, which is very similar to this hierarchy. You can find a header file "CMinusAst.h" with the appropriate declarations in the Notes directory. If a program is valid, pretty print the AST to a file as specified below.
Use the Visitor design pattern and a PrintVisitor to print the tree. See Visitor for more on the Visitor pattern.
Take the name of a C- program as a command-line argument. If no argument is specified read from standard input. Use ".cm" as the extension for C- source files.
Output errors as in the previous assignment. If a program is valid, output the AST to text file "X.ast", where "X" is the base name of the source file. If reading from stdin, output the AST to "Default.ast". Note that you will NOT have type information for "var" expressions yet.
For valid programs use PRECISELY the format below with the EXACT same SPACING and SPELLING.
Valid! Writing AST to "InsertionSort.ast"
See InsertionSort.ast for sample output. The tree therein corresponds to the program InsertionSort.cm. Your output should be NEARLY identical.
You may work with a partner. Only ONE team member should submit. Ensure each team member's name is listed in all submitted files.
Submit your driver file "CMinus.cc", "Lexer.cc", "Parser.cc", "CMinusAst.cc", other necessary source files, header file(s), and Makefile. ENSURE your Makefile is named "Makefile" and that it properly builds your program, and that "make clean" removes the executable and all generated files.
N/A