Skip to content

Instantly share code, notes, and snippets.

@ilyarudyak
Last active August 1, 2016 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyarudyak/ab4eed87244b24826bbd93f277d1ea48 to your computer and use it in GitHub Desktop.
Save ilyarudyak/ab4eed87244b24826bbd93f277d1ea48 to your computer and use it in GitHub Desktop.
- extern YYSTYPE cool_yylval. Its type is defined in the same file cool-parse.h. This is our global union where
we store attributes. We use cool_yylval.symbol for numbers, identifiers and strings, cool_yylval.boolean for booleans.
Defined in lextext.cc (contains the main function which will call your lexer and print out the tokens that it returns).
- extern int curr_lineno. "Your scanner should maintain the variable curr lineno that indicates which line in
the source text is currently being scanned. This feature will aid the parser in printing useful error messages."
(see 4.4 of PA1.pdf). Defined in lextext.cc.
You should advanced it when deal with \n - in comments, strings and catch all section:
curr_lineno++;
- stringtable, inttable, idtable. These are String tables described in A Tour of the Cool Support Code, 3.
The are defined in stringtab.cc (they are all from StringTable class):
IdTable idtable;
IntTable inttable;
StrTable stringtable;
we use it like this:
cool_yylval.symbol = inttable.add_string(yytext);
- char *yytext. Holds the text of the current token. It may be modified but not lengthened (you cannot
append characters to the end). See here: http://flex.sourceforge.net/manual/User-Values.html#User-Values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment