Be sure to read Flex and Bison documentations and tutorials, see Flex & Bison.
std::string
. See the following
code for the basics.
... \" yylval->str = new std::string (); BEGIN SC_STRING; <SC_STRING>{ /* Handling of the strings. Initial " is eaten. */ \" { BEGIN INITIAL; return STRING; } ... \\x[0-9a-fA-F]{2} { yylval->str->append (1, strtol (yytext + 2, 0, 16)); } ... }
symbol::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 IF;
...
%%
...
See the lecture notes, and have a look at the scanner and parser chapters of this draft.
yy::Parser::print_
to implement --parse-trace
support (voir T1 Samples). yy::Parser::print_
is the C++
equivalent of the yyprint
feature for C parsers, see the Bison
documentation. Pay special attention to the display of strings and
identifiers.
symbol::Symbol
keeps a single copy of identifiers, see
src/symbol. Its implementation in src/symbol/symbol.hxx is
incomplete.
The most delicate part is the constructor symbol::Symbol::Symbol
(const std::string &s)
: just bare in mind that (i) you must make sure
that the string s is inserted in the set, and (ii) save in this
new symbol::Symbol
object a reference to this inserted string.
Carefully read the documentation of std::set::insert
.