[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dubious features
From: |
Akim Demaille |
Subject: |
Re: Dubious features |
Date: |
Thu, 08 Jun 2006 14:17:27 +0200 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) |
>>> "Akim" == Akim Demaille <address@hidden> writes:
> But it gives an easy mean to implement this bug: /%union[^{]*/. I
> suppose that I can accumulate the various values if there are several
> unions, after all GIGO is a sane principle :)
Here is my proposal.
2006-06-08 Akim Demaille <address@hidden>
* src/scan-gram.l: No longer "parse" things after `%union' until
`{'. Rather, implement the simpler behavior of Solaris Yacc:
match a single token from '%union[^{]*'.
(SC_PRE_CODE, token_type): Remove.
* src/parse-gram.y: Adjust.
Index: src/parse-gram.y
===================================================================
RCS file: /cvsroot/bison/bison/src/parse-gram.y,v
retrieving revision 1.75
diff -u -u -r1.75 parse-gram.y
--- src/parse-gram.y 6 Jun 2006 16:40:06 -0000 1.75
+++ src/parse-gram.y 8 Jun 2006 12:12:39 -0000
@@ -113,7 +113,7 @@
%token PERCENT_DESTRUCTOR "%destructor"
%token PERCENT_PRINTER "%printer"
-%token PERCENT_UNION "%union {...}"
+%token PERCENT_UNION "%union"
%token PERCENT_LEFT "%left"
%token PERCENT_RIGHT "%right"
@@ -170,13 +170,13 @@
%type <chars> STRING string_content
"{...}"
- "%union {...}"
+ "%union"
PROLOGUE EPILOGUE
%printer { fprintf (stderr, "\"%s\"", $$); }
STRING string_content
%printer { fprintf (stderr, "{\n%s\n}", $$); }
"{...}"
- "%union {...}"
+ "%union"
PROLOGUE EPILOGUE
%type <uniqstr> TYPE
%printer { fprintf (stderr, "<%s>", $$); } TYPE
@@ -252,9 +252,9 @@
{
grammar_start_symbol_set ($2, @2);
}
-| "%union {...}"
+| "%union" "{...}"
{
- char const *body = $1;
+ char const *body = $2;
if (typed)
{
@@ -266,7 +266,8 @@
}
typed = true;
- muscle_code_grow ("stype", body, @1);
+ muscle_code_grow ("stype", $1, @1);
+ muscle_code_grow ("stype", body, @2);
}
| "%destructor" "{...}" symbols.1
{
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.90
diff -u -u -r1.90 scan-gram.l
--- src/scan-gram.l 7 Jun 2006 21:17:35 -0000 1.90
+++ src/scan-gram.l 8 Jun 2006 12:12:39 -0000
@@ -88,9 +88,6 @@
/* A identifier was just read in directives/rules. Special state
to capture the sequence `identifier :'. */
%x SC_AFTER_IDENTIFIER
- /* A keyword that should be followed by some code was read (e.g.
- %printer). */
-%x SC_PRE_CODE
/* Three types of user code:
- prologue (code between `%{' `%}' in the first section, before %%);
@@ -124,9 +121,6 @@
/* Parent context state, when applicable. */
int context_state IF_LINT (= 0);
- /* Token type to return, when applicable. */
- int token_type IF_LINT (= 0);
-
/* Location of most recent identifier, when applicable. */
location id_loc IF_LINT (= empty_location);
@@ -145,7 +139,7 @@
| Scanning white space. |
`-----------------------*/
-<INITIAL,SC_AFTER_IDENTIFIER,SC_PRE_CODE>
+<INITIAL,SC_AFTER_IDENTIFIER>
{
/* Comments and white space. */
"," warn_at (*loc, _("stray `,' treated as white space"));
@@ -175,17 +169,17 @@
"%default"[-_]"prec" return PERCENT_DEFAULT_PREC;
"%define" return PERCENT_DEFINE;
"%defines" return PERCENT_DEFINES;
- "%destructor" /* FIXME: Remove once %union handled
differently. */ token_type = BRACED_CODE; return PERCENT_DESTRUCTOR;
+ "%destructor" return PERCENT_DESTRUCTOR;
"%dprec" return PERCENT_DPREC;
"%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE;
"%expect" return PERCENT_EXPECT;
"%expect"[-_]"rr" return PERCENT_EXPECT_RR;
"%file-prefix" return PERCENT_FILE_PREFIX;
"%fixed"[-_]"output"[-_]"files" return PERCENT_YACC;
- "%initial-action" /* FIXME: Remove once %union handled differently.
*/ token_type = BRACED_CODE; return PERCENT_INITIAL_ACTION;
+ "%initial-action" return PERCENT_INITIAL_ACTION;
"%glr-parser" return PERCENT_GLR_PARSER;
"%left" return PERCENT_LEFT;
- "%lex-param" /* FIXME: Remove once %union handled differently. */
token_type = BRACED_CODE; return PERCENT_LEX_PARAM;
+ "%lex-param" return PERCENT_LEX_PARAM;
"%locations" return PERCENT_LOCATIONS;
"%merge" return PERCENT_MERGE;
"%name"[-_]"prefix" return PERCENT_NAME_PREFIX;
@@ -195,9 +189,9 @@
"%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
"%nterm" return PERCENT_NTERM;
"%output" return PERCENT_OUTPUT;
- "%parse-param" /* FIXME: Remove once %union handled differently. */
token_type = BRACED_CODE; return PERCENT_PARSE_PARAM;
+ "%parse-param" return PERCENT_PARSE_PARAM;
"%prec" return PERCENT_PREC;
- "%printer" /* FIXME: Remove once %union handled differently.
*/ token_type = BRACED_CODE; return PERCENT_PRINTER;
+ "%printer" return PERCENT_PRINTER;
"%pure"[-_]"parser" return PERCENT_PURE_PARSER;
"%require" return PERCENT_REQUIRE;
"%right" return PERCENT_RIGHT;
@@ -207,7 +201,13 @@
"%token" return PERCENT_TOKEN;
"%token"[-_]"table" return PERCENT_TOKEN_TABLE;
"%type" return PERCENT_TYPE;
- "%union" token_type = PERCENT_UNION; BEGIN SC_PRE_CODE;
+ "%union"[^{]* {
+ obstack_grow (&obstack_for_string,
+ yytext + 6, yyleng - 6);
+ STRING_FINISH;
+ val->chars = last_string;
+ return PERCENT_UNION;
+ }
"%verbose" return PERCENT_VERBOSE;
"%yacc" return PERCENT_YACC;
@@ -248,7 +248,6 @@
if (current_rule && current_rule->action)
grammar_midrule_action ();
STRING_GROW;
- token_type = BRACED_CODE;
braces_level = 0;
code_start = loc->start;
BEGIN SC_BRACED_CODE;
@@ -501,45 +500,11 @@
}
- /*---------------------------------------------------------------.
- | Scanning after %union etc., possibly followed by white space. |
- | For %union only, allow arbitrary C code to appear before the |
- | following brace, as an extension to POSIX. |
- `---------------------------------------------------------------*/
-
-<SC_PRE_CODE>
-{
- . {
- bool valid = yytext[0] == '{' || token_type == PERCENT_UNION;
- scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0);
- yyless (0);
- if (valid)
- {
- braces_level = -1;
- code_start = loc->start;
- BEGIN SC_BRACED_CODE;
- }
- else
- {
- complain_at (*loc, _("missing `{' in %s"),
- token_name (token_type));
- obstack_sgrow (&obstack_for_string, "{}");
- STRING_FINISH;
- val->chars = last_string;
- BEGIN INITIAL;
- return token_type;
- }
- }
-
- <<EOF>> unexpected_eof (scanner_cursor, "{}"); BEGIN INITIAL;
-}
-
-
- /*---------------------------------------------------------------.
- | Scanning some code in braces (%union and actions). The initial |
- | "{" is already eaten. |
- `---------------------------------------------------------------*/
+ /*-----------------------------------------------------------.
+ | Scanning some code in braces (actions). The initial "{" is |
+ | already eaten. |
+ `-----------------------------------------------------------*/
<SC_BRACED_CODE>
{
@@ -556,7 +521,7 @@
val->chars = last_string;
gram_last_braced_code_loc = *loc;
BEGIN INITIAL;
- return token_type;
+ return BRACED_CODE;
}
}
- Re: Dubious features, (continued)
- Re: Dubious features, Akim Demaille, 2006/06/07
- Re: Dubious features, Joel E. Denny, 2006/06/07
- Re: Dubious features, Akim Demaille, 2006/06/07
- Re: Dubious features, Joel E. Denny, 2006/06/07
- Re: Dubious features, Paul Eggert, 2006/06/07
- Re: Dubious features, Joel E. Denny, 2006/06/07
Re: Dubious features, Paul Eggert, 2006/06/07
- Re: Dubious features, Akim Demaille, 2006/06/08
- Re: Dubious features, Paul Eggert, 2006/06/08
- Re: Dubious features, Akim Demaille, 2006/06/08
- Re: Dubious features,
Akim Demaille <=
- Re: Dubious features, Paul Eggert, 2006/06/08
- Re: Dubious features, Akim Demaille, 2006/06/08
- Re: Dubious features, Paul Eggert, 2006/06/08
- Re: Dubious features, Akim Demaille, 2006/06/10
- Re: Dubious features, Paul Eggert, 2006/06/11
- Re: %union ... {, Akim Demaille, 2006/06/16
- Re: %union ... {, Paul Eggert, 2006/06/16
- Re: %union ... {, Akim Demaille, 2006/06/17
- Re: %union ... {, Paul Eggert, 2006/06/19
- Re: %union ... {, Hans Aberg, 2006/06/19