]> git.saurik.com Git - bison.git/blobdiff - src/parse-gram.y
Pacify "gcc -Wunused" for the input function from Flex.
[bison.git] / src / parse-gram.y
index f5015e2487663a51f39f0229bb39b042041c8b88..6f9ac83b399040695070e9ecf09dc16de0cc0a15 100644 (file)
@@ -27,6 +27,7 @@
 #include "getargs.h"
 #include "gram.h"
 #include "muscle-tab.h"
+#include "named-ref.h"
 #include "quotearg.h"
 #include "reader.h"
 #include "symlist.h"
@@ -63,6 +64,7 @@ static symbol_class current_class = unknown_sym;
 static uniqstr current_type = NULL;
 static symbol *current_lhs;
 static location current_lhs_location;
+static named_ref *current_lhs_named_ref;
 static int current_prec = 0;
 
 #define YYTYPE_INT16 int_fast16_t
@@ -76,7 +78,7 @@ static int current_prec = 0;
 %defines
 %locations
 %pure-parser
-%error-verbose
+%define parse.error "verbose"
 %name-prefix="gram_"
 %expect 0
 
@@ -98,6 +100,7 @@ static int current_prec = 0;
   assoc assoc;
   uniqstr uniqstr;
   unsigned char character;
+  named_ref *named_ref;
 };
 
 /* Define the tokens together with their human representation.  */
@@ -131,6 +134,7 @@ static int current_prec = 0;
   PERCENT_DEFAULT_PREC    "%default-prec"
   PERCENT_DEFINE          "%define"
   PERCENT_DEFINES         "%defines"
+  PERCENT_ERROR_VERBOSE   "%error-verbose"
   PERCENT_EXPECT          "%expect"
   PERCENT_EXPECT_RR      "%expect-rr"
   PERCENT_FLAG            "%<flag>"
@@ -167,6 +171,7 @@ static int current_prec = 0;
 %token TAG             "<tag>"
 %token TAG_ANY         "<*>"
 %token TAG_NONE        "<>"
+%token BRACKETED_ID    "[identifier]"
 
 %type <character> CHAR
 %printer { fputs (char_name ($$), stderr); } CHAR
@@ -180,7 +185,8 @@ static int current_prec = 0;
 %printer { fprintf (stderr, "{\n%s\n}", $$); }
         braceless content.opt "{...}" "%{...%}" EPILOGUE
 
-%type <uniqstr> TAG ID ID_COLON PERCENT_FLAG variable
+%type <uniqstr> TAG ID ID_COLON BRACKETED_ID PERCENT_FLAG variable
+%type <named_ref> named_ref.opt
 %printer { fputs ($$, stderr); } ID variable
 %printer { fprintf (stderr, "%s:", $$); } ID_COLON
 %printer { fprintf (stderr, "%%%s", $$); } PERCENT_FLAG
@@ -229,7 +235,8 @@ prologue_declaration:
     }
 | "%define" variable content.opt
     {
-      muscle_percent_define_insert ($2, @2, $3);
+      muscle_percent_define_insert ($2, @2, $3,
+                                    MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
     }
 | "%defines"                       { defines_flag = true; }
 | "%defines" STRING
@@ -237,6 +244,11 @@ prologue_declaration:
       defines_flag = true;
       spec_defines_file = xstrdup ($2);
     }
+| "%error-verbose"
+    {
+      muscle_percent_define_insert ("parse.error", @1, "verbose",
+                                    MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
+    }
 | "%expect" INT                    { expected_sr_conflicts = $2; }
 | "%expect-rr" INT                { expected_rr_conflicts = $2; }
 | "%file-prefix" STRING            { spec_file_prefix = $2; }
@@ -504,7 +516,8 @@ rules_or_grammar_declaration:
 ;
 
 rules:
-  id_colon { current_lhs = $1; current_lhs_location = @1; } rhses.1
+  id_colon named_ref.opt { current_lhs = $1; current_lhs_location = @1;
+    current_lhs_named_ref = $2; } rhses.1
 ;
 
 rhses.1:
@@ -515,11 +528,12 @@ rhses.1:
 
 rhs:
   /* Nothing.  */
-    { grammar_current_rule_begin (current_lhs, current_lhs_location); }
-| rhs symbol
-    { grammar_current_rule_symbol_append ($2, @2); }
-| rhs "{...}"
-    { grammar_current_rule_action_append ($2, @2); }
+    { grammar_current_rule_begin (current_lhs, current_lhs_location,
+                                 current_lhs_named_ref); }
+| rhs symbol named_ref.opt
+    { grammar_current_rule_symbol_append ($2, @2, $3); }
+| rhs "{...}" named_ref.opt
+    { grammar_current_rule_action_append ($2, @2, $3); }
 | rhs "%prec" symbol
     { grammar_current_rule_prec_set ($3, @3); }
 | rhs "%dprec" INT
@@ -528,6 +542,12 @@ rhs:
     { grammar_current_rule_merge_set ($3, @3); }
 ;
 
+named_ref.opt:
+  /* Nothing. */ { $$ = 0; }
+|
+  BRACKETED_ID   { $$ = named_ref_new($1, @1); }
+;
+
 
 /*---------------------------.
 | variable and content.opt.  |