bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Use locations in the variant example.


From: Akim Demaille
Subject: [PATCH] Use locations in the variant example.
Date: Mon, 02 Mar 2009 15:34:11 -0000

Yes, this obfuscates the point of this example, variants only.  But glr.cc
cannot work (yet?) without locations.  This change makes it easier to use
this example with glr.cc.

        * examples/variant.yy (assert): %define it.
        (locations): Request them.
        (yylex): Bind the location to the stage.
---
 ChangeLog           |   11 +++++++++++
 examples/variant.yy |   18 +++++++++++-------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bf24312..6f8df1a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2009-03-02  Akim Demaille  <address@hidden>
 
+       Use locations in the variant example.
+       Yes, this obfuscates the point of this example, variants only.  But 
glr.cc
+       cannot work (yet?) without locations.  This change makes it easier to 
use
+       this example with glr.cc.
+       
+       * examples/variant.yy (assert): %define it.
+       (locations): Request them.
+       (yylex): Bind the location to the stage.
+
+2009-03-02  Akim Demaille  <address@hidden>
+
        Dub make_TOKEN as a public type interface.
        * data/c++.m4 (b4_symbol_constructor_declare)
        (b4_symbol_constructor_define): New empty stubs.
diff --git a/examples/variant.yy b/examples/variant.yy
index fe5dce0..8471e6e 100644
--- a/examples/variant.yy
+++ b/examples/variant.yy
@@ -1,8 +1,10 @@
 %debug
 %skeleton "lalr1.cc"
 %defines
+%define assert
 %define variant
 %define lex_symbol
+%locations
 
 %code requires // *.hh
 {
@@ -85,26 +87,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
-- 
1.6.2.rc0.35.g1b53





reply via email to

[Prev in Thread] Current Thread [Next in Thread]