X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/0078681b6bc2d90f74654f85f076fe224a990f07..5a321748e2ec62e10c615e1e557c972c291b10db:/examples/variant.yy
diff --git a/examples/variant.yy b/examples/variant.yy
index 016c4b2a..39a57ba8 100644
--- a/examples/variant.yy
+++ b/examples/variant.yy
@@ -1,8 +1,27 @@
+/*
+ Copyright (C) 2008-2012 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
%debug
%skeleton "lalr1.cc"
%defines
+%define parse.assert
%define variant
%define lex_symbol
+%locations
%code requires // *.hh
{
@@ -46,13 +65,14 @@ typedef std::list strings_type;
}
}
-%token TEXT;
+%token <::std::string> TEXT;
%token NUMBER;
-%printer { debug_stream () << $$; } ;
+%printer { debug_stream () << $$; }
+ <::std::string> <::std::list>;
%token END_OF_FILE 0;
-%type item;
-%type list;
+%type <::std::string> item;
+%type <::std::list> list;
%%
@@ -84,26 +104,28 @@ yy::parser::symbol_type
yylex ()
{
static int stage = -1;
- switch (++stage)
+ ++stage;
+ yy::parser::location_type loc(0, stage + 1, stage + 1);
+ switch (stage)
{
case 0:
- return yy::parser::make_TEXT ("I have three numbers for you.");
+ return yy::parser::make_TEXT ("I have three numbers for you.", loc);
case 1:
case 2:
case 3:
- return yy::parser::make_NUMBER (stage);
+ return yy::parser::make_NUMBER (stage, loc);
case 4:
- return yy::parser::make_TEXT ("And that's all!");
+ return yy::parser::make_TEXT ("And that's all!", loc);
default:
- return yy::parser::make_END_OF_FILE ();
+ return yy::parser::make_END_OF_FILE (loc);
}
}
// Mandatory error function
void
-yy::parser::error (const std::string& message)
+yy::parser::error (const yy::parser::location_type& loc, const std::string& msg)
{
- std::cerr << message << std::endl;
+ std::cerr << loc << ": " << msg << std::endl;
}
int