CMSC 435: Assignment 6
Overview
Add tree-building code to your C- parser so that it builds an abstract syntax tree (AST). Use the tree design defined in Ast.hh. If a program is valid, pretty print the AST to a file as specified below.
Use the Visitor Pattern
and a PrintVisitor to print the tree. See Visitor for
more on the design pattern, and specifically, std::visit
for how we will implement the pattern in C++.
Input Specification
Take the name of a C- program as a command-line argument. If no
argument is specified read from standard input (this is NECESSARY for
the grading scripts). Use .cm as the extension for C-
source files. You may add zero or more optional flags.
> ./CMinus [ --flags ]* [ <Program.cm> ]
Output Specification
Output “Valid!” if the program is a valid sentence in C-.
Additionally, output the AST to a text file Program.ast,
where Program is the base name of the source file. If you
are reading from stdin, output the AST to
Default.ast. If there are errors, output them as you did
before. Do NOT produce an AST file if there are errors.
Use PRECISELY the format below with the EXACT same SPACING and SPELLING.
> ./CMinus Gcd.cm
Valid!
AST output: Gcd.ast
For outputting the AST, use PRECISELY the format below with the EXACT same SPACING and SPELLING.
See InsertionSort.ast. The tree therein corresponds to the program InsertionSort.cm.
Logistics
You may work with a partner. Only ONE team member should submit. Ensure each team member’s name is listed in all submitted files.
Submission
Submit ALL necessary source files and a Makefile. ENSURE
your Makefile is named Makefile, properly builds your
program, and that make clean removes all generated
files.
Hints
N/A
Gary M. Zoppetti, Ph.D.