TC-2 Code to Write¶
What is to be done:
- src/parse/parsetiger.yy
- Build the AST
Complete actions to instantiate AST nodes with the driver’s methods accessible using
td.tp_.- Support object-related syntax
Supporting object constructs, an improvement suggested for TC-1 (see TC-1 Improvements), is highly recommended.
- Support metavariable constructs
Augment your scanner and your parser to support the (reserved) keywords
_chunks,_exp,_lvalueand_nametyand implement the corresponding grammar rules (see Language Extensions in Tiger Compiler Reference Manual). The semantic actions of these productions shall use themetavarfunction template to fetch the right AST subtree from theparse::Tweastobject attached to the parsing context (parse::TigerParserinstance).- Implement error recovery.
There should be at least three uses of the token
error. Read the Bison documentation about it.- Use %printer
Extend the use of
%printerto display non-terminals.- Use %destructor
Use
%destructorto reclaim the memory bound to semantic values thrown away during error recovery.- GLR
Change your skeleton to
glr.cc, use the%glr-parserdirective. Thanks to GLR, conflicts (S/R and/or R/R) can be accepted. Use%expectand%expect-rrto specify their number. For information, we have no R/R conflicts, and two S/R: one related to the “big lvalue” issue, and the other to the implementation of the two_castoperators (see Additional Syntactic Specifications in Tiger Compiler Reference Manual).- Chunks
In order to implement easily the type checking of declarations and to simplify following modules, adjust your grammar to parse declarations by chunks. The implementations of these chunks are in
ast::FunctionChunk,ast::MethodChunk,ast::VarChunk, andast::TypeChunk; they are implemented thanks toast::Chunk). Note that anast::VarChunknode appearing in a declaration list shall contain exactly oneast::VarDecobject (see TC-2 Chunks); however, anast::VarChunkused to implement a function’s formal arguments may of course contain several ast::VarDec (one per formal).
- src/parse/tiger-driver.hxx
Implement all methods to create AST nodes on the driver with
make_methods.- src/ast
Complete the abstract syntax tree module: no ‘FIXME:’ should be left. Several files are missing in full. See src/ast/README for additional information on the missing classes.
- src/ast/default-visitor.hxx
Complete the
GenDefaultVisitorclass template. It is the basis for following visitors in the Tiger compiler.- src/ast/object-visitor.hxx
Likewise, complete
GenObjectVisitor. This class template is used to instantiate visitors factoring common code (default traversals of object-related nodes) and serves as a base class ofast::PrettyPrinter(and laterbind::Binder).- src/ast/pretty-printer.*
The
PrettyPrinterclass must be written entirely. It must use themisc::indentfeatures to support indentation.