2 Copyright (C) 2008-2015, 2018-2021 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>.
21 %define api.token.constructor
22 %define api.value.type variant
23 %define api.location.file none
27 %code requires // *.hh
31 typedef std::vector<std::string> strings_type;
41 // Prototype of the yylex function providing subsequent tokens.
42 static parser::symbol_type yylex ();
44 // Print a vector of strings.
46 operator<< (std::ostream& o, const strings_type& ss)
50 for (strings_type::const_iterator i = ss.begin (), end = ss.end ();
63 to_string (const T& t)
71 %token <::std::string> TEXT;
73 %printer { yyo << '(' << &$$ << ") " << $$; } <*>;
76 %type <::std::string> item;
77 %type <::std::vector<std::string>> list;
82 list { std::cout << $1 << '\n'; }
86 %empty { /* Generates an empty string list */ }
87 | list item { std::swap ($$, $1); $$.push_back ($2); }
92 | NUMBER { $$ = to_string ($1); }
98 // Use nullptr with pre-C++11.
99 #if !defined __cplusplus || __cplusplus < 201103L
102 # define NULLPTR nullptr
105 // The yylex function providing subsequent tokens:
106 // TEXT "I have three numbers for you."
110 // TEXT "And that's all!"
117 static int count = 0;
118 const int stage = count;
120 parser::location_type loc (NULLPTR, stage + 1, stage + 1);
124 return parser::make_TEXT ("I have three numbers for you.", loc);
128 return parser::make_NUMBER (stage, loc);
130 return parser::make_TEXT ("And that's all!", loc);
132 return parser::make_END_OF_FILE (loc);
136 // Mandatory error function
138 parser::error (const parser::location_type& loc, const std::string& msg)
140 std::cerr << loc << ": " << msg << '\n';
148 p.set_debug_level (!!getenv ("YYDEBUG"));