13 typedef std::list<std::string> strings_type;
23 // Prototype of the yylex function providing subsequent tokens.
24 static yy::parser::symbol_type yylex ();
26 // Printing a list of strings.
27 // Koening look up will look into std, since that's an std::list.
31 operator<< (std::ostream& o, const strings_type& s)
33 std::copy (s.begin (), s.end (),
34 std::ostream_iterator<strings_type::value_type> (o, "\n"));
39 // Conversion to string.
43 string_cast (const T& t)
51 %token <::std::string> TEXT;
53 %printer { debug_stream () << $$; }
54 <int> <::std::string> <::std::list<std::string>>;
57 %type <::std::string> item;
58 %type <::std::list<std::string>> list;
63 list { std::cout << $1 << std::endl; }
67 /* nothing */ { /* Generates an empty string list */ }
68 | list item { std::swap ($$, $1); $$.push_back ($2); }
72 TEXT { std::swap ($$, $1); }
73 | NUMBER { $$ = string_cast ($1); }
77 // The yylex function providing subsequent tokens:
78 // TEXT "I have three numbers for you:"
82 // TEXT " and that's all!"
86 yy::parser::symbol_type
89 static int stage = -1;
91 yy::parser::location_type loc(0, stage + 1, stage + 1);
95 return yy::parser::make_TEXT ("I have three numbers for you.", loc);
99 return yy::parser::make_NUMBER (stage, loc);
101 return yy::parser::make_TEXT ("And that's all!", loc);
103 return yy::parser::make_END_OF_FILE (loc);
107 // Mandatory error function
109 yy::parser::error (const yy::parser::location_type& loc, const std::string& msg)
111 std::cerr << loc << ": " << msg << std::endl;
118 p.set_debug_level (!!getenv ("YYDEBUG"));