X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/eaca4c1103000fe906bd1ae031cf91ce37f83ce2..ca2a6d1587f421a6c58b9f80cc8d6b983c9a62dc:/src/parse-gram.y diff --git a/src/parse-gram.y b/src/parse-gram.y index 453c35f8..d588dfa8 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -1,7 +1,7 @@ %{/* Bison Grammar Parser -*- C -*- - Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software - Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 + Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -118,7 +118,6 @@ static char const *char_name (char); %token PERCENT_DPREC "%dprec" %token PERCENT_MERGE "%merge" - /*----------------------. | Global Declarations. | `----------------------*/ @@ -151,6 +150,8 @@ static char const *char_name (char); ; %token BRACED_CODE "{...}" +%token BRACED_PREDICATE "%?{...}" +%token BRACKETED_ID "[identifier]" %token CHAR "char" %token EPILOGUE "epilogue" %token EQUAL "=" @@ -163,7 +164,6 @@ static char const *char_name (char); %token TAG "" %token TAG_ANY "<*>" %token TAG_NONE "<>" -%token BRACKETED_ID "[identifier]" %type CHAR %printer { fputs (char_name ($$), stderr); } CHAR @@ -171,28 +171,29 @@ static char const *char_name (char); /* braceless is not to be used for rule or symbol actions, as it calls code_props_plain_init. */ %type STRING "%{...%}" EPILOGUE braceless content.opt -%type "{...}" +%type "{...}" "%?{...}" %printer { fputs (quotearg_style (c_quoting_style, $$), stderr); } STRING %printer { fprintf (stderr, "{\n%s\n}", $$); } braceless content.opt "{...}" "%{...%}" EPILOGUE -%type TAG ID ID_COLON BRACKETED_ID PERCENT_FLAG variable -%type named_ref.opt -%printer { fputs ($$, stderr); } ID variable +%type BRACKETED_ID ID ID_COLON PERCENT_FLAG TAG variable +%printer { fputs ($$, stderr); } +%printer { fprintf (stderr, "[%s]", $$); } BRACKETED_ID %printer { fprintf (stderr, "%s:", $$); } ID_COLON %printer { fprintf (stderr, "%%%s", $$); } PERCENT_FLAG %printer { fprintf (stderr, "<%s>", $$); } TAG %type INT -%printer { fprintf (stderr, "%d", $$); } INT +%printer { fprintf (stderr, "%d", $$); } -%type id id_colon symbol symbol.prec string_as_id -%printer { fprintf (stderr, "%s", $$->tag); } id symbol string_as_id +%type id id_colon string_as_id symbol symbol.prec +%printer { fprintf (stderr, "%s", $$->tag); } %printer { fprintf (stderr, "%s:", $$->tag); } id_colon %type precedence_declarator %type symbols.1 symbols.prec generic_symlist generic_symlist_item +%type named_ref.opt /*---------. | %param. | @@ -236,6 +237,7 @@ static char const *char_name (char); CASE(parse, parse-param); CASE(both, param); #undef CASE + case param_none: aver (false); break; } } ; @@ -584,7 +586,9 @@ rhs: | 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); } + { grammar_current_rule_action_append ($2, @2, $3, false); } +| rhs "%?{...}" + { grammar_current_rule_action_append ($2, @2, NULL, true); } | rhs "%prec" symbol { grammar_current_rule_prec_set ($3, @3); } | rhs "%dprec" INT @@ -599,7 +603,6 @@ named_ref.opt: BRACKETED_ID { $$ = named_ref_new($1, @1); } ; - /*---------------------------. | variable and content.opt. | `---------------------------*/ @@ -727,23 +730,25 @@ add_param (param_type type, char *decl, location loc) "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "_" "0123456789"; + char const *name_start = NULL; - char *p; - - /* Stop on last actual character. */ - for (p = decl; p[1]; p++) - if ((p == decl - || ! memchr (alphanum, p[-1], sizeof alphanum)) - && memchr (alphanum, p[0], sizeof alphanum - 10)) - name_start = p; - - /* Strip the surrounding '{' and '}', and any blanks just inside - the braces. */ - while (*--p == ' ' || *p == '\t') - continue; - p[1] = '\0'; - while (*++decl == ' ' || *decl == '\t') - continue; + { + char *p; + /* Stop on last actual character. */ + for (p = decl; p[1]; p++) + if ((p == decl + || ! memchr (alphanum, p[-1], sizeof alphanum)) + && memchr (alphanum, p[0], sizeof alphanum - 10)) + name_start = p; + + /* Strip the surrounding '{' and '}', and any blanks just inside + the braces. */ + while (*--p == ' ' || *p == '\t') + continue; + p[1] = '\0'; + while (*++decl == ' ' || *decl == '\t') + continue; + } if (! name_start) complain_at (loc, _("missing identifier in parameter declaration"));