11 typedef std::list<std::string> strings_type;
21 // Prototype of the yylex function providing subsequent tokens.
22 static yy::parser::symbol_type yylex ();
24 // Printing a list of strings.
25 // Koening look up will look into std, since that's an std::list.
29 operator<< (std::ostream& o, const strings_type& s)
31 std::copy (s.begin (), s.end (),
32 std::ostream_iterator<strings_type::value_type> (o, "\n"));
37 // Conversion to string.
41 string_cast (const T& t)
49 %token <std::string> TEXT;
51 %printer { debug_stream () << $$; } <int> <std::string> <strings_type>;
54 %type <std::string> item;
55 %type <strings_type> list;
60 list { std::cout << $1 << std::endl; }
64 /* nothing */ { /* Generates an empty string list */ }
65 | list item { std::swap ($$, $1); $$.push_back ($2); }
69 TEXT { std::swap ($$, $1); }
70 | NUMBER { $$ = string_cast ($1); }
74 // The yylex function providing subsequent tokens:
75 // TEXT "I have three numbers for you:"
79 // TEXT " and that's all!"
83 yy::parser::symbol_type
86 static int stage = -1;
90 return yy::parser::make_TEXT ("I have three numbers for you.");
94 return yy::parser::make_NUMBER (stage);
96 return yy::parser::make_TEXT ("And that's all!");
98 return yy::parser::make_END_OF_FILE ();
102 // Mandatory error function
104 yy::parser::error (const std::string& message)
106 std::cerr << message << std::endl;
113 p.set_debug_level (!!getenv ("YYDEBUG"));