Next: TC-1 FAQ, Previous: TC-1 Given Code, Up: TC-1 [Contents][Index]
Be sure to read Flex and Bison documentations and tutorials, see Flex & Bison.
Include your own test suite in the tests directory, and hook it
to make check
.
The scanner must be completed to read strings, identifiers etc. and track locations.
std::string
. See the following
code for the basics.
… \" grown_string.clear(); BEGIN SC_STRING; <SC_STRING>{ /* Handling of the strings. Initial " is eaten. */ \" { BEGIN INITIAL; return TOKEN_VAL(STRING, grown_string); } … \\x[0-9a-fA-F]{2} { grown_string.append(1, strtol(yytext + 2, 0, 16)); } … }
misc::symbol
objects, not strings.
Location
to use is produced
by Bison: src/parse/location.hh.
To track of locations, adjust your scanner, use YY_USER_ACTION
and the yylex
prologue:
...
%%
%{
// Everything here is run each time yylex
is invoked.
%}
"if" return TOKEN(IF);
...
%%
...
See the lecture notes, and read the C++ chapter of http://www.gnu.org/software/bison/manual/bison.html, GNU Bison’s documentation. Note that the version being used for the Tiger project may differ from the latest public release, thus students should build their own documentation by running ‘make html’ in the provided Bison tarball.
Pay special attention to its “Complete C++ Example” which is very much like our set up.
%printer
to implement --parse-trace support for
terminals (see TC-1 Samples)
The class TigerParser
drives the lexing and parsing of input file.
Its implementation in src/parse/tiger-parser.cc is incomplete.
The class misc::symbol
keeps a single copy of identifiers, see
lib/misc. Its implementation in lib/misc/symbol.hxx and
lib/misc/symbol.cc is incomplete. Note that running ‘make
check’ in lib/misc exercises lib/misc/test-symbol.cc:
having this unit test pass should be a goal by itself. As a matter of
fact, unit tests were left to help you: once they pass successfully you
may proceed to the rest of the compiler. misc::symbol
’s
implementation is based on misc::unique
, a generic class
implementing the Flyweight design pattern. The definition of this
class, lib/misc/unique.hxx, is also to be completed.
The implementation of the class template misc::variant<T0, Ts...>
lacks a couple of conversion operators that you have to supply.
Next: TC-1 FAQ, Previous: TC-1 Given Code, Up: TC-1 [Contents][Index]