From 7ec2d4cd3932bfba78e9fbd52509d9f80b61c8ef Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 12 Nov 2002 08:26:38 +0000 Subject: [PATCH] * src/scan-gram.l, src/reader.h (scanner_last_string_free): Restore. * src/scan-gram.l (last_string): Is global to the file, not to yylex. * src/parse-gram.y (input): Don't append the epilogue here, (epilogue.opt): do it here, and free the scanner's obstack. * src/reader.c (epilogue_set): Rename as... (epilogue_augment): this. * data/c.m4 (b4_epilogue): Defaults to empty. --- ChangeLog | 12 ++++++++++++ data/c.m4 | 8 ++++++++ src/parse-gram.c | 27 ++++++++++++--------------- src/parse-gram.y | 14 ++++++++------ src/reader.c | 7 +++++-- src/reader.h | 3 ++- src/scan-gram.l | 12 +++++++++--- 7 files changed, 56 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index a715cc9..112d663 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2002-11-12 Akim Demaille + * src/scan-gram.l, src/reader.h (scanner_last_string_free): + Restore. + * src/scan-gram.l (last_string): Is global to the file, not to + yylex. + * src/parse-gram.y (input): Don't append the epilogue here, + (epilogue.opt): do it here, and free the scanner's obstack. + * src/reader.c (epilogue_set): Rename as... + (epilogue_augment): this. + * data/c.m4 (b4_epilogue): Defaults to empty. + +2002-11-12 Akim Demaille + * src/getargs.c (long_options): Remove duplicates. * src/vmsgetargs.c, src/build.com, src/bison.cld, src/vmshlp.mar: Remove. diff --git a/data/c.m4 b/data/c.m4 index aad71ba..b67a443 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -65,6 +65,14 @@ m4_define([b4_identification], +## ---------------- ## +## Default values. ## +## ---------------- ## + +m4_define_default([b4_epilogue], []) + + + ## ------------------------ ## ## Pure/impure interfaces. ## ## ------------------------ ## diff --git a/src/parse-gram.c b/src/parse-gram.c index 5d2706c..841054c 100644 --- a/src/parse-gram.c +++ b/src/parse-gram.c @@ -458,14 +458,14 @@ static const yysigned_char yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned short yyrline[] = { - 0, 169, 169, 182, 184, 187, 189, 190, 191, 192, + 0, 170, 170, 182, 184, 187, 189, 190, 191, 192, 193, 194, 195, 196, 197, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 212, 214, 215, 219, 226, 225, 236, 235, 248, 247, 253, 253, 258, 267, 282, 284, 285, 288, 290, 295, 297, 301, 306, 311, 317, 323, 333, 336, 345, 347, 353, 355, 360, 367, 366, 371, 373, 376, 379, 381, 383, 385, 387, 391, 393, - 396, 402, 411, 419, 424, 430, 432 + 396, 402, 411, 419, 421, 428, 430 }; #endif @@ -1216,10 +1216,9 @@ yyreduce: switch (yyn) { case 2: -#line 171 "parse-gram.y" +#line 172 "parse-gram.y" { yycontrol->errcode = 0; - epilogue_set (yyvsp[0].string, yylsp[0]); } break; @@ -1601,17 +1600,11 @@ yyreduce: } break; - case 73: -#line 421 "parse-gram.y" - { - yyval.string = xstrdup (""); - } - break; - case 74: -#line 425 "parse-gram.y" +#line 422 "parse-gram.y" { - yyval.string = yyvsp[0].string; + epilogue_augment (yyvsp[0].string, yylsp[0]); + scanner_last_string_free (); } break; @@ -1619,7 +1612,7 @@ yyreduce: } /* Line 1056 of /usr/local/share/bison/yacc.c. */ -#line 1623 "parse-gram.c" +#line 1616 "parse-gram.c" yyvsp -= yylen; yyssp -= yylen; @@ -1838,7 +1831,7 @@ yyreturn: } -#line 434 "parse-gram.y" +#line 432 "parse-gram.y" /*------------------------------------------------------------------. | When debugging the parser, display tokens' locations and values. | @@ -1872,6 +1865,10 @@ yyprint (FILE *file, case EPILOGUE: fprintf (file, " = {{ %s }}", value->string); break; + + default: + fprintf (file, "unknown token type"); + break; } } diff --git a/src/parse-gram.y b/src/parse-gram.y index 74a6574..c10c82a 100644 --- a/src/parse-gram.y +++ b/src/parse-gram.y @@ -158,7 +158,8 @@ braced_code_t current_braced_code = action_braced_code; %type STRING string_content - BRACED_CODE PROLOGUE EPILOGUE epilogue.opt action + BRACED_CODE action + PROLOGUE EPILOGUE %type TYPE %type INT %type ID symbol string_as_id @@ -170,7 +171,6 @@ input: declarations "%%" grammar epilogue.opt { yycontrol->errcode = 0; - epilogue_set ($4, @4); } ; @@ -418,12 +418,10 @@ string_content: epilogue.opt: /* Nothing. */ - { - $$ = xstrdup (""); - } | "%%" EPILOGUE { - $$ = $2; + epilogue_augment ($2, @2); + scanner_last_string_free (); } ; @@ -464,6 +462,10 @@ yyprint (FILE *file, case EPILOGUE: fprintf (file, " = {{ %s }}", value->string); break; + + default: + fprintf (file, "unknown token type"); + break; } } diff --git a/src/reader.c b/src/reader.c index fa34809..9f83a93 100644 --- a/src/reader.c +++ b/src/reader.c @@ -84,8 +84,9 @@ prologue_augment (const char *prologue, location_t location) `----------------------*/ void -epilogue_set (const char *epilogue, location_t location) +epilogue_augment (const char *epilogue, location_t location) { + char *extension = NULL; obstack_fgrow1 (&muscle_obstack, "]b4_syncline([[%d]], [[", location.first_line); MUSCLE_OBSTACK_SGROW (&muscle_obstack, @@ -93,7 +94,9 @@ epilogue_set (const char *epilogue, location_t location) obstack_sgrow (&muscle_obstack, "]])[\n"); obstack_sgrow (&muscle_obstack, epilogue); obstack_1grow (&muscle_obstack, 0); - muscle_insert ("epilogue", obstack_finish (&muscle_obstack)); + extension = obstack_finish (&muscle_obstack); + muscle_grow ("epilogue", extension, ""); + obstack_free (&muscle_obstack, extension); } diff --git a/src/reader.h b/src/reader.h index cca624a..a32e84f 100644 --- a/src/reader.h +++ b/src/reader.h @@ -42,6 +42,7 @@ extern FILE *gram_in; extern int gram__flex_debug; void scanner_initialize (void); void scanner_free (void); +void scanner_last_string_free (void); # define YY_DECL \ int gram_lex (yystype *yylval, location_t *yylloc, \ @@ -69,7 +70,7 @@ extern braced_code_t current_braced_code; /* From reader.c. */ void grammar_start_symbol_set (symbol_t *s, location_t l); void prologue_augment (const char *prologue, location_t location); -void epilogue_set (const char *epilogue, location_t location); +void epilogue_augment (const char *epilogue, location_t location); void grammar_symbol_append (symbol_t *s, location_t l); void grammar_rule_begin (symbol_t *lhs, location_t l); void grammar_rule_end (location_t l); diff --git a/src/scan-gram.l b/src/scan-gram.l index 02f5e85..4e2e194 100644 --- a/src/scan-gram.l +++ b/src/scan-gram.l @@ -142,6 +142,10 @@ extend_location (location_t *loc, char const *token, int size) static struct obstack string_obstack; +/* A string representing the most recently saved token. */ +static char *last_string; + + #define YY_OBS_GROW \ obstack_grow (&string_obstack, yytext, yyleng) @@ -154,6 +158,11 @@ static struct obstack string_obstack; #define YY_OBS_FREE \ obstack_free (&string_obstack, last_string) +void +scanner_last_string_free (void) +{ + YY_OBS_FREE; +} /* Within well-formed rules, RULE_LENGTH is the number of values in the current rule so far, which says where to find `$0' with respect @@ -199,9 +208,6 @@ splice (\\[ \f\t\v]*\n)* /* Scanner context when scanning C code. */ int c_context IF_LINT (= 0); - /* A string representing the most recently saved token. */ - char *last_string; - /* At each yylex invocation, mark the current position as the start of the next token. */ YY_STEP; -- 2.7.4