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 () << $$; }
52 <int> <::std::string> <::std::list<std::string>>;
55 %type <::std::string> item;
56 %type <::std::list<std::string>> list;
61 list { std::cout << $1 << std::endl; }
65 /* nothing */ { /* Generates an empty string list */ }
66 | list item { std::swap ($$, $1); $$.push_back ($2); }
70 TEXT { std::swap ($$, $1); }
71 | NUMBER { $$ = string_cast ($1); }
75 // The yylex function providing subsequent tokens:
76 // TEXT "I have three numbers for you:"
80 // TEXT " and that's all!"
84 yy::parser::symbol_type
87 static int stage = -1;
91 return yy::parser::make_TEXT ("I have three numbers for you.");
95 return yy::parser::make_NUMBER (stage);
97 return yy::parser::make_TEXT ("And that's all!");
99 return yy::parser::make_END_OF_FILE ();
103 // Mandatory error function
105 yy::parser::error (const std::string& message)
107 std::cerr << message << std::endl;
114 p.set_debug_level (!!getenv ("YYDEBUG"));