From e9955c83734d0a545d7822a1feb9c4a8038a62cb Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 11 Jun 2002 20:16:05 +0000 Subject: [PATCH] Have Bison grammars parsed by a Bison grammar. * src/reader.c, src/reader.h (prologue_augment): New. * src/reader.c (copy_definition): Remove. * src/reader.h, src/reader.c (gram_start_symbol_set, prologue_augment) (grammar_symbol_append, grammar_rule_begin, grammar_midrule_action) (grammar_current_rule_prec_set, grammar_current_rule_check) (grammar_current_rule_symbol_append) (grammar_current_rule_action_append): Export. * src/parse-gram.y (symbol_list_new, symbol_list_symbol_append_ (symbol_list_action_append): Remove. Hook the routines from reader. * src/scan-gram.l: In INITIAL, characters and strings are tokens. * src/system.h (ATTRIBUTE_NORETURN, ATTRIBUTE_UNUSED): Now. * src/reader.c (read_declarations): Remove, unused. * src/parse-gram.y: Handle the epilogue. * src/reader.h, src/reader.c (gram_start_symbol_set): Rename as... (grammar_start_symbol_set): this. * src/scan-gram.l: Be sure to ``use'' yycontrol to keep GCC quiet. * src/reader.c (readgram): Remove, unused. (reader): Adjust to insert eoftoken and axiom where appropriate. * src/reader.c (copy_dollar): Replace with... * src/scan-gram.h (handle_dollar): this. * src/parse-gram.y: Remove `%thong'. * src/reader.c (copy_at): Replace with... * src/scan-gram.h (handle_at): this. * src/complain.h, src/complain.c (warn_at, complain_at, fatal_at): New. * src/scan-gram.l (YY_LINES): Keep lineno synchronized for the time being. * src/reader.h, src/reader.c (grammar_rule_end): New. * src/parse.y (current_type, current_class): New. Implement `%nterm', `%token' support. Merge `%term' into `%token'. (string_as_id): New. * src/symtab.h, src/symtab.c (symbol_make_alias): Don't pass the type name. * src/parse-gram.y: Be sure to handle properly the beginning of rules. * src/parse-gram.y: Handle %type. * src/reader.c (grammar_rule_end): Call grammar_current_rule_check. * src/parse-gram.y: More directives support. * src/options.c: No longer handle source directives. * src/parse-gram.y: Fix %output. * src/parse-gram.y: Handle %union. Use the prologue locations. * src/reader.c (parse_union_decl): Remove. * src/reader.h, src/reader.c (epilogue_set): New. * src/parse-gram.y: Use it. * data/bison.simple, data/bison.c++: b4_stype is now either not defined, then default to int, or to the contents of %union, without `union' itself. Adjust. * src/muscle_tab.c (muscle_init): Don't predefine `stype'. * src/output.c (actions_output): Don't output braces, as they are already handled by the scanner. * src/scan-gram.l (SC_CHARACTER): Set the user_token_number of characters to themselves. * tests/reduce.at (Reduced Automaton): End the grammars with %% so that the epilogue has a proper #line. * src/parse-gram.y: Handle precedence/associativity. * src/symtab.c (symbol_precedence_set): Requires the symbol to be a terminal. * src/scan-gram.l (SC_BRACED_CODE): Catch strings and characters. * tests/calc.at: Do not use `%token "foo"' as it makes not sense at all to define terminals that cannot be emitted. * src/scan-gram.l: Escape M4 characters. * src/scan-gram.l: Working properly with escapes in user strings/characters. * tests/torture.at (AT_DATA_TRIANGULAR_GRAMMAR) (AT_DATA_HORIZONTAL_GRAMMAR): Respect the `%token ID NUM STRING' grammar. Use more modest sizes, as for the time being the parser does not release memory, and therefore the process swallows a huge amount of memory. * tests/torture.at (AT_DATA_LOOKAHEADS_GRAMMAR): Adjust to the stricter %token grammar. * src/symtab.h (associativity): Add `undef_assoc'. (symbol_precedence_set): Do nothing when passed an undef_assoc. * src/symtab.c (symbol_check_alias_consistence): Adjust. * tests/regression.at (Invalid %directive): Remove, as it is now meaningless. (Invalid inputs): Adjust to the new error messages. (Token definitions): The new grammar doesn't allow too many eccentricities. * src/lex.h, src/lex.c: Remove. * src/reader.c (lastprec, skip_to_char, read_signed_integer) (copy_character, copy_string2, copy_string, copy_identifier) (copy_comment, parse_token_decl, parse_type_decl, parse_assoc_decl) (parse_muscle_decl, parse_dquoted_param, parse_skel_decl) (parse_action): Remove. * po/POTFILES.in: Adjust. --- ChangeLog | 123 ++ data/bison.c++ | 7 +- data/bison.simple | 13 +- po/POTFILES.in | 3 +- src/Makefile.am | 8 +- src/complain.c | 132 +++ src/complain.h | 24 +- src/conflicts.c | 4 + src/lex.c | 604 ---------- src/lex.h | 82 -- src/main.c | 1 - src/muscle_tab.c | 1 - src/options.c | 49 +- src/output.c | 8 +- src/parse-gram.c | 1790 ++++++++++++++++++++++++++++ src/parse-gram.h | 124 ++ src/parse-gram.y | 386 ++++++ src/reader.c | 1250 ++------------------ src/reader.h | 89 +- src/scan-action.l | 46 + src/scan-gram.c | 2750 +++++++++++++++++++++++++++++++++++++++++++ src/scan-gram.l | 582 +++++++++ src/symtab.c | 49 +- src/symtab.h | 17 +- src/system.h | 16 +- tests/calc.at | 2 +- tests/reduce.at | 2 + tests/regression.at | 49 +- tests/synclines.at | 2 +- tests/torture.at | 18 +- 30 files changed, 6269 insertions(+), 1962 deletions(-) delete mode 100644 src/lex.c delete mode 100644 src/lex.h create mode 100644 src/parse-gram.c create mode 100644 src/parse-gram.h create mode 100644 src/parse-gram.y create mode 100644 src/scan-action.l create mode 100644 src/scan-gram.c create mode 100644 src/scan-gram.l diff --git a/ChangeLog b/ChangeLog index 3f62dea0..b30617c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,126 @@ +2002-06-11 Akim Demaille + + Have Bison grammars parsed by a Bison grammar. + + * src/reader.c, src/reader.h (prologue_augment): New. + * src/reader.c (copy_definition): Remove. + + * src/reader.h, src/reader.c (gram_start_symbol_set, prologue_augment) + (grammar_symbol_append, grammar_rule_begin, grammar_midrule_action) + (grammar_current_rule_prec_set, grammar_current_rule_check) + (grammar_current_rule_symbol_append) + (grammar_current_rule_action_append): Export. + * src/parse-gram.y (symbol_list_new, symbol_list_symbol_append_ + (symbol_list_action_append): Remove. + Hook the routines from reader. + * src/scan-gram.l: In INITIAL, characters and strings are tokens. + * src/system.h (ATTRIBUTE_NORETURN, ATTRIBUTE_UNUSED): Now. + + * src/reader.c (read_declarations): Remove, unused. + + * src/parse-gram.y: Handle the epilogue. + * src/reader.h, src/reader.c (gram_start_symbol_set): Rename as... + (grammar_start_symbol_set): this. + * src/scan-gram.l: Be sure to ``use'' yycontrol to keep GCC quiet. + * src/reader.c (readgram): Remove, unused. + (reader): Adjust to insert eoftoken and axiom where appropriate. + + * src/reader.c (copy_dollar): Replace with... + * src/scan-gram.h (handle_dollar): this. + * src/parse-gram.y: Remove `%thong'. + + * src/reader.c (copy_at): Replace with... + * src/scan-gram.h (handle_at): this. + + * src/complain.h, src/complain.c (warn_at, complain_at, fatal_at): + New. + + * src/scan-gram.l (YY_LINES): Keep lineno synchronized for the + time being. + + * src/reader.h, src/reader.c (grammar_rule_end): New. + + * src/parse.y (current_type, current_class): New. + Implement `%nterm', `%token' support. + Merge `%term' into `%token'. + (string_as_id): New. + * src/symtab.h, src/symtab.c (symbol_make_alias): Don't pass the + type name. + + * src/parse-gram.y: Be sure to handle properly the beginning of + rules. + + * src/parse-gram.y: Handle %type. + * src/reader.c (grammar_rule_end): Call grammar_current_rule_check. + + * src/parse-gram.y: More directives support. + * src/options.c: No longer handle source directives. + + * src/parse-gram.y: Fix %output. + + * src/parse-gram.y: Handle %union. + Use the prologue locations. + * src/reader.c (parse_union_decl): Remove. + + * src/reader.h, src/reader.c (epilogue_set): New. + * src/parse-gram.y: Use it. + + * data/bison.simple, data/bison.c++: b4_stype is now either not + defined, then default to int, or to the contents of %union, + without `union' itself. + Adjust. + * src/muscle_tab.c (muscle_init): Don't predefine `stype'. + + * src/output.c (actions_output): Don't output braces, as they are + already handled by the scanner. + + * src/scan-gram.l (SC_CHARACTER): Set the user_token_number of + characters to themselves. + + * tests/reduce.at (Reduced Automaton): End the grammars with %% so + that the epilogue has a proper #line. + + * src/parse-gram.y: Handle precedence/associativity. + + * src/symtab.c (symbol_precedence_set): Requires the symbol to be + a terminal. + * src/scan-gram.l (SC_BRACED_CODE): Catch strings and characters. + * tests/calc.at: Do not use `%token "foo"' as it makes not sense + at all to define terminals that cannot be emitted. + + * src/scan-gram.l: Escape M4 characters. + + * src/scan-gram.l: Working properly with escapes in user + strings/characters. + + * tests/torture.at (AT_DATA_TRIANGULAR_GRAMMAR) + (AT_DATA_HORIZONTAL_GRAMMAR): Respect the `%token ID NUM STRING' + grammar. + Use more modest sizes, as for the time being the parser does not + release memory, and therefore the process swallows a huge amount + of memory. + + * tests/torture.at (AT_DATA_LOOKAHEADS_GRAMMAR): Adjust to the + stricter %token grammar. + + * src/symtab.h (associativity): Add `undef_assoc'. + (symbol_precedence_set): Do nothing when passed an undef_assoc. + * src/symtab.c (symbol_check_alias_consistence): Adjust. + + * tests/regression.at (Invalid %directive): Remove, as it is now + meaningless. + (Invalid inputs): Adjust to the new error messages. + (Token definitions): The new grammar doesn't allow too many + eccentricities. + + * src/lex.h, src/lex.c: Remove. + * src/reader.c (lastprec, skip_to_char, read_signed_integer) + (copy_character, copy_string2, copy_string, copy_identifier) + (copy_comment, parse_token_decl, parse_type_decl, parse_assoc_decl) + (parse_muscle_decl, parse_dquoted_param, parse_skel_decl) + (parse_action): Remove. + * po/POTFILES.in: Adjust. + 2002-06-11 Akim Demaille * src/reader.c (parse_action): Don't store directly into the diff --git a/data/bison.c++ b/data/bison.c++ index 0878770b..dafdddee 100644 --- a/data/bison.c++ +++ b/data/bison.c++ @@ -159,11 +159,10 @@ b4_token_defines(b4_tokens) #endif #ifndef YYSTYPE -m4_ifdef([b4_stype_line], +m4_ifdef([b4_stype], [#line b4_stype_line "b4_filename" -])dnl -typedef b4_stype -yystype; +typedef union b4_stype yystype;], +[typedef int yystype;]) # define YYSTYPE yystype #endif diff --git a/data/bison.simple b/data/bison.simple index 8b5eda87..301058ea 100644 --- a/data/bison.simple +++ b/data/bison.simple @@ -191,10 +191,10 @@ b4_token_defines(b4_tokens) #endif #ifndef YYSTYPE -m4_ifdef([b4_stype_line], +m4_ifdef([b4_stype], [#line b4_stype_line "b4_filename" -])dnl -typedef b4_stype yystype; +typedef union b4_stype yystype;], +[typedef int yystype;]) # define YYSTYPE yystype # define YYSTYPE_IS_TRIVIAL 1 #endif @@ -1238,11 +1238,10 @@ m4_if(b4_defines_flag, 0, [], b4_token_defines(b4_tokens) #ifndef YYSTYPE -m4_ifdef([b4_stype_line], +m4_ifdef([b4_stype], [#line b4_stype_line "b4_filename" -])dnl -typedef b4_stype -yystype; +typedef union b4_stype yystype;], +[typedef int yystype;]) # define YYSTYPE yystype #endif diff --git a/po/POTFILES.in b/po/POTFILES.in index d612be37..6d22190f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,10 +4,11 @@ src/conflicts.c src/files.c src/getargs.c src/lalr.c -src/lex.c +src/parse-gram.c src/print.c src/reader.c src/reduce.c +src/scan-gram.c lib/error.c lib/getopt.c diff --git a/src/Makefile.am b/src/Makefile.am index bc591744..78996c9d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,8 +36,10 @@ LDADD = $(INTLLIBS) ../lib/libbison.a bin_PROGRAMS = bison bison_SOURCES = LR0.c closure.c complain.c conflicts.c \ + parse-gram.y parse-gram.h \ + scan-gram.c \ derives.c \ - files.c getargs.c gram.c lalr.c lex.c main.c nullable.c \ + files.c getargs.c gram.c lalr.c main.c nullable.c \ output.h output.c \ state.h state.c \ print_graph.h print_graph.c \ @@ -46,13 +48,13 @@ bison_SOURCES = LR0.c closure.c complain.c conflicts.c \ print.c reader.c reduce.c symtab.c vcg.c \ scan-skel.l -BUILT_SOURCES = scan-skel.c +BUILT_SOURCES = scan-skel.c scan-gram.c parse-gram.c parse-gram.h EXTRA_bison_SOURCES = vmsgetargs.c noinst_HEADERS = LR0.h closure.h complain.h conflicts.h \ derives.h \ - files.h getargs.h gram.h lalr.h lex.h nullable.h \ + files.h getargs.h gram.h lalr.h nullable.h \ print.h reader.h reduce.h symtab.h system.h \ types.h vcg.h vcg_defaults.h diff --git a/src/complain.c b/src/complain.c index fd14d946..49c61897 100644 --- a/src/complain.c +++ b/src/complain.c @@ -114,6 +114,56 @@ unsigned int complain_message_count; | Report a warning, and proceed. | `--------------------------------*/ +void +#if defined VA_START && defined __STDC__ +warn_at (int location, const char *message, ...) +#else +warn_at (location, message, va_alist) + int location + char *message; + va_dcl +#endif +{ +#ifdef VA_START + va_list args; +#endif + + if (error_one_per_line) + { + static const char *old_infile; + static int old_lineno; + + if (old_lineno == location && + (infile == old_infile || !strcmp (old_infile, infile))) + /* Simply return and print nothing. */ + return; + + old_infile = infile; + old_lineno = location; + } + + fflush (stdout); + if (infile != NULL) + fprintf (stderr, "%s:%d: ", infile, location); + else + fprintf (stderr, "%s:", program_name); + + fputs (_("warning: "), stderr); + +#ifdef VA_START + VA_START (args, message); + vfprintf (stderr, message, args); + va_end (args); +#else + fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); +#endif + + ++warn_message_count; + putc ('\n', stderr); + fflush (stderr); +} + + void #if defined VA_START && defined __STDC__ warn (const char *message, ...) @@ -166,6 +216,54 @@ warn (message, va_alist) | An error has occurred, but we can proceed, and die later. | `-----------------------------------------------------------*/ +void +#if defined VA_START && defined __STDC__ +complain_at (int location, const char *message, ...) +#else +complain_at (location, message, va_alist) + int location; + char *message; + va_dcl +#endif +{ +#ifdef VA_START + va_list args; +#endif + + if (error_one_per_line) + { + static const char *old_infile; + static int old_lineno; + + if (old_lineno == location && + (infile == old_infile || !strcmp (old_infile, infile))) + /* Simply return and print nothing. */ + return; + + old_infile = infile; + old_lineno = location; + } + + fflush (stdout); + if (infile != NULL) + fprintf (stderr, "%s:%d: ", infile, location); + else + fprintf (stderr, "%s:", program_name); + +#ifdef VA_START + VA_START (args, message); + vfprintf (stderr, message, args); + va_end (args); +#else + fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); +#endif + + ++complain_message_count; + putc ('\n', stderr); + fflush (stderr); +} + + void #if defined VA_START && defined __STDC__ complain (const char *message, ...) @@ -216,6 +314,40 @@ complain (message, va_alist) | A severe error has occurred, we cannot proceed. | `-------------------------------------------------*/ +void +#if defined VA_START && defined __STDC__ +fatal_at (int location, const char *message, ...) +#else +fatal (location, message, va_alist) + int location; + char *message; + va_dcl +#endif +{ +#ifdef VA_START + va_list args; +#endif + + fflush (stdout); + if (infile != NULL) + fprintf (stderr, "%s:%d: ", infile, location); + else + fprintf (stderr, "%s:", program_name); + + fputs (_("fatal error: "), stderr); + +#ifdef VA_START + VA_START (args, message); + vfprintf (stderr, message, args); + va_end (args); +#else + fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); +#endif + putc ('\n', stderr); + fflush (stderr); + exit (1); +} + void #if defined VA_START && defined __STDC__ fatal (const char *message, ...) diff --git a/src/complain.h b/src/complain.h index 2911a4dc..79a3e122 100644 --- a/src/complain.h +++ b/src/complain.h @@ -27,23 +27,35 @@ extern "C" { /* Informative messages, but we proceed. */ -extern void warn (const char *format, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); +void warn (const char *format, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); + +void warn_at (int location, const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); /* Something bad happen, but let's continue and die later. */ -extern void complain (const char *format, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); +void complain (const char *format, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); + +void complain_at (int location, const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); /* Something bad happen and we die now. */ -extern void fatal (const char *format, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); +void fatal (const char *format, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); + +void fatal_at (int location, const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); #else void warn (); +void warn_at (); void complain (); +void complain_at (); void fatal (); +void fatal_at (); #endif /* Position in the current input file. */ diff --git a/src/conflicts.c b/src/conflicts.c index 876310f5..a7f4646e 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -216,6 +216,10 @@ resolve_sr_conflict (state_t *state, int lookahead) /* Record an explicit error for this token. */ errp->errs[errp->nerrs++] = i; break; + + case undef_assoc: + assert (symbols[i]->assoc != undef_assoc); + break; } } diff --git a/src/lex.c b/src/lex.c deleted file mode 100644 index 62afbee5..00000000 --- a/src/lex.c +++ /dev/null @@ -1,604 +0,0 @@ -/* Token-reader for Bison's input parser, - Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002 - Free Software Foundation, Inc. - - This file is part of Bison, the GNU Compiler Compiler. - - Bison is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - Bison is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#include "system.h" -#include "getargs.h" -#include "files.h" -#include "symtab.h" -#include "options.h" -#include "lex.h" -#include "complain.h" -#include "gram.h" -#include "quote.h" - -/* Buffer for storing the current token. */ -static struct obstack token_obstack; -const char *token_buffer = NULL; - -symbol_t *symval = NULL; -int numval; - -/* A token to be reread, see unlex and lex. */ -static token_t unlexed = tok_undef; -static symbol_t *unlexed_symval = NULL; -static const char *unlexed_token_buffer = NULL; - -void -lex_init (void) -{ - obstack_init (&token_obstack); - unlexed = tok_undef; -} - - -void -lex_free (void) -{ - obstack_free (&token_obstack, NULL); -} - - -int -skip_white_space (void) -{ - int c; - int inside; - - c = getc (finput); - - for (;;) - { - int cplus_comment; - - switch (c) - { - case '/': - /* FIXME: Should probably be merged with copy_comment. */ - c = getc (finput); - if (c != '*' && c != '/') - { - complain (_("unexpected `/' found and ignored")); - break; - } - cplus_comment = (c == '/'); - - c = getc (finput); - - inside = 1; - while (inside) - { - if (!cplus_comment && c == '*') - { - while (c == '*') - c = getc (finput); - - if (c == '/') - { - inside = 0; - c = getc (finput); - } - } - else if (c == '\n') - { - lineno++; - if (cplus_comment) - inside = 0; - c = getc (finput); - } - else if (c == EOF) - fatal (_("unterminated comment")); - else - c = getc (finput); - } - - break; - - case '\n': - lineno++; - - case ' ': - case '\t': - case '\f': - c = getc (finput); - break; - - default: - return c; - } - } -} - - -/*-----------------------------------------------------. -| Do a getc, but give error message if EOF encountered | -`-----------------------------------------------------*/ - -int -xgetc (FILE *f) -{ - int c = getc (f); - if (c == EOF) - fatal (_("unexpected end of file")); - return c; -} - - -/*---------------------------------------------------------------. -| Read one literal character from FINPUT, process \-escapes, and | -| return the character. | -`---------------------------------------------------------------*/ - -char -literalchar (void) -{ - int c; - int res; - - c = xgetc (finput); - if (c == '\n') - { - complain (_("unescaped newline in constant")); - ungetc (c, finput); - res = '?'; - } - else if (c != '\\') - { - res = c; - } - else - { - c = xgetc (finput); - if (c == 't') - res = '\t'; - else if (c == 'n') - res = '\n'; - else if (c == 'a') - res = '\007'; - else if (c == 'r') - res = '\r'; - else if (c == 'f') - res = '\f'; - else if (c == 'b') - res = '\b'; - else if (c == 'v') - res = '\013'; - else if (c == '\\') - res = '\\'; - else if (c == '\'') - res = '\''; - else if (c == '\"') - res = '\"'; - else if (c <= '7' && c >= '0') - { - res = 0; - while (c <= '7' && c >= '0') - { - res = (res * 8) + (c - '0'); - if (res >= 256 || res < 0) - { - complain (_("octal value outside range 0...255: `\\%o'"), - res); - res &= 0xFF; - break; - } - c = xgetc (finput); - } - ungetc (c, finput); - } - else if (c == 'x') - { - c = xgetc (finput); - res = 0; - while (1) - { - if (c >= '0' && c <= '9') - res *= 16, res += c - '0'; - else if (c >= 'a' && c <= 'f') - res *= 16, res += c - 'a' + 10; - else if (c >= 'A' && c <= 'F') - res *= 16, res += c - 'A' + 10; - else - break; - if (res >= 256 || res < 0) - { - complain (_("hexadecimal value above 255: `\\x%x'"), res); - res &= 0xFF; - break; - } - c = xgetc (finput); - } - ungetc (c, finput); - } - else - { - char badchar [] = "c"; - badchar[0] = c; - complain (_("unknown escape sequence: `\\' followed by `%s'"), - quote (badchar)); - res = '?'; - } - } /* has \ */ - - return res; -} - - -void -unlex (token_t token) -{ - unlexed = token; - unlexed_token_buffer = token_buffer; - unlexed_symval = symval; -} - -/*-----------------------------------------------------------------. -| We just read `<' from FIN. Store in TOKEN_BUFFER, the type name | -| specified between the `<...>'. | -`-----------------------------------------------------------------*/ - -void -read_type_name (FILE *fin) -{ - int c = getc (fin); - - while (c != '>') - { - if (c == EOF) - fatal (_("unterminated type name at end of file")); - if (c == '\n') - { - complain (_("unterminated type name")); - ungetc (c, fin); - break; - } - - obstack_1grow (&token_obstack, c); - c = getc (fin); - } - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); -} - - -token_t -lex (void) -{ - int c; - - /* Just to make sure. */ - token_buffer = NULL; - - if (unlexed != tok_undef) - { - token_t res = unlexed; - symval = unlexed_symval; - token_buffer = unlexed_token_buffer; - unlexed = tok_undef; - return res; - } - - c = skip_white_space (); - - switch (c) - { - case EOF: - token_buffer = "EOF"; - return tok_eof; - - case 'A': case 'B': case 'C': case 'D': case 'E': - case 'F': case 'G': case 'H': case 'I': case 'J': - case 'K': case 'L': case 'M': case 'N': case 'O': - case 'P': case 'Q': case 'R': case 'S': case 'T': - case 'U': case 'V': case 'W': case 'X': case 'Y': - case 'Z': - case 'a': case 'b': case 'c': case 'd': case 'e': - case 'f': case 'g': case 'h': case 'i': case 'j': - case 'k': case 'l': case 'm': case 'n': case 'o': - case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'v': case 'w': case 'x': case 'y': - case 'z': - case '.': case '_': - - while (isalnum (c) || c == '_' || c == '.') - { - obstack_1grow (&token_obstack, c); - c = getc (finput); - } - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); - ungetc (c, finput); - symval = getsym (token_buffer); - return tok_identifier; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - { - numval = 0; - - while (isdigit (c)) - { - obstack_1grow (&token_obstack, c); - numval = numval * 10 + c - '0'; - c = getc (finput); - } - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); - ungetc (c, finput); - return tok_number; - } - - case '\'': - /* parse the literal token and compute character code in code */ - - { - int code = literalchar (); - - obstack_1grow (&token_obstack, '\''); - obstack_1grow (&token_obstack, code); - - c = getc (finput); - if (c != '\'') - { - complain (_("use \"...\" for multi-character literal tokens")); - while (literalchar () != '\'') - /* Skip. */; - } - obstack_1grow (&token_obstack, '\''); - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); - symval = getsym (token_buffer); - symbol_class_set (symval, token_sym); - symbol_user_token_number_set (symval, code); - return tok_identifier; - } - - case '\"': - /* parse the literal string token and treat as an identifier */ - - { - int code; - - obstack_1grow (&token_obstack, '\"'); - /* Read up to and including ". */ - do - { - code = literalchar (); - obstack_1grow (&token_obstack, code); - } - while (code != '\"'); - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); - - symval = getsym (token_buffer); - symbol_class_set (symval, token_sym); - return tok_identifier; - } - - case ',': - token_buffer = ","; - return tok_comma; - - case ':': - token_buffer = ":"; - return tok_colon; - - case ';': - token_buffer = ";"; - return tok_semicolon; - - case '|': - token_buffer = "|"; - return tok_bar; - - case '{': - token_buffer = "{"; - return tok_left_curly; - - case '=': - obstack_1grow (&token_obstack, c); - do - { - c = getc (finput); - obstack_1grow (&token_obstack, c); - if (c == '\n') - lineno++; - } - while (c == ' ' || c == '\n' || c == '\t'); - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); - - if (c == '{') - { - return tok_left_curly; - } - else - { - ungetc (c, finput); - return tok_illegal; - } - - case '<': - read_type_name (finput); - return tok_typename; - - case '%': - return parse_percent_token (); - - default: - obstack_1grow (&token_obstack, c); - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); - return tok_illegal; - } -} - -/* This function is a strcmp, which doesn't differentiate `-' and `_' - chars. */ - -static int -option_strcmp (const char *left, const char *right) -{ - const unsigned char *l, *r; - int c; - - assert (left); - assert (right); - l = (const unsigned char *)left; - r = (const unsigned char *)right; - while (((c = *l - *r++) == 0 && *l != '\0') - || ((*l == '-' || *l == '_') && (*r == '_' || *r == '-'))) - l++; - return c; -} - -/* Parse a token which starts with %. - Assumes the % has already been read and discarded. */ - -token_t -parse_percent_token (void) -{ - const struct option_table_s *tx = NULL; - const char *arg = NULL; - /* Where the ARG was found in token_buffer. */ - size_t arg_offset = 0; - - int c = getc (finput); - obstack_1grow (&token_obstack, '%'); - obstack_1grow (&token_obstack, c); - - if (!isalpha (c)) - { - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); - - switch (c) - { - case '%': - return tok_two_percents; - - case '{': - return tok_percent_left_curly; - - /* The following guys are here for backward compatibility with - very ancient Yacc versions. The paper of Johnson mentions - them (as ancient :). */ - case '<': - return tok_left; - - case '>': - return tok_right; - - case '2': - return tok_nonassoc; - - case '0': - return tok_token; - - case '=': - return tok_prec; - - default: - return tok_illegal; - } - } - - while (c = getc (finput), isalpha (c) || c == '_' || c == '-') - { - if (c == '_') - c = '-'; - obstack_1grow (&token_obstack, c); - } - - /* %DIRECTIVE="ARG". Separate into - TOKEN_BUFFER = `%DIRECTIVE\0ARG\0'. - This is a bit hackish, but once we move to a Bison parser, - things will be cleaned up. */ - if (c == '=') - { - /* End of the directive. We skip the `='. */ - obstack_1grow (&token_obstack, '\0'); - /* Fetch the ARG if present. */ - c = getc (finput); - if (c == '"') - { - int code; - arg_offset = obstack_object_size (&token_obstack); - /* Read up to and including `"'. Do not append the closing - `"' in the output: it's not part of the ARG. */ - while ((code = literalchar ()) != '"') - obstack_1grow (&token_obstack, code); - } - /* else: should be an error. */ - } - else - ungetc (c, finput); - - obstack_1grow (&token_obstack, '\0'); - token_buffer = obstack_finish (&token_obstack); - if (arg_offset) - arg = token_buffer + arg_offset; - - /* table lookup % directive */ - for (tx = option_table; tx->name; tx++) - if ((tx->access == opt_percent || tx->access == opt_both) - && option_strcmp (token_buffer + 1, tx->name) == 0) - break; - - if (arg && tx->ret_val != tok_stropt) - fatal (_("`%s' supports no argument: %s"), token_buffer, quote (arg)); - - - switch (tx->ret_val) - { - case tok_stropt: - assert (tx->flag); - if (arg) - { - char **flag = (char **) tx->flag; - /* Keep only the first assignment: command line options have - already been processed, and we want them to have - precedence. Side effect: if this %-option is used - several times, only the first is honored. Bah. */ - if (!*flag) - *flag = xstrdup (arg); - } - else - fatal (_("`%s' requires an argument"), token_buffer); - return tok_noop; - break; - - case tok_intopt: - assert (tx->flag); - *((int *) (tx->flag)) = 1; - return tok_noop; - break; - - case tok_obsolete: - fatal (_("`%s' is no longer supported"), token_buffer); - return tok_noop; - break; - - default: - return tx->ret_val; - break; - } - abort (); -} diff --git a/src/lex.h b/src/lex.h deleted file mode 100644 index 4e93a1c5..00000000 --- a/src/lex.h +++ /dev/null @@ -1,82 +0,0 @@ -/* Token type definitions for bison's input reader, - Copyright 1984, 1989, 1992, 2000, 2001 Free Software Foundation, Inc. - - This file is part of Bison, the GNU Compiler Compiler. - - Bison is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - Bison is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -#ifndef LEX_H_ -# define LEX_H_ - -/* Token-type codes. */ -typedef enum token_e - { - tok_undef, /* Not defined. Used to initial token_t vars. */ - tok_eof, - tok_identifier, - tok_comma, - tok_colon, - tok_semicolon, - tok_bar, - tok_left_curly, - tok_two_percents, - tok_percent_left_curly, - tok_token, - tok_nterm, - tok_type, - tok_union, - tok_start, - tok_left, - tok_right, - tok_nonassoc, - tok_prec, - tok_typename, - tok_number, - tok_expect, - tok_define, - tok_skel, - tok_noop, - /* A directive that sets to true its associated variable. */ - tok_intopt, - /* A directive that sets its associated variable to the string - argument. */ - tok_stropt, - tok_illegal, - tok_obsolete - } token_t; - -extern const char *token_buffer; -extern symbol_t *symval; -extern int numval; - -void lex_init PARAMS ((void)); -void lex_free PARAMS ((void)); -int skip_white_space PARAMS ((void)); -void unlex PARAMS ((token_t)); -void read_type_name PARAMS ((FILE *fin)); -int xgetc PARAMS ((FILE *fin)); - -/* Return one of the token-type codes. When an identifier is seen, - the code IDENTIFIER is returned and the name is looked up in the - symbol table using symtab.c; symval is set to a pointer to the - entry found. */ - -token_t lex PARAMS ((void)); -char literalchar PARAMS ((void)); - -token_t parse_percent_token PARAMS ((void)); - -#endif /* !LEX_H_ */ diff --git a/src/main.c b/src/main.c index c0faa97a..9421df91 100644 --- a/src/main.c +++ b/src/main.c @@ -38,7 +38,6 @@ #include "conflicts.h" #include "print_graph.h" #include "muscle_tab.h" -#include "lex.h" /* The name this program was run with, for messages. */ char *program_name; diff --git a/src/muscle_tab.c b/src/muscle_tab.c index 13b14198..b556ef73 100644 --- a/src/muscle_tab.c +++ b/src/muscle_tab.c @@ -55,7 +55,6 @@ muscle_init (void) muscle_insert ("filename", infile); /* Types. */ - muscle_insert ("stype", "int"); muscle_insert ("ltype", "yyltype"); /* Default #line formatting. */ diff --git a/src/options.c b/src/options.c index 73b77c06..f8f5301e 100644 --- a/src/options.c +++ b/src/options.c @@ -24,7 +24,6 @@ #include "getargs.h" #include "symtab.h" #include "gram.h" -#include "lex.h" #include "output.h" #include "options.h" @@ -77,55 +76,33 @@ const struct option_table_s option_table[] = /* Hidden. */ OPTN ("trace", no, &trace_flag, 0, 1) - /* - * Percent declarations. - */ - - DRTV ("token", no, NULL, tok_token) - DRTV ("term", no, NULL, tok_token) - DRTV ("nterm", no, NULL, tok_nterm) - DRTV ("type", no, NULL, tok_type) - DRTV ("union", no, NULL, tok_union) - DRTV ("expect", no, NULL, tok_expect) - DRTV ("start", no, NULL, tok_start) - DRTV ("left", no, NULL, tok_left) - DRTV ("right", no, NULL, tok_right) - DRTV ("nonassoc", no, NULL, tok_nonassoc) - DRTV ("binary", no, NULL, tok_nonassoc) - DRTV ("prec", no, NULL, tok_prec) - DRTV ("verbose", no, &report_flag, tok_intopt) - DRTV ("error-verbose",no, &error_verbose, tok_intopt) - /* FIXME: semantic parsers will output an `include' of an output file: be sure that the naem included is indeed the name of the output file. */ /* FIXME Should we activate this options ? */ - BOTH ("output", required, &spec_outfile, tok_stropt, 'o') - BOTH ("file-prefix", required, &spec_file_prefix, tok_stropt, 'b') - BOTH ("name-prefix", required, &spec_name_prefix, tok_stropt, 'p') - - DRTV ("define", no, NULL, tok_define) - DRTV ("pure-parser", no, &pure_parser, tok_intopt) + OPTN ("output", required, &spec_outfile, 0, 'o') + OPTN ("file-prefix", required, &spec_file_prefix, 0, 'b') + OPTN ("name-prefix", required, &spec_name_prefix, 0, 'p') /* * Percent and command line declarations. */ /* Output. */ - BOTH ("defines", optional, &defines_flag, tok_intopt, 'd') + OPTN ("defines", optional, &defines_flag, 0, 'd') /* Operation modes. */ - BOTH ("fixed-output-files", no, &yacc_flag, tok_intopt, 'y') - BOTH ("yacc", no, &yacc_flag, tok_intopt, 'y') + OPTN ("fixed-output-files", no, &yacc_flag, 0, 'y') + OPTN ("yacc", no, &yacc_flag, 0, 'y') /* Parser. */ - BOTH ("debug", no, &debug_flag, tok_intopt, 't') - BOTH ("locations", no, &locations_flag, tok_intopt, 1) - BOTH ("no-lines", no, &no_lines_flag, tok_intopt, 'l') - BOTH ("no-parser", no, &no_parser_flag, tok_intopt, 'n') - BOTH ("raw", no, 0, tok_obsolete, 0) - BOTH ("skeleton", required, 0, tok_skel, 'S') - BOTH ("token-table", no, &token_table_flag, tok_intopt, 'k') + OPTN ("debug", no, &debug_flag, 0, 't') + OPTN ("locations", no, &locations_flag, 0, 1) + OPTN ("no-lines", no, &no_lines_flag, 0, 'l') + OPTN ("no-parser", no, &no_parser_flag, 0, 'n') + OPTN ("raw", no, 0, 0, 0) + OPTN ("skeleton", required, 0, 0, 'S') + OPTN ("token-table", no, &token_table_flag, 0, 'k') {0, 0, 0, 0, 0, 0} }; diff --git a/src/output.c b/src/output.c index 02dfdb68..5645e8cd 100644 --- a/src/output.c +++ b/src/output.c @@ -548,12 +548,8 @@ actions_output (FILE *out) rules[rule].action_line, quotearg_style (c_quoting_style, muscle_find ("filename"))); - /* As a Bison extension, add the ending semicolon. Since some - Yacc don't do that, help people using bison as a Yacc - finding their missing semicolons. */ - fprintf (out, "{ %s%s }\n break;\n\n", - rules[rule].action, - yacc_flag ? ";" : ""); + fprintf (out, " %s\n break;\n\n", + rules[rule].action); } } diff --git a/src/parse-gram.c b/src/parse-gram.c new file mode 100644 index 00000000..efb6d0b8 --- /dev/null +++ b/src/parse-gram.c @@ -0,0 +1,1790 @@ +/* A Bison parser, made from parse-gram.y + by GNU bison 1.49b. */ + +/* Skeleton output parser for Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software + Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* This is the parser code that is written into each bison parser when + the %semantic_parser declaration is not specified in the grammar. + It was written by Richard Stallman by simplifying the original so + called ``semantic'' parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Pure parsers. */ +#define YYPURE 1 + +/* Using locations. */ +#define YYLSP_NEEDED 1 + +/* If NAME_PREFIX is specified substitute the variables and functions + names. */ +#define yyparse gram_parse +#define yylex gram_lex +#define yyerror gram_error +#define yylval gram_lval +#define yychar gram_char +#define yydebug gram_debug +#define yynerrs gram_nerrs +#if YYLSP_NEEDED +# define yylloc gram_lloc +#endif + + +/* Copy the first part of user declarations. */ +#line 31 "parse-gram.y" + +#include "system.h" +#include "muscle_tab.h" +#include "files.h" +#include "getargs.h" +#include "output.h" +#include "gram.h" +#include "reader.h" +#include "conflicts.h" + +/* Pass the control structure to YYPARSE and YYLEX. */ +#define YYPARSE_PARAM gram_control +#define YYLEX_PARAM gram_control +/* YYPARSE receives GRAM_CONTROL as a void *. Provide a + correctly typed access to it. */ +#define yycontrol ((gram_control_t *) gram_control) + +/* Request detailed parse error messages, and pass them to + GRAM_ERROR. */ +#undef yyerror +#define yyerror(Msg) \ + gram_error (yycontrol, &yylloc, Msg) + +/* When debugging our pure parser, we want to see values and locations + of the tokens. */ +#define YYPRINT(File, Type, Value) \ + yyprint (File, &yylloc, Type, &Value) +static void yyprint (FILE *file, const yyltype *loc, + int type, const yystype *value); + +symbol_class current_class = unknown_sym; +char *current_type = 0; +symbol_t *current_lhs; +associativity current_assoc; +int current_prec = 0; + + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +#ifndef YYSTYPE +#line 70 "parse-gram.y" +typedef union +{ + symbol_t *symbol; + int integer; + char *string; + associativity assoc; +} yystype; +# define YYSTYPE yystype +# define YYSTYPE_IS_TRIVIAL 1 +#endif + +#ifndef YYLTYPE +typedef struct yyltype +{ + int first_line; + int first_column; + int last_line; + int last_column; +} yyltype; +# define YYLTYPE yyltype +# define YYLTYPE_IS_TRIVIAL 1 +#endif + +/* Copy the second part of user declarations. */ + + +/* Line 215 of /usr/local/share/bison/bison.simple. */ +#line 145 "parse-gram.c" + +#if ! defined (yyoverflow) || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# if YYSTACK_USE_ALLOCA +# define YYSTACK_ALLOC alloca +# else +# ifndef YYSTACK_USE_ALLOCA +# if defined (alloca) || defined (_ALLOCA_H) +# define YYSTACK_ALLOC alloca +# else +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# else +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# endif +# define YYSTACK_ALLOC malloc +# define YYSTACK_FREE free +# endif +#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ + + +#if (! defined (yyoverflow) \ + && (! defined (__cplusplus) \ + || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + short yyss; + YYSTYPE yyvs; +# if YYLSP_NEEDED + YYLTYPE yyls; +# endif +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# if YYLSP_NEEDED +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAX) +# else +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAX) +# endif + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + register YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (0) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack, Stack, yysize); \ + Stack = &yyptr->Stack; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) + +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# if defined (__STDC__) || defined (__cplusplus) + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + GRAM_EOF = 0, + STRING = 258, + CHARACTER = 259, + INT = 260, + PERCENT_TOKEN = 261, + PERCENT_NTERM = 262, + PERCENT_TYPE = 263, + PERCENT_UNION = 264, + PERCENT_EXPECT = 265, + PERCENT_START = 266, + PERCENT_LEFT = 267, + PERCENT_RIGHT = 268, + PERCENT_NONASSOC = 269, + PERCENT_PREC = 270, + PERCENT_VERBOSE = 271, + PERCENT_ERROR_VERBOSE = 272, + PERCENT_OUTPUT = 273, + PERCENT_FILE_PREFIX = 274, + PERCENT_NAME_PREFIX = 275, + PERCENT_DEFINE = 276, + PERCENT_PURE_PARSER = 277, + PERCENT_DEFINES = 278, + PERCENT_YACC = 279, + PERCENT_DEBUG = 280, + PERCENT_LOCATIONS = 281, + PERCENT_NO_LINES = 282, + PERCENT_SKELETON = 283, + PERCENT_TOKEN_TABLE = 284, + TYPE = 285, + EQUAL = 286, + SEMICOLON = 287, + COLON = 288, + PIPE = 289, + ID = 290, + PERCENT_PERCENT = 291, + PROLOGUE = 292, + EPILOGUE = 293, + BRACED_CODE = 294 + }; +# endif + /* POSIX requires `int' for tokens in interfaces. */ +# define YYTOKENTYPE int +#endif /* !YYTOKENTYPE */ +#define GRAM_EOF 0 +#define STRING 258 +#define CHARACTER 259 +#define INT 260 +#define PERCENT_TOKEN 261 +#define PERCENT_NTERM 262 +#define PERCENT_TYPE 263 +#define PERCENT_UNION 264 +#define PERCENT_EXPECT 265 +#define PERCENT_START 266 +#define PERCENT_LEFT 267 +#define PERCENT_RIGHT 268 +#define PERCENT_NONASSOC 269 +#define PERCENT_PREC 270 +#define PERCENT_VERBOSE 271 +#define PERCENT_ERROR_VERBOSE 272 +#define PERCENT_OUTPUT 273 +#define PERCENT_FILE_PREFIX 274 +#define PERCENT_NAME_PREFIX 275 +#define PERCENT_DEFINE 276 +#define PERCENT_PURE_PARSER 277 +#define PERCENT_DEFINES 278 +#define PERCENT_YACC 279 +#define PERCENT_DEBUG 280 +#define PERCENT_LOCATIONS 281 +#define PERCENT_NO_LINES 282 +#define PERCENT_SKELETON 283 +#define PERCENT_TOKEN_TABLE 284 +#define TYPE 285 +#define EQUAL 286 +#define SEMICOLON 287 +#define COLON 288 +#define PIPE 289 +#define ID 290 +#define PERCENT_PERCENT 291 +#define PROLOGUE 292 +#define EPILOGUE 293 +#define BRACED_CODE 294 + + + + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 3 +#define YYFLAG -32768 +#define YYLAST 110 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 40 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 28 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 69 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 94 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 294 + +#define YYTRANSLATE(X) \ + ((unsigned)(X) <= YYMAXUTOK ? yytranslate[X] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const unsigned char yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const unsigned char yyprhs[] = +{ + 0, 0, 3, 4, 10, 11, 14, 16, 18, 20, + 24, 26, 28, 31, 35, 37, 41, 43, 47, 49, + 52, 54, 56, 58, 60, 61, 65, 68, 69, 73, + 74, 79, 83, 84, 89, 91, 93, 95, 96, 98, + 100, 103, 105, 108, 110, 112, 115, 118, 122, 124, + 127, 129, 132, 133, 139, 141, 145, 146, 149, 152, + 156, 158, 160, 162, 164, 166, 168, 169, 172, 173 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const signed char yyrhs[] = +{ + 41, 0, -1, -1, 42, 43, 36, 57, 66, -1, + -1, 43, 44, -1, 45, -1, 37, -1, 25, -1, + 21, 65, 65, -1, 23, -1, 17, -1, 10, 5, + -1, 19, 31, 65, -1, 26, -1, 20, 31, 65, + -1, 27, -1, 18, 31, 65, -1, 22, -1, 28, + 65, -1, 29, -1, 16, -1, 24, -1, 49, -1, + -1, 7, 46, 56, -1, 11, 62, -1, -1, 6, + 47, 56, -1, -1, 8, 30, 48, 53, -1, 9, + 39, 67, -1, -1, 51, 52, 50, 54, -1, 12, + -1, 13, -1, 14, -1, -1, 30, -1, 35, -1, + 53, 35, -1, 62, -1, 54, 62, -1, 30, -1, + 35, -1, 35, 5, -1, 35, 64, -1, 35, 5, + 64, -1, 55, -1, 56, 55, -1, 58, -1, 57, + 58, -1, -1, 35, 33, 59, 60, 32, -1, 61, + -1, 60, 34, 61, -1, -1, 61, 62, -1, 61, + 63, -1, 61, 15, 62, -1, 35, -1, 64, -1, + 4, -1, 39, -1, 3, -1, 3, -1, -1, 36, + 38, -1, -1, 32, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const unsigned short yyrline[] = +{ + 0, 128, 128, 128, 136, 138, 141, 143, 144, 145, + 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 161, 163, 163, 168, 172, 172, 177, + 177, 181, 189, 189, 196, 198, 199, 202, 204, 208, + 210, 214, 220, 229, 234, 239, 245, 251, 261, 264, + 268, 270, 273, 273, 278, 280, 283, 286, 288, 290, + 294, 296, 297, 300, 306, 315, 323, 328, 334, 336 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE +/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "\"end of string\"", "error", "$undefined.", "STRING", "CHARACTER", "INT", + "\"%token\"", "\"%nterm\"", "\"%type\"", "\"%union\"", "\"%expect\"", + "\"%start\"", "\"%left\"", "\"%right\"", "\"%nonassoc\"", "\"%prec\"", + "\"%verbose\"", "\"%error-verbose\"", "\"%output\"", "\"%file-prefix\"", + "\"%name-prefix\"", "\"%define\"", "\"%pure-parser\"", "\"%defines\"", + "\"%yacc\"", "\"%debug\"", "\"%locations\"", "\"%no-lines\"", + "\"%skeleton\"", "\"%token-table\"", "TYPE", "\"=\"", "\";\"", "\":\"", + "\"|\"", "\"identifier\"", "\"%%\"", "PROLOGUE", "EPILOGUE", + "BRACED_CODE", "$axiom", "input", "@1", "directives", "directive", + "grammar_directives", "@2", "@3", "@4", "precedence_directives", "@5", + "precedence_directive", "type.opt", "nterms_to_type.1", + "terms_to_prec.1", "symbol_def", "symbol_defs.1", "gram", "rules", "@6", + "rhses.1", "rhs", "symbol", "action", "string_as_id", "string_content", + "epilogue.opt", "semi_colon_opt", 0 +}; +#endif + +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const short yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, + 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, + -1 +}; + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const unsigned char yyr1[] = +{ + 0, 40, 42, 41, 43, 43, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 45, 46, 45, 45, 47, 45, 48, + 45, 45, 50, 49, 51, 51, 51, 52, 52, 53, + 53, 54, 54, 55, 55, 55, 55, 55, 56, 56, + 57, 57, 59, 58, 60, 60, 61, 61, 61, 61, + 62, 62, 62, 63, 64, 65, 66, 66, 67, 67 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const unsigned char yyr2[] = +{ + 0, 2, 0, 5, 0, 2, 1, 1, 1, 3, + 1, 1, 2, 3, 1, 3, 1, 3, 1, 2, + 1, 1, 1, 1, 0, 3, 2, 0, 3, 0, + 4, 3, 0, 4, 1, 1, 1, 0, 1, 1, + 2, 1, 2, 1, 1, 2, 2, 3, 1, 2, + 1, 2, 0, 5, 1, 3, 0, 2, 2, 3, + 1, 1, 1, 1, 1, 1, 0, 2, 0, 1 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const short yydefact[] = +{ + 2, 0, 4, 0, 0, 27, 24, 0, 0, 0, + 0, 34, 35, 36, 21, 11, 0, 0, 0, 0, + 18, 10, 22, 8, 14, 16, 0, 20, 0, 7, + 5, 6, 23, 37, 0, 0, 29, 68, 12, 64, + 62, 60, 26, 61, 0, 0, 0, 65, 0, 19, + 0, 66, 50, 38, 32, 43, 44, 48, 28, 25, + 0, 69, 31, 17, 13, 15, 9, 52, 0, 51, + 3, 0, 45, 46, 49, 39, 30, 56, 67, 33, + 41, 47, 40, 0, 54, 42, 53, 56, 0, 63, + 57, 58, 55, 59 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const short yydefgoto[] = +{ + -1, 1, 2, 4, 30, 31, 35, 34, 60, 32, + 71, 33, 54, 76, 79, 57, 58, 51, 52, 77, + 83, 84, 90, 91, 43, 48, 70, 62 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +static const short yypact[] = +{ + -32768, 9,-32768,-32768, 73,-32768,-32768, -19, -24, 12, + 0,-32768,-32768,-32768,-32768,-32768, -5, -3, -1, 26, + -32768,-32768,-32768,-32768,-32768,-32768, 26,-32768, -4,-32768, + -32768,-32768,-32768, 2, -23, -23,-32768, 4,-32768,-32768, + -32768,-32768,-32768,-32768, 26, 26, 26,-32768, 26,-32768, + 1, -17,-32768,-32768,-32768,-32768, 5,-32768, -23, -23, + 3,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 6,-32768, + -32768, 0, 36,-32768,-32768,-32768, 7,-32768,-32768, 0, + -32768,-32768,-32768, -18, -2,-32768,-32768,-32768, 0,-32768, + -32768,-32768, -2,-32768 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const short yypgoto[] = +{ + -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, + -32768,-32768,-32768,-32768,-32768, -38, 8,-32768, -11,-32768, + -32768, -46, -10,-32768, -50, -21,-32768,-32768 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. */ +static const short yytable[] = +{ + 42, 39, 40, 39, 40, 49, 73, 55, 39, 3, + 72, 36, 56, 88, 86, 37, 87, 38, 50, 68, + 74, 74, 81, 63, 64, 65, 44, 66, 45, 47, + 46, 50, 53, 41, 67, 41, 61, 89, 75, 39, + 69, 92, 82, 59, 78, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 80, 0, 0, 0, 0, 0, 0, 0, 85, + 0, 0, 0, 0, 0, 0, 0, 0, 93, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 0, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 0, 0, 0, 0, 0, 0, 28, + 29 +}; + +static const short yycheck[] = +{ + 10, 3, 4, 3, 4, 26, 56, 30, 3, 0, + 5, 30, 35, 15, 32, 39, 34, 5, 35, 36, + 58, 59, 72, 44, 45, 46, 31, 48, 31, 3, + 31, 35, 30, 35, 33, 35, 32, 39, 35, 3, + 51, 87, 35, 35, 38, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 71, -1, -1, -1, -1, -1, -1, -1, 79, + -1, -1, -1, -1, -1, -1, -1, -1, 88, 6, + 7, 8, 9, 10, 11, 12, 13, 14, -1, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, -1, -1, -1, -1, -1, -1, 36, + 37 +}; + +#if YYDEBUG +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const unsigned char yystos[] = +{ + 0, 41, 42, 0, 43, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 36, 37, + 44, 45, 49, 51, 47, 46, 30, 39, 5, 3, + 4, 35, 62, 64, 31, 31, 31, 3, 65, 65, + 35, 57, 58, 30, 52, 30, 35, 55, 56, 56, + 48, 32, 67, 65, 65, 65, 65, 33, 36, 58, + 66, 50, 5, 64, 55, 35, 53, 59, 38, 54, + 62, 64, 35, 60, 61, 62, 32, 34, 15, 39, + 62, 63, 61, 62 +}; +#endif + +#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) +# define YYSIZE_T __SIZE_TYPE__ +#endif +#if ! defined (YYSIZE_T) && defined (size_t) +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# endif +#endif +#if ! defined (YYSIZE_T) +# define YYSIZE_T unsigned int +#endif + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY -2 +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrlab1 + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ + +#define YYFAIL goto yyerrlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yychar1 = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror ("syntax error: cannot back up"); \ + YYERROR; \ + } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +/* YYLLOC_DEFAULT -- Compute the default location (before the actions + are run). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + Current.first_line = Rhs[1].first_line; \ + Current.first_column = Rhs[1].first_column; \ + Current.last_line = Rhs[N].last_line; \ + Current.last_column = Rhs[N].last_column; +#endif + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#if YYPURE +# if YYLSP_NEEDED +# ifdef YYLEX_PARAM +# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) +# else +# define YYLEX yylex (&yylval, &yylloc) +# endif +# else /* !YYLSP_NEEDED */ +# ifdef YYLEX_PARAM +# define YYLEX yylex (&yylval, YYLEX_PARAM) +# else +# define YYLEX yylex (&yylval) +# endif +# endif /* !YYLSP_NEEDED */ +#else /* !YYPURE */ +# define YYLEX yylex () +#endif /* !YYPURE */ + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +#endif /* !YYDEBUG */ + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#if YYMAXDEPTH == 0 +# undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined (__GLIBC__) && defined (_STRING_H) +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +static YYSIZE_T +# if defined (__STDC__) || defined (__cplusplus) +yystrlen (const char *yystr) +# else +yystrlen (yystr) + const char *yystr; +# endif +{ + register const char *yys = yystr; + + while (*yys++ != '\0') + continue; + + return yys - yystr - 1; +} +# endif +# endif + +# ifndef yystpcpy +# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +# if defined (__STDC__) || defined (__cplusplus) +yystpcpy (char *yydest, const char *yysrc) +# else +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +# endif +{ + register char *yyd = yydest; + register const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +#endif /* !YYERROR_VERBOSE */ + + + +/* The user can define YYPARSE_PARAM as the name of an argument to be passed + into yyparse. The argument should have type void *. + It should actually point to an object. + Grammar actions can access the variable by casting it + to the proper pointer type. */ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM +# define YYPARSE_PARAM_DECL +# else +# define YYPARSE_PARAM_ARG YYPARSE_PARAM +# define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; +# endif +#else /* !YYPARSE_PARAM */ +# define YYPARSE_PARAM_ARG +# define YYPARSE_PARAM_DECL +#endif /* !YYPARSE_PARAM */ + +/* Prevent warning if -Wstrict-prototypes. */ +#ifdef __GNUC__ +# ifdef YYPARSE_PARAM +int yyparse (void *); +# else +int yyparse (void); +# endif +#endif + +/* YY_DECL_VARIABLES -- depending whether we use a pure parser, + variables are global, or local to YYPARSE. */ + +#define YY_DECL_NON_LSP_VARIABLES \ +/* The lookahead symbol. */ \ +int yychar; \ + \ +/* The semantic value of the lookahead symbol. */ \ +YYSTYPE yylval; \ + \ +/* Number of parse errors so far. */ \ +int yynerrs; + +#if YYLSP_NEEDED +# define YY_DECL_VARIABLES \ +YY_DECL_NON_LSP_VARIABLES \ + \ +/* Location data for the lookahead symbol. */ \ +YYLTYPE yylloc; +#else +# define YY_DECL_VARIABLES \ +YY_DECL_NON_LSP_VARIABLES +#endif + +/* If nonreentrant, generate the variables here. */ + +#if !YYPURE +YY_DECL_VARIABLES +#endif /* !YYPURE */ + +int +yyparse (YYPARSE_PARAM_ARG) + YYPARSE_PARAM_DECL +{ + /* If reentrant, generate the variables here. */ +#if YYPURE + YY_DECL_VARIABLES +#endif /* !YYPURE */ + + register int yystate; + register int yyn; + int yyresult; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + /* Lookahead token as an internal (translated) token number. */ + int yychar1 = 0; + + /* Three stacks and their tools: + `yyss': related to states, + `yyvs': related to semantic values, + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + short yyssa[YYINITDEPTH]; + short *yyss = yyssa; + register short *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + register YYSTYPE *yyvsp; + +#if YYLSP_NEEDED + /* The location stack. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp; +#endif + +#if YYLSP_NEEDED +# define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) +#else +# define YYPOPSTACK (yyvsp--, yyssp--) +#endif + + YYSIZE_T yystacksize = YYINITDEPTH; + + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; +#if YYLSP_NEEDED + YYLTYPE yyloc; +#endif + + /* When reducing, the number of symbols on the RHS of the reduced + rule. */ + int yylen; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss; + yyvsp = yyvs; +#if YYLSP_NEEDED + yylsp = yyls; +#endif + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. + */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyssp >= yyss + yystacksize - 1) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. */ +# if YYLSP_NEEDED + YYLTYPE *yyls1 = yyls; + /* This used to be a conditional around just the two extra args, + but that might be undefined if yyoverflow is a macro. */ + yyoverflow ("parser stack overflow", + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yyls1, yysize * sizeof (*yylsp), + &yystacksize); + yyls = yyls1; +# else + yyoverflow ("parser stack overflow", + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yystacksize); +# endif + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyoverflowlab; +# else + /* Extend the stack our own way. */ + if (yystacksize >= YYMAXDEPTH) + goto yyoverflowlab; + yystacksize *= 2; + if (yystacksize > YYMAXDEPTH) + yystacksize = YYMAXDEPTH; + + { + short *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyoverflowlab; + YYSTACK_RELOCATE (yyss); + YYSTACK_RELOCATE (yyvs); +# if YYLSP_NEEDED + YYSTACK_RELOCATE (yyls); +# endif +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; +#if YYLSP_NEEDED + yylsp = yyls + yysize - 1; +#endif + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyssp >= yyss + yystacksize - 1) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a lookahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to lookahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* yychar is either YYEMPTY or YYEOF + or a valid token in external form. */ + + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + /* Convert token to internal form (in yychar1) for indexing tables with. */ + + if (yychar <= 0) /* This means end of input. */ + { + yychar1 = 0; + yychar = YYEOF; /* Don't call YYLEX any more. */ + + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yychar1 = YYTRANSLATE (yychar); + +#if YYDEBUG + /* We have to keep this `#if YYDEBUG', since we use variables + which are defined only if `YYDEBUG' is set. */ + if (yydebug) + { + YYFPRINTF (stderr, "Next token is %d (%s", + yychar, yytname[yychar1]); + /* Give the individual parser a way to print the precise + meaning of a token, for further debugging info. */ +# ifdef YYPRINT + YYPRINT (stderr, yychar, yylval); +# endif + YYFPRINTF (stderr, ")\n"); + } +#endif + } + + yyn += yychar1; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) + goto yydefault; + + yyn = yytable[yyn]; + + /* yyn is what to do for this token type in this state. + Negative => reduce, -yyn is rule number. + Positive => shift, yyn is new state. + New state is final state => don't bother to shift, + just return success. + 0, or most negative number => error. */ + + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrlab; + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the lookahead token. */ + YYDPRINTF ((stderr, "Shifting token %d (%s), ", + yychar, yytname[yychar1])); + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; +#if YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + yystate = yyn; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to the semantic value of + the lookahead token. This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + +#if YYLSP_NEEDED + /* Default location. */ + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); +#endif + +#if YYDEBUG + /* We have to keep this `#if YYDEBUG', since we use variables which + are defined only if `YYDEBUG' is set. */ + if (yydebug) + { + int yyi; + + YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", + yyn - 1, yyrline[yyn]); + + /* Print the symbols being reduced, and their result. */ + for (yyi = yyprhs[yyn]; yyrhs[yyi] >= 0; yyi++) + YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); + YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]); + } +#endif + switch (yyn) + { + case 2: +#line 128 "parse-gram.y" +{ LOCATION_RESET (yylloc); ; } + break; + + case 3: +#line 130 "parse-gram.y" +{ + yycontrol->errcode = 0; + epilogue_set (yyvsp[0].string, yylsp[0].first_line); + ; } + break; + + case 7: +#line 143 "parse-gram.y" +{ prologue_augment (yyvsp[0].string, yylsp[0].first_line); ; } + break; + + case 8: +#line 144 "parse-gram.y" +{ debug_flag = 1; ; } + break; + + case 9: +#line 145 "parse-gram.y" +{ muscle_insert (yyvsp[-1].string, yyvsp[0].string); ; } + break; + + case 10: +#line 146 "parse-gram.y" +{ defines_flag = 1; ; } + break; + + case 11: +#line 147 "parse-gram.y" +{ error_verbose = 1; ; } + break; + + case 12: +#line 148 "parse-gram.y" +{ expected_conflicts = yyvsp[0].integer; ; } + break; + + case 13: +#line 149 "parse-gram.y" +{ spec_file_prefix = yyvsp[0].string; ; } + break; + + case 14: +#line 150 "parse-gram.y" +{ locations_flag = 1; ; } + break; + + case 15: +#line 151 "parse-gram.y" +{ spec_name_prefix = yyvsp[0].string; ; } + break; + + case 16: +#line 152 "parse-gram.y" +{ no_lines_flag = 1; ; } + break; + + case 17: +#line 153 "parse-gram.y" +{ spec_outfile = yyvsp[0].string; ; } + break; + + case 18: +#line 154 "parse-gram.y" +{ pure_parser = 1; ; } + break; + + case 19: +#line 155 "parse-gram.y" +{ skeleton = yyvsp[0].string; ; } + break; + + case 20: +#line 156 "parse-gram.y" +{ token_table_flag = 1; ; } + break; + + case 21: +#line 157 "parse-gram.y" +{ report_flag = 1; ; } + break; + + case 22: +#line 158 "parse-gram.y" +{ yacc_flag = 1; ; } + break; + + case 24: +#line 163 "parse-gram.y" +{ current_class = nterm_sym; ; } + break; + + case 25: +#line 164 "parse-gram.y" +{ + current_class = unknown_sym; + current_type = NULL; + ; } + break; + + case 26: +#line 169 "parse-gram.y" +{ + grammar_start_symbol_set (yyvsp[0].symbol); + ; } + break; + + case 27: +#line 172 "parse-gram.y" +{ current_class = token_sym; ; } + break; + + case 28: +#line 173 "parse-gram.y" +{ + current_class = unknown_sym; + current_type = NULL; + ; } + break; + + case 29: +#line 177 "parse-gram.y" +{ current_type = yyvsp[0].string; ; } + break; + + case 30: +#line 178 "parse-gram.y" +{ + current_type = NULL; + ; } + break; + + case 31: +#line 182 "parse-gram.y" +{ + typed = 1; + MUSCLE_INSERT_INT ("stype_line", yylsp[-1].first_line); + muscle_insert ("stype", yyvsp[-1].string); + ; } + break; + + case 32: +#line 191 "parse-gram.y" +{ current_assoc = yyvsp[-1].assoc; ++current_prec; ; } + break; + + case 33: +#line 193 "parse-gram.y" +{ current_assoc = non_assoc; current_type = NULL; ; } + break; + + case 34: +#line 197 "parse-gram.y" +{ yyval.assoc = left_assoc; ; } + break; + + case 35: +#line 198 "parse-gram.y" +{ yyval.assoc = right_assoc; ; } + break; + + case 36: +#line 199 "parse-gram.y" +{ yyval.assoc = non_assoc; ; } + break; + + case 37: +#line 203 "parse-gram.y" +{ current_type = NULL;; } + break; + + case 38: +#line 204 "parse-gram.y" +{ current_type = yyvsp[0].string; ; } + break; + + case 39: +#line 209 "parse-gram.y" +{ symbol_type_set (yyvsp[0].symbol, current_type); ; } + break; + + case 40: +#line 210 "parse-gram.y" +{ symbol_type_set (yyvsp[0].symbol, current_type); ; } + break; + + case 41: +#line 216 "parse-gram.y" +{ + symbol_type_set (yyvsp[0].symbol, current_type); + symbol_precedence_set (yyvsp[0].symbol, current_prec, current_assoc); + ; } + break; + + case 42: +#line 221 "parse-gram.y" +{ + symbol_type_set (yyvsp[0].symbol, current_type); + symbol_precedence_set (yyvsp[0].symbol, current_prec, current_assoc); + ; } + break; + + case 43: +#line 231 "parse-gram.y" +{ + current_type = yyvsp[0].string; + ; } + break; + + case 44: +#line 235 "parse-gram.y" +{ + symbol_class_set (yyvsp[0].symbol, current_class); + symbol_type_set (yyvsp[0].symbol, current_type); + ; } + break; + + case 45: +#line 240 "parse-gram.y" +{ + symbol_class_set (yyvsp[-1].symbol, current_class); + symbol_type_set (yyvsp[-1].symbol, current_type); + symbol_user_token_number_set (yyvsp[-1].symbol, yyvsp[0].integer); + ; } + break; + + case 46: +#line 246 "parse-gram.y" +{ + symbol_class_set (yyvsp[-1].symbol, current_class); + symbol_type_set (yyvsp[-1].symbol, current_type); + symbol_make_alias (yyvsp[-1].symbol, yyvsp[0].symbol); + ; } + break; + + case 47: +#line 252 "parse-gram.y" +{ + symbol_class_set (yyvsp[-2].symbol, current_class); + symbol_type_set (yyvsp[-2].symbol, current_type); + symbol_user_token_number_set (yyvsp[-2].symbol, yyvsp[-1].integer); + symbol_make_alias (yyvsp[-2].symbol, yyvsp[0].symbol); + ; } + break; + + case 48: +#line 263 "parse-gram.y" +{ ;; } + break; + + case 49: +#line 265 "parse-gram.y" +{ ;; } + break; + + case 52: +#line 274 "parse-gram.y" +{ current_lhs = yyvsp[-1].symbol; ; } + break; + + case 53: +#line 275 "parse-gram.y" +{ ;; } + break; + + case 54: +#line 279 "parse-gram.y" +{ grammar_rule_end (); ; } + break; + + case 55: +#line 280 "parse-gram.y" +{ grammar_rule_end (); ; } + break; + + case 56: +#line 285 "parse-gram.y" +{ grammar_rule_begin (current_lhs); ; } + break; + + case 57: +#line 287 "parse-gram.y" +{ grammar_current_rule_symbol_append (yyvsp[0].symbol); ; } + break; + + case 58: +#line 289 "parse-gram.y" +{ grammar_current_rule_action_append (yyvsp[0].string, yylsp[0].first_line); ; } + break; + + case 59: +#line 291 "parse-gram.y" +{ grammar_current_rule_prec_set (yyvsp[0].symbol); ; } + break; + + case 60: +#line 295 "parse-gram.y" +{ yyval.symbol = yyvsp[0].symbol; ; } + break; + + case 61: +#line 296 "parse-gram.y" +{ yyval.symbol = yyvsp[0].symbol; ; } + break; + + case 62: +#line 297 "parse-gram.y" +{ yyval.symbol = getsym (yyvsp[0].string); ; } + break; + + case 63: +#line 302 "parse-gram.y" +{ yyval.string = yyvsp[0].string; ; } + break; + + case 64: +#line 308 "parse-gram.y" +{ + yyval.symbol = getsym (yyvsp[0].string); + symbol_class_set (yyval.symbol, token_sym); + ; } + break; + + case 65: +#line 317 "parse-gram.y" +{ + yyval.string = yyvsp[0].string + 1; + yyval.string[strlen (yyval.string) - 1] = '\0'; + ; } + break; + + case 66: +#line 325 "parse-gram.y" +{ + yyval.string = xstrdup (""); + ; } + break; + + case 67: +#line 329 "parse-gram.y" +{ + yyval.string = yyvsp[0].string; + ; } + break; + + + } + +/* Line 1010 of /usr/local/share/bison/bison.simple. */ +#line 1520 "parse-gram.c" + + yyvsp -= yylen; + yyssp -= yylen; +#if YYLSP_NEEDED + yylsp -= yylen; +#endif + +#if YYDEBUG + if (yydebug) + { + short *yyssp1 = yyss - 1; + YYFPRINTF (stderr, "state stack now"); + while (yyssp1 != yyssp) + YYFPRINTF (stderr, " %d", *++yyssp1); + YYFPRINTF (stderr, "\n"); + } +#endif + + *++yyvsp = yyval; +#if YYLSP_NEEDED + *++yylsp = yyloc; +#endif + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; + +#if YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (yyn > YYFLAG && yyn < YYLAST) + { + YYSIZE_T yysize = 0; + char *yymsg; + int yyx, yycount; + + yycount = 0; + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + for (yyx = yyn < 0 ? -yyn : 0; + yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) + if (yycheck[yyx + yyn] == yyx) + yysize += yystrlen (yytname[yyx]) + 15, yycount++; + yysize += yystrlen ("parse error, unexpected ") + 1; + yysize += yystrlen (yytname[YYTRANSLATE (yychar)]); + yymsg = (char *) YYSTACK_ALLOC (yysize); + if (yymsg != 0) + { + char *yyp = yystpcpy (yymsg, "parse error, unexpected "); + yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]); + + if (yycount < 5) + { + yycount = 0; + for (yyx = yyn < 0 ? -yyn : 0; + yyx < (int) (sizeof (yytname) / sizeof (char *)); + yyx++) + if (yycheck[yyx + yyn] == yyx) + { + const char *yyq = ! yycount ? ", expecting " : " or "; + yyp = yystpcpy (yyp, yyq); + yyp = yystpcpy (yyp, yytname[yyx]); + yycount++; + } + } + yyerror (yymsg); + YYSTACK_FREE (yymsg); + } + else + yyerror ("parse error; also virtual memory exhausted"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror ("parse error"); + } + goto yyerrlab1; + + +/*----------------------------------------------------. +| yyerrlab1 -- error raised explicitly by an action. | +`----------------------------------------------------*/ +yyerrlab1: + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + YYDPRINTF ((stderr, "Discarding token %d (%s).\n", + yychar, yytname[yychar1])); + yychar = YYEMPTY; + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYFLAG) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + +#if YYDEBUG + if (yydebug) + { + if (yystos[yystate] < YYNTOKENS) + { + YYFPRINTF (stderr, "Error: popping token %d (%s", + yytoknum[yystos[yystate]], yytname[yystos[yystate]]); +# ifdef YYPRINT + YYPRINT (stderr, yytoknum[yystos[yystate]], *yyvsp); +# endif + YYFPRINTF (stderr, ")\n"); + } + else + { + YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n", + yytname[yystos[yystate]]); + } + } +#endif + + yyvsp--; + yystate = *--yyssp; +#if YYLSP_NEEDED + yylsp--; +#endif + +#if YYDEBUG + if (yydebug) + { + short *yyssp1 = yyss - 1; + YYFPRINTF (stderr, "Error: state stack now"); + while (yyssp1 != yyssp) + YYFPRINTF (stderr, " %d", *++yyssp1); + YYFPRINTF (stderr, "\n"); + } +#endif + } + + if (yyn == YYFINAL) + YYACCEPT; + + YYDPRINTF ((stderr, "Shifting error token, ")); + + *++yyvsp = yylval; +#if YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +/*---------------------------------------------. +| yyoverflowab -- parser overflow comes here. | +`---------------------------------------------*/ +yyoverflowlab: + yyerror ("parser stack overflow"); + yyresult = 2; + /* Fall through. */ + +yyreturn: +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + return yyresult; +} + +#line 338 "parse-gram.y" + +/*------------------------------------------------------------------. +| When debugging the parser, display tokens' locations and values. | +`------------------------------------------------------------------*/ + +static void +yyprint (FILE *file, + const yyltype *loc, int type, const yystype *value) +{ + fputs (" (", file); + LOCATION_PRINT (file, *loc); + fputs (")", file); + switch (type) + { + case CHARACTER: + fprintf (file, " = '%s'", value->string); + break; + + case ID: + fprintf (file, " = %s", value->symbol->tag); + break; + + case INT: + fprintf (file, " = %d", value->integer); + break; + + case STRING: + fprintf (file, " = \"%s\"", value->string); + break; + + case TYPE: + fprintf (file, " = <%s>", value->string); + break; + + case BRACED_CODE: + case PROLOGUE: + case EPILOGUE: + fprintf (file, " = {{ %s }}", value->string); + break; + } +} + +void +gram_error (gram_control_t *control ATTRIBUTE_UNUSED, + yyltype *yylloc, const char *msg) +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": %s\n", msg); +} + diff --git a/src/parse-gram.h b/src/parse-gram.h new file mode 100644 index 00000000..0e2f0fcf --- /dev/null +++ b/src/parse-gram.h @@ -0,0 +1,124 @@ +#ifndef BISON_PARSE_GRAM_H +# define BISON_PARSE_GRAM_H + +/* Tokens. */ +#ifndef YYTOKENTYPE +# if defined (__STDC__) || defined (__cplusplus) + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + GRAM_EOF = 0, + STRING = 258, + CHARACTER = 259, + INT = 260, + PERCENT_TOKEN = 261, + PERCENT_NTERM = 262, + PERCENT_TYPE = 263, + PERCENT_UNION = 264, + PERCENT_EXPECT = 265, + PERCENT_START = 266, + PERCENT_LEFT = 267, + PERCENT_RIGHT = 268, + PERCENT_NONASSOC = 269, + PERCENT_PREC = 270, + PERCENT_VERBOSE = 271, + PERCENT_ERROR_VERBOSE = 272, + PERCENT_OUTPUT = 273, + PERCENT_FILE_PREFIX = 274, + PERCENT_NAME_PREFIX = 275, + PERCENT_DEFINE = 276, + PERCENT_PURE_PARSER = 277, + PERCENT_DEFINES = 278, + PERCENT_YACC = 279, + PERCENT_DEBUG = 280, + PERCENT_LOCATIONS = 281, + PERCENT_NO_LINES = 282, + PERCENT_SKELETON = 283, + PERCENT_TOKEN_TABLE = 284, + TYPE = 285, + EQUAL = 286, + SEMICOLON = 287, + COLON = 288, + PIPE = 289, + ID = 290, + PERCENT_PERCENT = 291, + PROLOGUE = 292, + EPILOGUE = 293, + BRACED_CODE = 294 + }; +# endif + /* POSIX requires `int' for tokens in interfaces. */ +# define YYTOKENTYPE int +#endif /* !YYTOKENTYPE */ +#define GRAM_EOF 0 +#define STRING 258 +#define CHARACTER 259 +#define INT 260 +#define PERCENT_TOKEN 261 +#define PERCENT_NTERM 262 +#define PERCENT_TYPE 263 +#define PERCENT_UNION 264 +#define PERCENT_EXPECT 265 +#define PERCENT_START 266 +#define PERCENT_LEFT 267 +#define PERCENT_RIGHT 268 +#define PERCENT_NONASSOC 269 +#define PERCENT_PREC 270 +#define PERCENT_VERBOSE 271 +#define PERCENT_ERROR_VERBOSE 272 +#define PERCENT_OUTPUT 273 +#define PERCENT_FILE_PREFIX 274 +#define PERCENT_NAME_PREFIX 275 +#define PERCENT_DEFINE 276 +#define PERCENT_PURE_PARSER 277 +#define PERCENT_DEFINES 278 +#define PERCENT_YACC 279 +#define PERCENT_DEBUG 280 +#define PERCENT_LOCATIONS 281 +#define PERCENT_NO_LINES 282 +#define PERCENT_SKELETON 283 +#define PERCENT_TOKEN_TABLE 284 +#define TYPE 285 +#define EQUAL 286 +#define SEMICOLON 287 +#define COLON 288 +#define PIPE 289 +#define ID 290 +#define PERCENT_PERCENT 291 +#define PROLOGUE 292 +#define EPILOGUE 293 +#define BRACED_CODE 294 + + + + +#ifndef YYSTYPE +#line 70 "parse-gram.y" +typedef union +{ + symbol_t *symbol; + int integer; + char *string; + associativity assoc; +} +yystype; +# define YYSTYPE yystype +#endif + + + +#ifndef YYLTYPE +typedef struct yyltype +{ + int first_line; + int first_column; + int last_line; + int last_column; +} yyltype; +# define YYLTYPE yyltype +#endif + + + +#endif /* not BISON_PARSE_GRAM_H */ + diff --git a/src/parse-gram.y b/src/parse-gram.y new file mode 100644 index 00000000..3cff05d1 --- /dev/null +++ b/src/parse-gram.y @@ -0,0 +1,386 @@ +/* Bison Grammar Parser -*- C -*- + Copyright (C) 2002 Free Software Foundation, Inc. + + This file is part of Bison, the GNU Compiler Compiler. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + + +%debug +%defines +%locations +%pure-parser +%error-verbose +%defines +%name-prefix="gram_" + +%{ +#include "system.h" +#include "muscle_tab.h" +#include "files.h" +#include "getargs.h" +#include "output.h" +#include "gram.h" +#include "reader.h" +#include "conflicts.h" + +/* Pass the control structure to YYPARSE and YYLEX. */ +#define YYPARSE_PARAM gram_control +#define YYLEX_PARAM gram_control +/* YYPARSE receives GRAM_CONTROL as a void *. Provide a + correctly typed access to it. */ +#define yycontrol ((gram_control_t *) gram_control) + +/* Request detailed parse error messages, and pass them to + GRAM_ERROR. */ +#undef yyerror +#define yyerror(Msg) \ + gram_error (yycontrol, &yylloc, Msg) + +/* When debugging our pure parser, we want to see values and locations + of the tokens. */ +#define YYPRINT(File, Type, Value) \ + yyprint (File, &yylloc, Type, &Value) +static void yyprint (FILE *file, const yyltype *loc, + int type, const yystype *value); + +symbol_class current_class = unknown_sym; +char *current_type = 0; +symbol_t *current_lhs; +associativity current_assoc; +int current_prec = 0; +%} + + +/* Only NUMBERS have a value. */ +%union +{ + symbol_t *symbol; + int integer; + char *string; + associativity assoc; +}; + +/* Define the tokens together with there human representation. */ +%token GRAM_EOF 0 "end of string" +%token STRING CHARACTER +%token INT + +%token PERCENT_TOKEN "%token" +%token PERCENT_NTERM "%nterm" +%token PERCENT_TYPE "%type" +%token PERCENT_UNION "%union" +%token PERCENT_EXPECT "%expect" +%token PERCENT_START "%start" +%token PERCENT_LEFT "%left" +%token PERCENT_RIGHT "%right" +%token PERCENT_NONASSOC "%nonassoc" +%token PERCENT_PREC "%prec" +%token PERCENT_VERBOSE "%verbose" +%token PERCENT_ERROR_VERBOSE "%error-verbose" + +%token PERCENT_OUTPUT "%output" +%token PERCENT_FILE_PREFIX "%file-prefix" +%token PERCENT_NAME_PREFIX "%name-prefix" + +%token PERCENT_DEFINE "%define" +%token PERCENT_PURE_PARSER "%pure-parser" + +%token PERCENT_DEFINES "%defines" + +%token PERCENT_YACC "%yacc" + +%token PERCENT_DEBUG "%debug" +%token PERCENT_LOCATIONS "%locations" +%token PERCENT_NO_LINES "%no-lines" +%token PERCENT_SKELETON "%skeleton" +%token PERCENT_TOKEN_TABLE "%token-table" + +%token TYPE +%token EQUAL "=" +%token SEMICOLON ";" +%token COLON ":" +%token PIPE "|" +%token ID "identifier" +%token PERCENT_PERCENT "%%" +%token PROLOGUE EPILOGUE +%token BRACED_CODE + +%type CHARACTER TYPE BRACED_CODE PROLOGUE EPILOGUE epilogue.opt action STRING string_content +%type INT +%type ID symbol string_as_id +%type precedence_directive +%% +input: { LOCATION_RESET (yylloc); } + directives "%%" gram epilogue.opt + { + yycontrol->errcode = 0; + epilogue_set ($5, @5.first_line); + } +; + +directives: + /* Nothing */ +| directives directive +; + +directive: + grammar_directives +| PROLOGUE { prologue_augment ($1, @1.first_line); } +| "%debug" { debug_flag = 1; } +| "%define" string_content string_content { muscle_insert ($2, $3); } +| "%defines" { defines_flag = 1; } +| "%error-verbose" { error_verbose = 1; } +| "%expect" INT { expected_conflicts = $2; } +| "%file-prefix" "=" string_content { spec_file_prefix = $3; } +| "%locations" { locations_flag = 1; } +| "%name-prefix" "=" string_content { spec_name_prefix = $3; } +| "%no-lines" { no_lines_flag = 1; } +| "%output" "=" string_content { spec_outfile = $3; } +| "%pure-parser" { pure_parser = 1; } +| "%skeleton" string_content { skeleton = $2; } +| "%token-table" { token_table_flag = 1; } +| "%verbose" { report_flag = 1; } +| "%yacc" { yacc_flag = 1; } +; + +grammar_directives: + precedence_directives +| "%nterm" { current_class = nterm_sym; } symbol_defs.1 + { + current_class = unknown_sym; + current_type = NULL; + } +| "%start" symbol + { + grammar_start_symbol_set ($2); + } +| "%token" { current_class = token_sym; } symbol_defs.1 + { + current_class = unknown_sym; + current_type = NULL; + } +| "%type" TYPE {current_type = $2; } nterms_to_type.1 + { + current_type = NULL; + } +| "%union" BRACED_CODE semi_colon_opt + { + typed = 1; + MUSCLE_INSERT_INT ("stype_line", @2.first_line); + muscle_insert ("stype", $2); + } +; + +precedence_directives: + precedence_directive type.opt + { current_assoc = $1; ++current_prec; } + terms_to_prec.1 + { current_assoc = non_assoc; current_type = NULL; } +; + +precedence_directive: + "%left" { $$ = left_assoc; } +| "%right" { $$ = right_assoc; } +| "%nonassoc" { $$ = non_assoc; } +; + +type.opt: + /* Nothing. */ { current_type = NULL;} +| TYPE { current_type = $1; } +; + +/* One or more nonterminals to be %typed. */ +nterms_to_type.1: + ID { symbol_type_set ($1, current_type); } +| nterms_to_type.1 ID { symbol_type_set ($2, current_type); } +; + +/* One or more symbols to be given a precedence/associativity. */ +terms_to_prec.1: + symbol + { + symbol_type_set ($1, current_type); + symbol_precedence_set ($1, current_prec, current_assoc); + } +| terms_to_prec.1 symbol + { + symbol_type_set ($2, current_type); + symbol_precedence_set ($2, current_prec, current_assoc); + } +; + + +/* One token definition. */ +symbol_def: + TYPE + { + current_type = $1; + } +| ID + { + symbol_class_set ($1, current_class); + symbol_type_set ($1, current_type); + } +| ID INT + { + symbol_class_set ($1, current_class); + symbol_type_set ($1, current_type); + symbol_user_token_number_set ($1, $2); + } +| ID string_as_id + { + symbol_class_set ($1, current_class); + symbol_type_set ($1, current_type); + symbol_make_alias ($1, $2); + } +| ID INT string_as_id + { + symbol_class_set ($1, current_class); + symbol_type_set ($1, current_type); + symbol_user_token_number_set ($1, $2); + symbol_make_alias ($1, $3); + } +; + +/* One or more symbol definitions. */ +symbol_defs.1: + symbol_def + {;} +| symbol_defs.1 symbol_def + {;} +; + +gram: + rules +| gram rules +; + +rules: + ID ":" { current_lhs = $1; } rhses.1 ";" + {;} +; + +rhses.1: + rhs { grammar_rule_end (); } +| rhses.1 "|" rhs { grammar_rule_end (); } +; + +rhs: + /* Nothing. */ + { grammar_rule_begin (current_lhs); } +| rhs symbol + { grammar_current_rule_symbol_append ($2); } +| rhs action + { grammar_current_rule_action_append ($2, @2.first_line); } +| rhs "%prec" symbol + { grammar_current_rule_prec_set ($3); } +; + +symbol: + ID { $$ = $1; } +| string_as_id { $$ = $1; } +| CHARACTER { $$ = getsym ($1); } +; + +action: + BRACED_CODE + { $$ = $1; } +; + +/* A string used as an ID: we have to keep the quotes. */ +string_as_id: + STRING + { + $$ = getsym ($1); + symbol_class_set ($$, token_sym); + } +; + +/* A string used for its contents. Strip the quotes. */ +string_content: + STRING + { + $$ = $1 + 1; + $$[strlen ($$) - 1] = '\0'; + }; + + +epilogue.opt: + /* Nothing. */ + { + $$ = xstrdup (""); + } +| "%%" EPILOGUE + { + $$ = $2; + } +; + +semi_colon_opt: + /* Nothing. */ +| ";" +; +%% +/*------------------------------------------------------------------. +| When debugging the parser, display tokens' locations and values. | +`------------------------------------------------------------------*/ + +static void +yyprint (FILE *file, + const yyltype *loc, int type, const yystype *value) +{ + fputs (" (", file); + LOCATION_PRINT (file, *loc); + fputs (")", file); + switch (type) + { + case CHARACTER: + fprintf (file, " = '%s'", value->string); + break; + + case ID: + fprintf (file, " = %s", value->symbol->tag); + break; + + case INT: + fprintf (file, " = %d", value->integer); + break; + + case STRING: + fprintf (file, " = \"%s\"", value->string); + break; + + case TYPE: + fprintf (file, " = <%s>", value->string); + break; + + case BRACED_CODE: + case PROLOGUE: + case EPILOGUE: + fprintf (file, " = {{ %s }}", value->string); + break; + } +} + +void +gram_error (gram_control_t *control ATTRIBUTE_UNUSED, + yyltype *yylloc, const char *msg) +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": %s\n", msg); +} diff --git a/src/reader.c b/src/reader.c index 6dd53f07..9e93cab6 100644 --- a/src/reader.c +++ b/src/reader.c @@ -27,7 +27,6 @@ #include "files.h" #include "symtab.h" #include "options.h" -#include "lex.h" #include "gram.h" #include "complain.h" #include "output.h" @@ -35,28 +34,12 @@ #include "conflicts.h" #include "muscle_tab.h" -typedef struct symbol_list -{ - struct symbol_list *next; - symbol_t *sym; - int line; - - /* The action is attached to the LHS of a rule. */ - const char *action; - int action_line; - - symbol_t *ruleprec; -} symbol_list; - int lineno; static symbol_list *grammar = NULL; static int start_flag = 0; /* Nonzero if %union has been seen. */ -static int typed = 0; - -/* Incremented for each %left, %right or %nonassoc seen */ -static int lastprec = 0; +int typed = 0; static symbol_list * symbol_list_new (symbol_t *sym) @@ -71,61 +54,13 @@ symbol_list_new (symbol_t *sym) return res; } -/*===================\ -| Low level lexing. | -\===================*/ - -static void -skip_to_char (int target) -{ - int c; - if (target == '\n') - complain (_(" Skipping to next \\n")); - else - complain (_(" Skipping to next %c"), target); - - do - c = skip_white_space (); - while (c != target && c != EOF); - if (c != EOF) - ungetc (c, finput); -} - - -/*---------------------------------------------------------. -| Read a signed integer from STREAM and return its value. | -`---------------------------------------------------------*/ - -static inline int -read_signed_integer (FILE *stream) -{ - int c = getc (stream); - int sign = 1; - int n = 0; - - if (c == '-') - { - c = getc (stream); - sign = -1; - } - - while (isdigit (c)) - { - n = 10 * n + (c - '0'); - c = getc (stream); - } - - ungetc (c, stream); - - return sign * n; -} /*--------------------------------------------------------------. | Get the data type (alternative in the union) of the value for | | symbol N in rule RULE. | `--------------------------------------------------------------*/ -static char * +char * get_type_name (int n, symbol_list *rule) { int i; @@ -153,885 +88,69 @@ get_type_name (int n, symbol_list *rule) return rp->sym->type_name; } - -/*------------------------------------------------------------------. -| Copy the character C to OOUT, and insert quadigraphs when needed. | -`------------------------------------------------------------------*/ - -static inline void -copy_character (struct obstack *oout, int c) -{ - switch (c) - { - case '[': - obstack_sgrow (oout, "@<:@"); - break; - - case ']': - obstack_sgrow (oout, "@:>@"); - break; - - default: - obstack_1grow (oout, c); - } -} - -/*------------------------------------------------------------. -| Dump the string from FIN to OOUT if non null. MATCH is the | -| delimiter of the string (either ' or "). | -`------------------------------------------------------------*/ - -static inline void -copy_string2 (FILE *fin, struct obstack *oout, int match, int store) -{ - int c; - - if (store) - obstack_1grow (oout, match); - - c = getc (fin); - - while (c != match) - { - if (c == EOF) - fatal (_("unterminated string at end of file")); - if (c == '\n') - { - complain (_("unterminated string")); - ungetc (c, fin); - c = match; /* invent terminator */ - continue; - } - - copy_character (oout, c); - - if (c == '\\') - { - c = getc (fin); - if (c == EOF) - fatal (_("unterminated string at end of file")); - copy_character (oout, c); - - if (c == '\n') - ++lineno; - } - - c = getc (fin); - } - - if (store) - obstack_1grow (oout, c); -} - -/* FIXME. */ - -static inline void -copy_string (FILE *fin, struct obstack *oout, int match) -{ - copy_string2 (fin, oout, match, 1); -} - -/* FIXME. */ - -static inline void -copy_identifier (FILE *fin, struct obstack *oout) -{ - int c; - - while (isalnum (c = getc (fin)) || c == '_') - obstack_1grow (oout, c); - - ungetc (c, fin); -} - - -/*------------------------------------------------------------------. -| Dump the wannabee comment from IN to OOUT. In fact we just saw a | -| `/', which might or might not be a comment. In any case, copy | -| what we saw. | -`------------------------------------------------------------------*/ - -static inline void -copy_comment (FILE *fin, struct obstack *oout) -{ - int cplus_comment; - int ended; - int c; - - /* We read a `/', output it. */ - obstack_1grow (oout, '/'); - - switch ((c = getc (fin))) - { - case '/': - cplus_comment = 1; - break; - case '*': - cplus_comment = 0; - break; - default: - ungetc (c, fin); - return; - } - - obstack_1grow (oout, c); - c = getc (fin); - - ended = 0; - while (!ended) - { - if (!cplus_comment && c == '*') - { - while (c == '*') - { - obstack_1grow (oout, c); - c = getc (fin); - } - - if (c == '/') - { - obstack_1grow (oout, c); - ended = 1; - } - } - else if (c == '\n') - { - ++lineno; - obstack_1grow (oout, c); - if (cplus_comment) - ended = 1; - else - c = getc (fin); - } - else if (c == EOF) - fatal (_("unterminated comment")); - else - { - copy_character (oout, c); - c = getc (fin); - } - } -} - - -/*-------------------------------------------------------------------. -| FIN is pointing to a location (i.e., a `@'). Output to OOUT a | -| reference to this location. RULE_LENGTH is the number of values in | -| the current rule so far, which says where to find `$0' with | -| respect to the top of the stack. | -`-------------------------------------------------------------------*/ - -static inline void -copy_at (FILE *fin, struct obstack *oout, int rule_length) -{ - int c = getc (fin); - locations_flag = 1; - - if (c == '$') - { - obstack_sgrow (oout, "]b4_lhs_location["); - } - else if (isdigit (c) || c == '-') - { - int n; - - ungetc (c, fin); - n = read_signed_integer (fin); - if (n > rule_length) - complain (_("invalid value: %s%d"), "@", n); - else - obstack_fgrow2 (oout, "]b4_rhs_location([%d], [%d])[", - rule_length, n); - } - else - { - char buf[] = "@c"; - buf[1] = c; - complain (_("%s is invalid"), quote (buf)); - } -} - - -/*------------------------------------------------------------------. -| FIN is pointing to a wannabee semantic value (i.e., a `$'). | -| | -| Possible inputs: $[]($|integer) | -| | -| Output to OOUT a reference to this semantic value. RULE_LENGTH is | -| the number of values in the current rule so far, which says where | -| to find `$0' with respect to the top of the stack. | -`------------------------------------------------------------------*/ - -static inline void -copy_dollar (FILE *fin, struct obstack *oout, - symbol_list *rule, int rule_length) -{ - int c = getc (fin); - const char *type_name = NULL; - - /* Get the type name if explicit. */ - if (c == '<') - { - read_type_name (fin); - type_name = token_buffer; - c = getc (fin); - } - - if (c == '$') - { - if (!type_name) - type_name = get_type_name (0, rule); - if (!type_name && typed) - complain (_("$$ of `%s' has no declared type"), - rule->sym->tag); - if (!type_name) - type_name = ""; - obstack_fgrow1 (oout, - "]b4_lhs_value([%s])[", type_name); - } - else if (isdigit (c) || c == '-') - { - int n; - ungetc (c, fin); - n = read_signed_integer (fin); - - if (n > rule_length) - complain (_("invalid value: %s%d"), "$", n); - else - { - if (!type_name && n > 0) - type_name = get_type_name (n, rule); - if (!type_name && typed) - complain (_("$%d of `%s' has no declared type"), - n, rule->sym->tag); - if (!type_name) - type_name = ""; - obstack_fgrow3 (oout, "]b4_rhs_value([%d], [%d], [%s])[", - rule_length, n, type_name); - } - } - else - { - char buf[] = "$c"; - buf[1] = c; - complain (_("%s is invalid"), quote (buf)); - } -} - -/*-------------------------------------------------------------------. -| Copy the contents of a `%{ ... %}' into the definitions file. The | -| `%{' has already been read. Return after reading the `%}'. | -`-------------------------------------------------------------------*/ - -static void -copy_definition (struct obstack *oout) -{ - int c; - /* -1 while reading a character if prev char was %. */ - int after_percent; - - if (!no_lines_flag) - { - obstack_fgrow2 (oout, muscle_find ("linef"), - lineno, quotearg_style (c_quoting_style, - muscle_find ("filename"))); - } - - after_percent = 0; - - c = getc (finput); - - for (;;) - { - switch (c) - { - case '\n': - obstack_1grow (oout, c); - ++lineno; - break; - - case '%': - after_percent = -1; - break; - case '\'': - case '"': - copy_string (finput, oout, c); - break; - case '/': - copy_comment (finput, oout); - break; +/*-----------------------. +| Set the start symbol. | +`-----------------------*/ - case EOF: - fatal ("%s", _("unterminated `%{' definition")); - - default: - copy_character (oout, c); - } - - c = getc (finput); - - if (after_percent) - { - if (c == '}') - return; - obstack_1grow (oout, '%'); - } - after_percent = 0; - } -} - - -/*------------------------------------------. -| Parse what comes after %token or %nterm. | -`------------------------------------------*/ - -static void -parse_token_decl (symbol_class class) -{ - token_t token = tok_undef; - char *typename = NULL; - - /* The symbol being defined. */ - symbol_t *symbol = NULL; - - /* After `%token' and `%nterm', any number of symbols maybe be - defined. */ - for (;;) - { - int tmp_char = ungetc (skip_white_space (), finput); - - /* `%' (for instance from `%token', or from `%%' etc.) is the - only valid means to end this declaration. */ - if (tmp_char == '%') - return; - if (tmp_char == EOF) - fatal (_("Premature EOF after %s"), token_buffer); - - token = lex (); - switch (token) - { - case tok_comma: - symbol = NULL; - break; - - case tok_typename: - typename = xstrdup (token_buffer); - symbol = NULL; - break; - - case tok_identifier: - if (*symval->tag == '\"' && symbol) - { - symbol_make_alias (symbol, symval, typename); - symbol = NULL; - } - else - { - symbol = symval; - symbol_class_set (symbol, class); - if (typename) - symbol_type_set (symbol, typename); - } - break; - - case tok_number: - symbol_user_token_number_set (symbol, numval); - break; - - default: - complain (_("`%s' is invalid in %s"), - token_buffer, - (class == token_sym) ? "%token" : "%nterm"); - skip_to_char ('%'); - } - } - -} - - -/*------------------------------. -| Parse what comes after %start | -`------------------------------*/ - -static void -parse_start_decl (void) +void +grammar_start_symbol_set (symbol_t *s) { if (start_flag) complain (_("multiple %s declarations"), "%start"); - if (lex () != tok_identifier) - complain (_("invalid %s declaration"), "%start"); else { start_flag = 1; - startsymbol = symval; + startsymbol = s; } } -/*-----------------------------------------------------------. -| read in a %type declaration and record its information for | -| get_type_name to access | -`-----------------------------------------------------------*/ - -static void -parse_type_decl (void) -{ - char *name; - - if (lex () != tok_typename) - { - complain ("%s", _("%type declaration has no ")); - skip_to_char ('%'); - return; - } - - name = xstrdup (token_buffer); - - for (;;) - { - token_t t; - int tmp_char = ungetc (skip_white_space (), finput); - - if (tmp_char == '%') - return; - if (tmp_char == EOF) - fatal (_("Premature EOF after %s"), token_buffer); - - t = lex (); - - switch (t) - { - case tok_comma: - case tok_semicolon: - break; - - case tok_identifier: - symbol_type_set (symval, name); - break; - - default: - complain (_("invalid %%type declaration due to item: %s"), - token_buffer); - skip_to_char ('%'); - } - } -} - - /*----------------------------------------------------------------. -| Read in a %left, %right or %nonassoc declaration and record its | -| information. | +| There are two prologues: one before %union, one after. Augment | +| the current one. | `----------------------------------------------------------------*/ -static void -parse_assoc_decl (associativity assoc) -{ - char *name = NULL; - int prev = 0; - - /* Assign a new precedence level, never 0. */ - ++lastprec; - - for (;;) - { - token_t t; - int tmp_char = ungetc (skip_white_space (), finput); - - if (tmp_char == '%') - return; - if (tmp_char == EOF) - fatal (_("Premature EOF after %s"), token_buffer); - - t = lex (); - - switch (t) - { - case tok_typename: - name = xstrdup (token_buffer); - break; - - case tok_comma: - break; - - case tok_identifier: - symbol_class_set (symval, token_sym); - symbol_precedence_set (symval, lastprec, assoc); - if (name) - symbol_type_set (symval, name); - break; - - case tok_number: - if (prev == tok_identifier) - { - symbol_user_token_number_set (symval, numval); - } - else - { - complain - (_("invalid text (%s) - number should be after identifier"), - token_buffer); - skip_to_char ('%'); - } - break; - - case tok_semicolon: - return; - - default: - complain (_("unexpected item: %s"), token_buffer); - skip_to_char ('%'); - } - - prev = t; - } -} - - - -/*--------------------------------------------------------------. -| Copy the union declaration into the stype muscle | -| (and fdefines), where it is made into the definition of | -| YYSTYPE, the type of elements of the parser value stack. | -`--------------------------------------------------------------*/ - -static void -parse_union_decl (void) -{ - int c; - int count = 0; - bool done = FALSE; - struct obstack union_obstack; - if (typed) - complain (_("multiple %s declarations"), "%union"); - - typed = 1; - - MUSCLE_INSERT_INT ("stype_line", lineno); - obstack_init (&union_obstack); - obstack_sgrow (&union_obstack, "union"); - - while (!done) - { - c = xgetc (finput); - - /* If C contains '/', it is output by copy_comment (). */ - if (c != '/') - obstack_1grow (&union_obstack, c); - - switch (c) - { - case '\n': - ++lineno; - break; - - case '/': - copy_comment (finput, &union_obstack); - break; - - case '{': - ++count; - break; - - case '}': - /* FIXME: Errr. How could this happen???. --akim */ - if (count == 0) - complain (_("unmatched %s"), "`}'"); - count--; - if (!count) - done = TRUE; - break; - } - } - - /* JF don't choke on trailing semi */ - c = skip_white_space (); - if (c != ';') - ungetc (c, finput); - obstack_1grow (&union_obstack, 0); - muscle_insert ("stype", obstack_finish (&union_obstack)); -} - - -/*-------------------------------------------------------. -| Parse the declaration %expect N which says to expect N | -| shift-reduce conflicts. | -`-------------------------------------------------------*/ - -static void -parse_expect_decl (void) -{ - int c = skip_white_space (); - ungetc (c, finput); - - if (!isdigit (c)) - complain (_("argument of %%expect is not an integer")); - else - expected_conflicts = read_signed_integer (finput); -} - - -static void -parse_muscle_decl (void) +void +prologue_augment (const char *prologue, int location) { - int ch = ungetc (skip_white_space (), finput); - char *muscle_key; - char *muscle_value; + struct obstack *oout = + !typed ? &pre_prologue_obstack : &post_prologue_obstack; - /* Read key. */ - if (!isalpha (ch) && ch != '_') - { - complain (_("invalid %s declaration"), "%define"); - skip_to_char ('%'); - return; - } - copy_identifier (finput, &muscle_obstack); - obstack_1grow (&muscle_obstack, 0); - muscle_key = obstack_finish (&muscle_obstack); - - /* Read value. */ - ch = skip_white_space (); - if (ch != '"') + if (!no_lines_flag) { - ungetc (ch, finput); - if (ch != EOF) - { - complain (_("invalid %s declaration"), "%define"); - skip_to_char ('%'); - return; - } - else - fatal (_("Premature EOF after %s"), "\""); + obstack_fgrow2 (oout, muscle_find ("linef"), + location, quotearg_style (c_quoting_style, + muscle_find ("filename"))); } - copy_string2 (finput, &muscle_obstack, '"', 0); - obstack_1grow (&muscle_obstack, 0); - muscle_value = obstack_finish (&muscle_obstack); - - /* Store the (key, value) pair in the environment. */ - muscle_insert (muscle_key, muscle_value); + obstack_sgrow (oout, prologue); } -/*---------------------------------. -| Parse a double quoted parameter. | -`---------------------------------*/ - -static const char * -parse_dquoted_param (const char *from) -{ - struct obstack param_obstack; - const char *param = NULL; - int c; - - obstack_init (¶m_obstack); - c = skip_white_space (); - - if (c != '"') - { - complain (_("invalid %s declaration"), from); - ungetc (c, finput); - skip_to_char ('%'); - return NULL; - } - - while ((c = literalchar ()) != '"') - obstack_1grow (¶m_obstack, c); - obstack_1grow (¶m_obstack, '\0'); - param = obstack_finish (¶m_obstack); +/*----------------------. +| Handle the epilogue. | +`----------------------*/ - if (c != '"' || strlen (param) == 0) - { - complain (_("invalid %s declaration"), from); - if (c != '"') - ungetc (c, finput); - skip_to_char ('%'); - return NULL; - } - - return param; -} - -/*----------------------------------. -| Parse what comes after %skeleton. | -`----------------------------------*/ - -static void -parse_skel_decl (void) +void +epilogue_set (const char *epilogue, int location) { - skeleton = parse_dquoted_param ("%skeleton"); -} - -/*----------------------------------------------------------------. -| Read from finput until `%%' is seen. Discard the `%%'. Handle | -| any `%' declarations, and copy the contents of any `%{ ... %}' | -| groups to PRE_PROLOGUE_OBSTACK or POST_PROLOGUE_OBSTACK. | -`----------------------------------------------------------------*/ + struct obstack el_obstack; + obstack_init (&el_obstack); -static void -read_declarations (void) -{ - for (;;) + if (!no_lines_flag) { - int c = skip_white_space (); - - if (c == '%') - { - token_t tok = parse_percent_token (); - - switch (tok) - { - case tok_two_percents: - return; - - case tok_percent_left_curly: - if (!typed) - copy_definition (&pre_prologue_obstack); - else - copy_definition (&post_prologue_obstack); - break; - - case tok_token: - parse_token_decl (token_sym); - break; - - case tok_nterm: - parse_token_decl (nterm_sym); - break; - - case tok_type: - parse_type_decl (); - break; - - case tok_start: - parse_start_decl (); - break; - - case tok_union: - parse_union_decl (); - break; - - case tok_expect: - parse_expect_decl (); - break; - - case tok_left: - parse_assoc_decl (left_assoc); - break; - - case tok_right: - parse_assoc_decl (right_assoc); - break; - - case tok_nonassoc: - parse_assoc_decl (non_assoc); - break; - - case tok_define: - parse_muscle_decl (); - break; - - case tok_skel: - parse_skel_decl (); - break; - - case tok_noop: - break; - - case tok_stropt: - case tok_intopt: - case tok_obsolete: - assert (0); - break; - - case tok_illegal: - default: - complain (_("unrecognized: %s"), token_buffer); - skip_to_char ('%'); - } - } - else if (c == EOF) - fatal (_("no input grammar")); - else - { - char buf[] = "c"; - buf[0] = c; - complain (_("unknown character: %s"), quote (buf)); - skip_to_char ('%'); - } + obstack_fgrow2 (&el_obstack, muscle_find ("linef"), + location, quotearg_style (c_quoting_style, + muscle_find ("filename"))); } + obstack_sgrow (&el_obstack, epilogue); + obstack_1grow (&el_obstack, 0); + muscle_insert ("epilogue", obstack_finish (&el_obstack)); } - -/*------------------------------------------------------------------. -| Assuming that a `{' has just been seen, copy everything up to the | -| matching `}' into ACTION_OBSTACK, and return a pointer to this | -| action. | -`------------------------------------------------------------------*/ -static char * -parse_action (symbol_list *rule) -{ - int count = 1; - - /* RULE_LENGTH is the number of values in the current rule so far, - which says where to find `$0' with respect to the top of the - stack. It is not the same as the rule->length in the case of mid - rule actions. */ - int rule_length = 0; - symbol_list *rhs; - for (rhs = rule->next; rhs; rhs = rhs->next) - ++rule_length; - - while (count > 0) - { - int c; - while ((c = getc (finput)) != '}') - switch (c) - { - case '\n': - copy_character (&action_obstack, c); - ++lineno; - break; - - case '{': - copy_character (&action_obstack, c); - ++count; - break; - - case '\'': - case '"': - copy_string (finput, &action_obstack, c); - break; - - case '/': - copy_comment (finput, &action_obstack); - break; - - case '$': - copy_dollar (finput, &action_obstack, rule, rule_length); - break; - - case '@': - copy_at (finput, &action_obstack, rule_length); - break; - - case EOF: - fatal (_("unmatched %s"), "`{'"); - - default: - copy_character (&action_obstack, c); - } - - /* Above loop exits when C is '}'. */ - if (--count) - copy_character (&action_obstack, c); - } - - obstack_1grow (&action_obstack, '\0'); - return obstack_finish (&action_obstack); -} @@ -1050,8 +169,7 @@ gensym (void) symbol_t *sym; sprintf (buf, "@%d", ++gensym_count); - token_buffer = buf; - sym = getsym (token_buffer); + sym = getsym (buf); sym->class = nterm_sym; sym->number = nvars++; return sym; @@ -1079,7 +197,7 @@ gensym (void) symbol_list *grammar_end = NULL; /* Append S to the GRAMMAR. */ -static void +void grammar_symbol_append (symbol_t *s) { symbol_list *p = symbol_list_new (s); @@ -1100,7 +218,7 @@ symbol_list *previous_rule = NULL; /* Create a new rule for LHS in to the GRAMMAR. */ -static void +void grammar_rule_begin (symbol_t *lhs) { if (!start_flag) @@ -1129,12 +247,56 @@ grammar_rule_begin (symbol_t *lhs) complain (_("rule given for %s, which is a token"), lhs->tag); } +/* Check that the last rule (CURRENT_RULE) is properly defined. For + instance, there should be no type clash on the default action. */ + +static void +grammar_current_rule_check (void) +{ + symbol_t *lhs = current_rule->sym; + symbol_t *first_rhs = current_rule->next->sym; + + /* If there is an action, then there is nothing we can do: the user + is allowed to shoot in her foot. */ + if (current_rule->action) + return; + + /* If $$ is being set in default way, report if any type mismatch. + */ + if (first_rhs) + { + const char *lhs_type = lhs->type_name ? lhs->type_name : ""; + const char *rhs_type = first_rhs->type_name ? first_rhs->type_name : ""; + if (strcmp (lhs_type, rhs_type)) + complain (_("type clash (`%s' `%s') on default action"), + lhs_type, rhs_type); + } + /* Warn if there is no default for $$ but we need one. */ + else + { + if (lhs->type_name) + complain (_("empty rule for typed nonterminal, and no action")); + } +} + + +/* End the currently being grown rule. */ + +void +grammar_rule_end (void) +{ + /* Put an empty link in the list to mark the end of this rule */ + grammar_symbol_append (NULL); + grammar_current_rule_check (); +} + + /* The previous action turns out the be a mid-rule action. Attach it to the current rule, i.e., create a dummy symbol, attach it this mid-rule action, and append this dummy nonterminal to the current rule. */ -static void +void grammar_midrule_action (void) { /* Since the action was written out with this rule's number, we must @@ -1174,7 +336,7 @@ grammar_midrule_action (void) /* Set the precedence symbol of the current rule to PRECSYM. */ -static void +void grammar_current_rule_prec_set (symbol_t *precsym) { if (current_rule->ruleprec) @@ -1182,43 +344,10 @@ grammar_current_rule_prec_set (symbol_t *precsym) current_rule->ruleprec = precsym; } -/* Check that the last rule (CURRENT_RULE) is properly defined. For - instance, there should be no type clash on the default action. */ - -static void -grammar_current_rule_check (void) -{ - symbol_t *lhs = current_rule->sym; - symbol_t *first_rhs = current_rule->next->sym; - - /* If there is an action, then there is nothing we can do: the user - is allowed to shoot in her foot. */ - if (current_rule->action) - return; - - /* If $$ is being set in default way, report if any type mismatch. - */ - if (first_rhs) - { - const char *lhs_type = lhs->type_name ? lhs->type_name : ""; - const char *rhs_type = first_rhs->type_name ? first_rhs->type_name : ""; - if (strcmp (lhs_type, rhs_type)) - complain (_("type clash (`%s' `%s') on default action"), - lhs_type, rhs_type); - } - /* Warn if there is no default for $$ but we need one. */ - else - { - if (lhs->type_name) - complain (_("empty rule for typed nonterminal, and no action")); - } -} - - /* Attach a SYMBOL to the current rule. If needed, move the previous action as a mid-rule action. */ -static void +void grammar_current_rule_symbol_append (symbol_t *symbol) { if (current_rule->action) @@ -1231,8 +360,8 @@ grammar_current_rule_symbol_append (symbol_t *symbol) /* Attach an ACTION to the current rule. If needed, move the previous action as a mid-rule action. */ -static void -grammar_current_rule_action_append (char *action, int action_line) +void +grammar_current_rule_action_append (const char *action, int action_line) { if (current_rule->action) grammar_midrule_action (); @@ -1240,171 +369,6 @@ grammar_current_rule_action_append (char *action, int action_line) current_rule->action_line = action_line; } - - -static void -readgram (void) -{ - token_t t; - symbol_t *lhs = NULL; - - t = lex (); - - while (t != tok_two_percents && t != tok_eof) - if (t == tok_identifier || t == tok_bar) - { - if (t == tok_identifier) - { - lhs = symval; - - t = lex (); - if (t != tok_colon) - { - complain (_("ill-formed rule: initial symbol not followed by colon")); - unlex (t); - } - } - if (nrules == 0 && t == tok_bar) - { - complain (_("grammar starts with vertical bar")); - lhs = symval; /* BOGUS: use a random symval */ - } - - grammar_rule_begin (lhs); - /* read the rhs of the rule. */ - - for (;;) - { - t = lex (); - if (t == tok_prec) - { - t = lex (); - grammar_current_rule_prec_set (symval); - t = lex (); - } - - if (!(t == tok_identifier || t == tok_left_curly)) - break; - - /* If next token is an identifier, see if a colon follows it. - If one does, exit this rule now. */ - if (t == tok_identifier) - { - symbol_t *ssave; - token_t t1; - - ssave = symval; - t1 = lex (); - unlex (t1); - symval = ssave; - if (t1 == tok_colon) - { - warn (_("previous rule lacks an ending `;'")); - break; - } - /* Not followed by colon => process as part of this - rule's rhs. */ - } - - if (t == tok_identifier) - { - grammar_current_rule_symbol_append (symval); - } - else /* handle an action. */ - { - int action_line = lineno; - char *action = parse_action (current_rule); - grammar_current_rule_action_append (action, action_line); - } - } /* end of read rhs of rule */ - - /* Put an empty link in the list to mark the end of this rule */ - grammar_symbol_append (NULL); - - if (t == tok_prec) - { - t = lex (); - grammar_current_rule_prec_set (symval); - t = lex (); - } - - if (t == tok_left_curly) - { - int action_line = lineno; - char *action = parse_action (current_rule); - grammar_current_rule_action_append (action, action_line); - t = lex (); - } - - grammar_current_rule_check (); - - if (t == tok_two_percents || t == tok_eof) - warn (_("previous rule lacks an ending `;'")); - if (t == tok_semicolon) - t = lex (); - } - else - { - complain (_("invalid input: %s"), quote (token_buffer)); - t = lex (); - } - - /* grammar has been read. Do some checking */ - - if (nrules == 0) - fatal (_("no rules in the input grammar")); - - /* Report any undefined symbols and consider them nonterminals. */ - symbols_check_defined (); - - /* Insert the initial rule, which line is that of the first rule - (not that of the start symbol): - - axiom: %start EOF. */ - { - symbol_list *p = symbol_list_new (axiom); - p->line = grammar->line; - p->next = symbol_list_new (startsymbol); - p->next->next = symbol_list_new (eoftoken); - p->next->next->next = symbol_list_new (NULL); - p->next->next->next->next = grammar; - nrules += 1; - nritems += 3; - grammar = p; - } - - if (nsyms > SHRT_MAX) - fatal (_("too many symbols (tokens plus nonterminals); maximum %d"), - SHRT_MAX); - - assert (nsyms == ntokens + nvars); -} - -/* At the end of the grammar file, some C source code must - be stored. It is going to be associated to the epilogue - directive. */ -static void -read_additionnal_code (void) -{ - int c; - struct obstack el_obstack; - - obstack_init (&el_obstack); - - if (!no_lines_flag) - { - obstack_fgrow2 (&el_obstack, muscle_find ("linef"), - lineno, quotearg_style (c_quoting_style, - muscle_find ("filename"))); - } - - while ((c = getc (finput)) != EOF) - copy_character (&el_obstack, c); - - obstack_1grow (&el_obstack, 0); - muscle_insert ("epilogue", obstack_finish (&el_obstack)); -} - /*---------------------------------------------------------------. | Convert the rules into the representation using RRHS, RLHS and | @@ -1481,7 +445,7 @@ packgram (void) void reader (void) { - lex_init (); + gram_control_t gram_control; lineno = 1; /* Initialize the muscle obstack. */ @@ -1513,11 +477,18 @@ reader (void) obstack_init (&post_prologue_obstack); finput = xfopen (infile, "r"); + gram_in = finput; + + gram_debug = !!getenv ("parse"); + gram__flex_debug = !!getenv ("scan"); + gram_parse (&gram_control); - /* Read the declaration section. Copy %{ ... %} groups to - TABLE_OBSTACK and FDEFINES file. Also notice any %token, %left, - etc. found there. */ - read_declarations (); + /* Grammar has been read. Do some checking */ + if (nrules == 0) + fatal (_("no rules in the input grammar")); + + /* Report any undefined symbols and consider them nonterminals. */ + symbols_check_defined (); /* If the user did not define her EOFTOKEN, do it now. */ if (!eoftoken) @@ -1529,13 +500,28 @@ reader (void) eoftoken->user_token_number = 0; } - /* Read in the grammar, build grammar in list form. Write out - actions. */ - readgram (); - /* Some C code is given at the end of the grammar file. */ - read_additionnal_code (); + /* Insert the initial rule, which line is that of the first rule + (not that of the start symbol): + + axiom: %start EOF. */ + { + symbol_list *p = symbol_list_new (axiom); + p->line = grammar->line; + p->next = symbol_list_new (startsymbol); + p->next->next = symbol_list_new (eoftoken); + p->next->next->next = symbol_list_new (NULL); + p->next->next->next->next = grammar; + nrules += 1; + nritems += 3; + grammar = p; + } + + if (nsyms > SHRT_MAX) + fatal (_("too many symbols (tokens plus nonterminals); maximum %d"), + SHRT_MAX); + + assert (nsyms == ntokens + nvars); - lex_free (); xfclose (finput); /* Assign the symbols their symbol numbers. Write #defines for the diff --git a/src/reader.h b/src/reader.h index f86d3c1b..6311fe86 100644 --- a/src/reader.h +++ b/src/reader.h @@ -21,13 +21,92 @@ #ifndef READER_H_ # define READER_H_ -#include "symtab.h" +typedef struct symbol_list +{ + struct symbol_list *next; + symbol_t *sym; + int line; -/* Read in the grammar specification and record it in the format - described in gram.h. */ + /* The action is attached to the LHS of a rule. */ + const char *action; + int action_line; -void reader PARAMS ((void)); + symbol_t *ruleprec; +} symbol_list; + +# include "parse-gram.h" + +typedef int location_t; + +/* Initialize LOC. */ +# define LOCATION_RESET(Loc) \ + (Loc).first_column = (Loc).first_line = 1; \ + (Loc).last_column = (Loc).last_line = 1; + +/* Advance of NUM columns. */ +# define LOCATION_COLUMNS(Loc, Num) \ + (Loc).last_column += Num; + +/* Advance of NUM lines. */ +# define LOCATION_LINES(Loc, Num) \ + (Loc).last_column = 1; \ + (Loc).last_line += Num; + +/* Restart: move the first cursor to the last position. */ +# define LOCATION_STEP(Loc) \ + (Loc).first_column = (Loc).last_column; \ + (Loc).first_line = (Loc).last_line; + +/* Output LOC on the stream OUT. */ +# define LOCATION_PRINT(Out, Loc) \ + fprintf (stderr, "%s:", infile); \ + if ((Loc).first_line != (Loc).last_line) \ + fprintf (Out, "%d.%d-%d.%d", \ + (Loc).first_line, (Loc).first_column, \ + (Loc).last_line, (Loc).last_column - 1); \ + else if ((Loc).first_column < (Loc).last_column - 1) \ + fprintf (Out, "%d.%d-%d", (Loc).first_line, \ + (Loc).first_column, (Loc).last_column - 1); \ + else \ + fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column) -extern int lineno; +typedef struct gram_control_s +{ + int errcode; +} gram_control_t; + +/* From the scanner. */ +extern FILE *gram_in; +extern int gram__flex_debug; + +# define YY_DECL \ + int gram_lex (yystype *yylval, yyltype *yylloc, \ + gram_control_t *yycontrol) +YY_DECL; + + +/* From the parser. */ +extern int gram_debug; +void gram_error (gram_control_t *control, + yyltype *loc, const char *msg); +int gram_parse (void *control); + +char *get_type_name PARAMS ((int n, symbol_list *rule)); +extern int typed; + +/* From reader.c. */ +void grammar_start_symbol_set PARAMS ((symbol_t *s)); +void prologue_augment PARAMS ((const char *prologue, location_t location)); +void epilogue_set PARAMS ((const char *epilogue, location_t location)); +void grammar_symbol_append PARAMS ((symbol_t *s)); +void grammar_rule_begin PARAMS ((symbol_t *lhs)); +void grammar_rule_end PARAMS ((void)); +void grammar_midrule_action PARAMS ((void)); +void grammar_current_rule_prec_set PARAMS ((symbol_t *precsym)); +void grammar_current_rule_symbol_append PARAMS ((symbol_t *symbol)); +void grammar_current_rule_action_append PARAMS ((const char *action, + int line)); +extern symbol_list *current_rule; +void reader PARAMS ((void)); #endif /* !READER_H_ */ diff --git a/src/scan-action.l b/src/scan-action.l new file mode 100644 index 00000000..8e498a85 --- /dev/null +++ b/src/scan-action.l @@ -0,0 +1,46 @@ +/* Scan User Actions. -*- C -*- + Copyright (C) 2002 Free Software Foundation, Inc. + + This file is part of Bison, the GNU Compiler Compiler. + + Bison is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + Bison is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bison; see the file COPYING. If not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +%option nodefault noyywrap nounput +%option prefix="action_" outfile="lex.yy.c" + +%{ +#include "system.h" +#include "files.h" +int skel_lex PARAMS ((void)); +static int yylineno = 1; +%} + +%x DOLLAR + +ID [a-zA-Z]+ +NUM -?[0-9]+ + +%% +$(-?[0-9])+ { fprintf (action_out, "yylsp[%s]", yytext + 1) ;} +@(-?[0-9])+ { fprintf (action_out, "yylsp[%s]", yytext + 1) ;} +$<{ID} { action_type = xstrndup (yytext + 2, yyleng - 2); BEGIN DOLLAR;} +$ { BEGIN DOLLAR;} + + +{ + {NUM}> { fprintf (action_out, "yyvsp[%s]", NUM } +} +%% diff --git a/src/scan-gram.c b/src/scan-gram.c new file mode 100644 index 00000000..d384f2d7 --- /dev/null +++ b/src/scan-gram.c @@ -0,0 +1,2750 @@ +#define yy_create_buffer gram__create_buffer +#define yy_delete_buffer gram__delete_buffer +#define yy_scan_buffer gram__scan_buffer +#define yy_scan_string gram__scan_string +#define yy_scan_bytes gram__scan_bytes +#define yy_flex_debug gram__flex_debug +#define yy_init_buffer gram__init_buffer +#define yy_flush_buffer gram__flush_buffer +#define yy_load_buffer_state gram__load_buffer_state +#define yy_switch_to_buffer gram__switch_to_buffer +#define yyin gram_in +#define yyleng gram_leng +#define yylex gram_lex +#define yyout gram_out +#define yyrestart gram_restart +#define yytext gram_text + +#line 19 "scan-gram.c" +/* A lexical scanner generated by flex */ + +/* Scanner skeleton version: + * $Header$ + */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 + +#include + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include +#include + +/* Use prototypes in function declarations. */ +#define YY_USE_PROTOS + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef __TURBOC__ + #pragma warn -rch + #pragma warn -use +#include +#include +#define YY_USE_CONST +#define YY_USE_PROTOS +#endif + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#define YY_BUF_SIZE 16384 + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +extern int yyleng; +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* The funky do-while in the following #define is used to turn the definition + * int a single C statement (which needs a semi-colon terminator). This + * avoids problems with code like: + * + * if ( condition_holds ) + * yyless( 5 ); + * else + * do_something_else(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the yyless() call. + */ + +/* Return all but the first 'n' matched characters back to the input stream. */ + +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + *yy_cp = yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yytext_ptr ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ +typedef unsigned int yy_size_t; + + +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + }; + +static YY_BUFFER_STATE yy_current_buffer = 0; + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart YY_PROTO(( FILE *input_file )); + +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); +void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); +#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) + +YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); +YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); +YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); + +static void *yy_flex_alloc YY_PROTO(( yy_size_t )); +static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); +static void yy_flex_free YY_PROTO(( void * )); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) + + +#define yywrap() 1 +#define YY_SKIP_YYWRAP + +#define FLEX_DEBUG +typedef unsigned char YY_CHAR; +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; +typedef int yy_state_type; + +#define FLEX_DEBUG +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 92 +#define YY_END_OF_BUFFER 93 +static yyconst short int yy_accept[355] = + { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 93, 44, + 33, 32, 32, 37, 44, 36, 34, 44, 35, 29, + 31, 44, 28, 41, 30, 48, 49, 49, 50, 45, + 46, 73, 75, 75, 72, 45, 92, 46, 69, 71, + 71, 68, 92, 52, 53, 53, 51, 92, 55, 56, + 56, 54, 84, 85, 85, 77, 86, 76, 86, 86, + 45, 46, 81, 80, 88, 90, 90, 77, 92, 76, + 88, 91, 91, 91, 77, 76, 91, 33, 32, 32, + 32, 32, 43, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 40, 34, 38, + 39, 35, 0, 48, 49, 49, 49, 49, 47, 73, + 75, 75, 75, 75, 74, 71, 71, 71, 71, 70, + 52, 53, 53, 53, 53, 67, 66, 67, 59, 60, + 61, 62, 63, 64, 65, 67, 56, 56, 56, 56, + 84, 85, 85, 85, 85, 82, 0, 82, 0, 78, + 79, 83, 0, 83, 88, 90, 90, 90, 90, 89, + 0, 87, 78, 79, 91, 91, 91, 91, 91, 78, + 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 39, 42, 0, 0, 0, 0, 79, + 79, 79, 79, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 57, 58, + 82, 0, 82, 0, 0, 0, 0, 0, 0, 0, + 9, 0, 0, 0, 0, 0, 0, 16, 0, 0, + 0, 0, 21, 0, 24, 0, 0, 27, 0, 2, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, + 0, 0, 18, 0, 20, 22, 25, 0, 1, 3, + 0, 6, 0, 0, 0, 0, 0, 0, 15, 0, + + 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, + 12, 13, 0, 19, 0, 0, 0, 0, 10, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, + 0, 11, 17, 23, 0, 0, 5, 0, 0, 0, + 0, 0, 8, 0 + } ; + +static yyconst int yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 2, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 5, 1, 6, 7, 1, 8, 1, + 1, 9, 1, 1, 10, 11, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 14, 14, 15, 16, 17, + 18, 19, 1, 20, 21, 21, 21, 21, 21, 21, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 22, 23, 24, 1, 25, 1, 26, 27, 28, 29, + + 30, 31, 32, 33, 34, 11, 35, 36, 37, 38, + 39, 40, 11, 41, 42, 43, 44, 45, 11, 46, + 47, 11, 48, 49, 50, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst int yy_meta[51] = + { 0, + 1, 1, 2, 3, 4, 5, 6, 5, 7, 1, + 8, 5, 9, 9, 1, 1, 1, 1, 10, 5, + 9, 11, 12, 11, 8, 9, 9, 9, 9, 9, + 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 5, 1, 5 + } ; + +static yyconst short int yy_base[382] = + { 0, + 0, 0, 48, 51, 58, 61, 83, 86, 73, 94, + 108, 110, 131, 179, 227, 249, 116, 142, 798, 799, + 795, 55, 64, 799, 267, 799, 0, 44, 79, 799, + 799, 0, 799, 799, 799, 0, 97, 99, 784, 799, + 799, 0, 119, 122, 799, 799, 0, 799, 799, 126, + 138, 799, 0, 0, 145, 153, 799, 311, 799, 155, + 157, 799, 0, 159, 164, 799, 159, 799, 62, 164, + 799, 799, 799, 799, 0, 185, 189, 0, 125, 0, + 185, 192, 201, 203, 205, 207, 209, 793, 211, 213, + 216, 219, 799, 760, 763, 187, 758, 49, 198, 747, + + 199, 756, 109, 208, 751, 758, 761, 799, 0, 799, + 0, 212, 767, 0, 241, 255, 259, 261, 799, 0, + 263, 265, 272, 274, 799, 276, 278, 280, 282, 799, + 0, 284, 286, 288, 296, 799, 799, 772, 799, 799, + 799, 799, 799, 799, 799, 0, 298, 314, 316, 318, + 0, 322, 324, 326, 328, 799, 322, 326, 765, 799, + 0, 799, 330, 332, 0, 344, 347, 355, 357, 243, + 263, 799, 0, 358, 360, 363, 365, 367, 369, 371, + 373, 745, 159, 741, 741, 200, 749, 751, 741, 368, + 747, 733, 745, 733, 741, 742, 745, 729, 734, 728, + + 733, 725, 737, 0, 799, 751, 0, 744, 373, 0, + 377, 385, 399, 736, 717, 726, 720, 728, 727, 726, + 712, 728, 723, 716, 725, 709, 709, 720, 717, 713, + 709, 703, 706, 712, 711, 701, 712, 710, 799, 799, + 718, 377, 391, 695, 703, 696, 692, 704, 721, 701, + 799, 686, 375, 694, 685, 689, 681, 799, 388, 681, + 693, 679, 799, 683, 799, 682, 680, 799, 671, 799, + 665, 401, 640, 631, 402, 625, 616, 598, 593, 799, + 589, 587, 799, 581, 799, 404, 799, 581, 799, 578, + 569, 799, 572, 573, 572, 558, 560, 550, 799, 562, + + 537, 521, 526, 799, 525, 524, 507, 509, 513, 500, + 510, 387, 387, 398, 799, 381, 389, 376, 376, 386, + 799, 799, 374, 799, 381, 367, 321, 313, 799, 307, + 303, 287, 265, 249, 228, 214, 207, 212, 160, 799, + 157, 799, 799, 799, 168, 405, 799, 149, 137, 91, + 85, 62, 799, 799, 430, 442, 454, 466, 478, 490, + 502, 514, 519, 528, 540, 552, 562, 574, 586, 597, + 609, 621, 633, 645, 657, 86, 669, 681, 693, 705, + 60 + } ; + +static yyconst short int yy_def[382] = + { 0, + 354, 1, 355, 355, 356, 356, 357, 357, 358, 358, + 359, 359, 360, 360, 361, 361, 362, 362, 354, 354, + 354, 354, 354, 354, 354, 354, 363, 354, 354, 354, + 354, 364, 354, 354, 354, 365, 354, 354, 354, 354, + 354, 366, 354, 354, 354, 354, 367, 354, 354, 354, + 354, 354, 368, 369, 354, 354, 354, 370, 354, 354, + 354, 354, 371, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 372, 354, 354, 372, 373, 372, + 372, 374, 374, 374, 374, 374, 374, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + + 354, 354, 354, 354, 354, 354, 354, 354, 363, 354, + 375, 354, 364, 365, 354, 354, 354, 354, 354, 366, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 369, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 376, 354, 354, 354, 354, + 371, 354, 354, 354, 354, 354, 354, 354, 377, 354, + 378, 354, 354, 354, 372, 354, 354, 354, 354, 373, + 373, 354, 372, 379, 374, 374, 374, 374, 374, 374, + 380, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + + 354, 354, 354, 375, 354, 354, 381, 377, 377, 378, + 379, 380, 380, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 377, 377, 377, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 0, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354 + } ; + +static yyconst short int yy_nxt[850] = + { 0, + 20, 21, 22, 23, 24, 20, 25, 26, 20, 20, + 27, 28, 29, 29, 30, 31, 32, 33, 20, 20, + 27, 20, 20, 20, 20, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, + 27, 27, 27, 27, 27, 27, 27, 34, 35, 20, + 37, 38, 110, 37, 38, 111, 39, 89, 90, 39, + 43, 44, 45, 43, 44, 45, 91, 92, 240, 40, + 160, 41, 40, 161, 41, 55, 56, 57, 187, 46, + 47, 48, 46, 47, 48, 50, 51, 188, 50, 51, + 52, 112, 112, 52, 207, 58, 55, 56, 57, 115, + + 116, 117, 118, 353, 46, 53, 48, 46, 53, 48, + 60, 61, 60, 61, 352, 62, 58, 62, 83, 84, + 85, 121, 122, 86, 123, 124, 351, 87, 126, 127, + 58, 171, 58, 64, 65, 66, 67, 46, 68, 48, + 128, 129, 69, 196, 83, 84, 85, 132, 133, 86, + 70, 197, 71, 87, 72, 134, 135, 147, 148, 149, + 150, 152, 153, 46, 156, 48, 154, 155, 157, 162, + 350, 158, 158, 163, 172, 159, 164, 164, 73, 349, + 74, 64, 65, 66, 67, 215, 68, 166, 167, 216, + 69, 168, 169, 173, 176, 177, 174, 347, 70, 346, + + 71, 345, 72, 176, 178, 179, 177, 176, 177, 176, + 177, 176, 177, 89, 90, 91, 92, 180, 89, 90, + 181, 91, 92, 189, 112, 112, 73, 184, 74, 76, + 77, 78, 185, 79, 80, 219, 190, 198, 81, 193, + 191, 344, 194, 115, 116, 220, 199, 343, 46, 354, + 48, 76, 77, 78, 200, 79, 80, 117, 118, 342, + 81, 115, 116, 117, 118, 121, 122, 123, 124, 171, + 46, 341, 48, 93, 121, 122, 123, 124, 126, 127, + 128, 129, 126, 127, 128, 129, 132, 133, 134, 135, + 132, 133, 354, 94, 340, 95, 96, 97, 134, 135, + + 147, 148, 98, 339, 99, 100, 101, 102, 103, 104, + 105, 106, 354, 107, 108, 137, 149, 150, 147, 148, + 149, 150, 338, 138, 152, 153, 154, 155, 152, 153, + 154, 155, 337, 137, 158, 158, 139, 140, 158, 158, + 336, 141, 164, 164, 164, 164, 166, 167, 142, 168, + 169, 143, 335, 144, 334, 145, 146, 166, 167, 168, + 169, 210, 176, 177, 210, 176, 178, 179, 177, 179, + 177, 176, 178, 176, 177, 176, 213, 224, 241, 210, + 210, 210, 242, 210, 277, 243, 243, 176, 213, 243, + 243, 209, 224, 333, 210, 209, 210, 282, 210, 277, + + 210, 179, 213, 243, 243, 225, 210, 332, 210, 209, + 291, 294, 282, 302, 348, 331, 330, 329, 328, 327, + 210, 326, 210, 325, 324, 291, 294, 323, 302, 348, + 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, + 36, 36, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 54, 54, 54, 54, + 54, 54, 54, 54, 54, 54, 54, 54, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + + 63, 63, 75, 75, 75, 75, 75, 75, 75, 75, + 75, 75, 75, 75, 82, 82, 82, 82, 82, 82, + 82, 82, 82, 82, 82, 82, 109, 109, 113, 113, + 113, 113, 113, 113, 113, 113, 113, 322, 113, 113, + 114, 321, 320, 114, 114, 114, 319, 114, 114, 114, + 318, 114, 120, 317, 316, 315, 120, 120, 120, 120, + 120, 120, 125, 314, 125, 125, 125, 125, 125, 125, + 125, 125, 125, 125, 130, 313, 130, 130, 130, 130, + 130, 130, 130, 130, 130, 130, 131, 312, 311, 310, + 131, 131, 131, 131, 131, 131, 131, 136, 309, 136, + + 136, 136, 136, 136, 136, 136, 136, 136, 136, 151, + 308, 307, 306, 305, 151, 151, 151, 151, 151, 304, + 151, 165, 303, 301, 165, 165, 300, 165, 165, 165, + 165, 299, 165, 170, 298, 297, 170, 170, 170, 170, + 170, 170, 170, 170, 170, 175, 175, 175, 175, 175, + 175, 175, 175, 175, 175, 296, 175, 204, 295, 204, + 204, 204, 204, 204, 204, 204, 204, 204, 204, 208, + 293, 208, 208, 208, 208, 208, 208, 208, 208, 208, + 208, 210, 292, 210, 210, 210, 210, 210, 210, 210, + 210, 210, 210, 211, 290, 211, 211, 211, 211, 211, + + 211, 211, 211, 211, 211, 212, 212, 212, 212, 212, + 212, 212, 212, 212, 212, 212, 212, 289, 288, 287, + 286, 285, 284, 283, 281, 280, 279, 278, 276, 275, + 274, 273, 272, 271, 270, 269, 209, 268, 267, 266, + 265, 264, 263, 262, 261, 260, 259, 258, 257, 256, + 255, 254, 253, 252, 251, 250, 249, 248, 247, 246, + 245, 244, 209, 239, 238, 237, 236, 235, 234, 233, + 232, 231, 230, 229, 228, 227, 226, 223, 222, 221, + 218, 217, 214, 209, 206, 205, 203, 202, 201, 195, + 192, 186, 183, 182, 88, 119, 88, 354, 19, 354, + + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354 + } ; + +static yyconst short int yy_chk[850] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 3, 3, 28, 4, 4, 28, 3, 22, 22, 4, + 5, 5, 5, 6, 6, 6, 23, 23, 381, 3, + 69, 3, 4, 69, 4, 9, 9, 9, 98, 5, + 5, 5, 6, 6, 6, 7, 7, 98, 8, 8, + 7, 29, 29, 8, 376, 9, 10, 10, 10, 37, + + 37, 38, 38, 352, 7, 7, 7, 8, 8, 8, + 11, 11, 12, 12, 351, 11, 10, 12, 17, 17, + 17, 43, 43, 17, 44, 44, 350, 17, 50, 50, + 11, 79, 12, 13, 13, 13, 13, 17, 13, 17, + 51, 51, 13, 103, 18, 18, 18, 55, 55, 18, + 13, 103, 13, 18, 13, 56, 56, 60, 60, 61, + 61, 64, 64, 18, 67, 18, 65, 65, 67, 70, + 349, 67, 67, 70, 79, 67, 70, 70, 13, 348, + 13, 14, 14, 14, 14, 183, 14, 76, 76, 183, + 14, 77, 77, 81, 82, 82, 81, 345, 14, 341, + + 14, 339, 14, 83, 83, 84, 84, 85, 85, 86, + 86, 87, 87, 89, 89, 90, 90, 87, 91, 91, + 87, 92, 92, 99, 112, 112, 14, 96, 14, 15, + 15, 15, 96, 15, 15, 186, 99, 104, 15, 101, + 99, 338, 101, 115, 115, 186, 104, 337, 15, 170, + 15, 16, 16, 16, 104, 16, 16, 116, 116, 336, + 16, 117, 117, 118, 118, 121, 121, 122, 122, 171, + 16, 335, 16, 25, 123, 123, 124, 124, 126, 126, + 127, 127, 128, 128, 129, 129, 132, 132, 133, 133, + 134, 134, 170, 25, 334, 25, 25, 25, 135, 135, + + 147, 147, 25, 333, 25, 25, 25, 25, 25, 25, + 25, 25, 171, 25, 25, 58, 148, 148, 149, 149, + 150, 150, 332, 58, 152, 152, 153, 153, 154, 154, + 155, 155, 331, 58, 157, 157, 58, 58, 158, 158, + 330, 58, 163, 163, 164, 164, 166, 166, 58, 167, + 167, 58, 328, 58, 327, 58, 58, 168, 168, 169, + 169, 174, 175, 175, 174, 176, 176, 177, 177, 178, + 178, 179, 179, 180, 180, 181, 181, 190, 209, 174, + 211, 174, 209, 211, 253, 209, 209, 212, 212, 242, + 242, 209, 190, 326, 181, 242, 181, 259, 211, 253, + + 211, 213, 213, 243, 243, 190, 212, 325, 212, 243, + 272, 275, 259, 286, 346, 323, 320, 319, 318, 317, + 213, 316, 213, 314, 313, 272, 275, 312, 286, 346, + 355, 355, 355, 355, 355, 355, 355, 355, 355, 355, + 355, 355, 356, 356, 356, 356, 356, 356, 356, 356, + 356, 356, 356, 356, 357, 357, 357, 357, 357, 357, + 357, 357, 357, 357, 357, 357, 358, 358, 358, 358, + 358, 358, 358, 358, 358, 358, 358, 358, 359, 359, + 359, 359, 359, 359, 359, 359, 359, 359, 359, 359, + 360, 360, 360, 360, 360, 360, 360, 360, 360, 360, + + 360, 360, 361, 361, 361, 361, 361, 361, 361, 361, + 361, 361, 361, 361, 362, 362, 362, 362, 362, 362, + 362, 362, 362, 362, 362, 362, 363, 363, 364, 364, + 364, 364, 364, 364, 364, 364, 364, 311, 364, 364, + 365, 310, 309, 365, 365, 365, 308, 365, 365, 365, + 307, 365, 366, 306, 305, 303, 366, 366, 366, 366, + 366, 366, 367, 302, 367, 367, 367, 367, 367, 367, + 367, 367, 367, 367, 368, 301, 368, 368, 368, 368, + 368, 368, 368, 368, 368, 368, 369, 300, 298, 297, + 369, 369, 369, 369, 369, 369, 369, 370, 296, 370, + + 370, 370, 370, 370, 370, 370, 370, 370, 370, 371, + 295, 294, 293, 291, 371, 371, 371, 371, 371, 290, + 371, 372, 288, 284, 372, 372, 282, 372, 372, 372, + 372, 281, 372, 373, 279, 278, 373, 373, 373, 373, + 373, 373, 373, 373, 373, 374, 374, 374, 374, 374, + 374, 374, 374, 374, 374, 277, 374, 375, 276, 375, + 375, 375, 375, 375, 375, 375, 375, 375, 375, 377, + 274, 377, 377, 377, 377, 377, 377, 377, 377, 377, + 377, 378, 273, 378, 378, 378, 378, 378, 378, 378, + 378, 378, 378, 379, 271, 379, 379, 379, 379, 379, + + 379, 379, 379, 379, 379, 380, 380, 380, 380, 380, + 380, 380, 380, 380, 380, 380, 380, 269, 267, 266, + 264, 262, 261, 260, 257, 256, 255, 254, 252, 250, + 249, 248, 247, 246, 245, 244, 241, 238, 237, 236, + 235, 234, 233, 232, 231, 230, 229, 228, 227, 226, + 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, + 215, 214, 208, 206, 203, 202, 201, 200, 199, 198, + 197, 196, 195, 194, 193, 192, 191, 189, 188, 187, + 185, 184, 182, 159, 138, 113, 107, 106, 105, 102, + 100, 97, 95, 94, 88, 39, 21, 19, 354, 354, + + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, + 354, 354, 354, 354, 354, 354, 354, 354, 354 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 1; + +static yyconst short int yy_rule_linenum[92] = + { 0, + 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, + 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 116, 117, 118, + 119, 121, 122, 123, 129, 132, 135, 138, 139, 142, + 145, 148, 150, 156, 172, 173, 184, 196, 197, 198, + 215, 223, 225, 244, 259, 261, 280, 292, 296, 297, + 298, 299, 300, 301, 302, 303, 304, 319, 325, 326, + 328, 346, 352, 353, 355, 373, 376, 379, 380, 391, + 401, 403, 404, 406, 407, 410, 429, 435, 436, 437, + 457 + + } ; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "scan-gram.l" +#define INITIAL 0 +/* Bison Grammar Scanner -*- C -*- + Copyright (C) 2002 Free Software Foundation, Inc. + + This file is part of Bison, the GNU Compiler Compiler. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ +#define YY_NO_UNPUT 1 +#define YY_NEVER_INTERACTIVE 1 +#define YY_STACK_USED 1 +#line 26 "scan-gram.l" +#include "system.h" +#include "complain.h" +#include "quote.h" +#include "getargs.h" +#include "gram.h" +#include "reader.h" + +/* Each time we match a string, move the end cursor to its end. */ +#define YY_USER_ACTION LOCATION_COLUMNS (*yylloc, yyleng) +#define YY_LINES LOCATION_LINES (*yylloc, yyleng); lineno += yyleng; +#define YY_STEP LOCATION_STEP (*yylloc) + +/* Appending to the STRING_OBSTACK. */ +#define YY_INIT obstack_init (&string_obstack) +#define YY_GROW obstack_grow (&string_obstack, yytext, yyleng) +#define YY_FINISH obstack_1grow (&string_obstack, '\0'); yylval->string = obstack_finish (&string_obstack); + +/* This is only to avoid GCC warnings. */ +#define YY_USER_INIT if (yycontrol) {;}; + +static struct obstack string_obstack; +static int braces_level = 0; +static int percent_percent_count = 0; + +static void handle_dollar PARAMS ((char *cp)); +static void handle_at PARAMS ((char *cp)); + +#define SC_COMMENT 1 + +#define SC_STRING 2 +#define SC_CHARACTER 3 + +#define SC_ESCAPED_STRING 4 +#define SC_ESCAPED_CHARACTER 5 + +#define SC_BRACED_CODE 6 +#define SC_PROLOGUE 7 +#define SC_EPILOGUE 8 + +#line 777 "scan-gram.c" + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap YY_PROTO(( void )); +#else +extern int yywrap YY_PROTO(( void )); +#endif +#endif + +#ifndef YY_NO_UNPUT +static void yyunput YY_PROTO(( int c, char *buf_ptr )); +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen YY_PROTO(( yyconst char * )); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif +#endif + +#if YY_STACK_USED +static int yy_start_stack_ptr = 0; +static int yy_start_stack_depth = 0; +static int *yy_start_stack = 0; +#ifndef YY_NO_PUSH_STATE +static void yy_push_state YY_PROTO(( int new_state )); +#endif +#ifndef YY_NO_POP_STATE +static void yy_pop_state YY_PROTO(( void )); +#endif +#ifndef YY_NO_TOP_STATE +static int yy_top_state YY_PROTO(( void )); +#endif + +#else +#define YY_NO_PUSH_STATE 1 +#define YY_NO_POP_STATE 1 +#define YY_NO_TOP_STATE 1 +#endif + +#ifdef YY_MALLOC_DECL +YY_MALLOC_DECL +#else +#if __STDC__ +#ifndef __cplusplus +#include +#endif +#else +/* Just try to get by without declaring the routines. This will fail + * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) + * or sizeof(void*) != sizeof(int). + */ +#endif +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ + +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( yy_current_buffer->yy_is_interactive ) \ + { \ + int c = '*', n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ + && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL int yylex YY_PROTO(( void )) +#endif + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +YY_DECL + { + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 64 "scan-gram.l" + + + /* At each yylex invocation, mark the current position as the + start of the next token. */ +#define TR_POS 0 +#if TR_POS + fprintf (stderr, "FOO1: "); + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, "\n"); +#endif + YY_STEP; +#if TR_POS + fprintf (stderr, "BAR1: "); + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, "\n"); +#endif + + + + /*----------------------------. + | Scanning Bison directives. | + `----------------------------*/ +#line 951 "scan-gram.c" + + if ( yy_init ) + { + yy_init = 0; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! yy_current_buffer ) + yy_current_buffer = + yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 355 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 799 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + +do_action: /* This label is used only to access EOF actions. */ + + if ( yy_flex_debug ) + { + if ( yy_act == 0 ) + fprintf( stderr, "--scanner backing up\n" ); + else if ( yy_act < 92 ) + fprintf( stderr, "--accepting rule at line %d (\"%s\")\n", + yy_rule_linenum[yy_act], yytext ); + else if ( yy_act == 92 ) + fprintf( stderr, "--accepting default rule (\"%s\")\n", + yytext ); + else if ( yy_act == 93 ) + fprintf( stderr, "--(end of buffer or a NUL)\n" ); + else + fprintf( stderr, "--EOF (start condition %d)\n", YY_START ); + } + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + + + +case 1: +YY_RULE_SETUP +#line 88 "scan-gram.l" +return PERCENT_NONASSOC; + YY_BREAK +case 2: +YY_RULE_SETUP +#line 89 "scan-gram.l" +return PERCENT_DEBUG; + YY_BREAK +case 3: +YY_RULE_SETUP +#line 90 "scan-gram.l" +return PERCENT_DEFINE; + YY_BREAK +case 4: +YY_RULE_SETUP +#line 91 "scan-gram.l" +return PERCENT_DEFINES; + YY_BREAK +case 5: +YY_RULE_SETUP +#line 92 "scan-gram.l" +return PERCENT_ERROR_VERBOSE; + YY_BREAK +case 6: +YY_RULE_SETUP +#line 93 "scan-gram.l" +return PERCENT_EXPECT; + YY_BREAK +case 7: +YY_RULE_SETUP +#line 94 "scan-gram.l" +return PERCENT_FILE_PREFIX; + YY_BREAK +case 8: +YY_RULE_SETUP +#line 95 "scan-gram.l" +return PERCENT_YACC; + YY_BREAK +case 9: +YY_RULE_SETUP +#line 96 "scan-gram.l" +return PERCENT_LEFT; + YY_BREAK +case 10: +YY_RULE_SETUP +#line 97 "scan-gram.l" +return PERCENT_LOCATIONS; + YY_BREAK +case 11: +YY_RULE_SETUP +#line 98 "scan-gram.l" +return PERCENT_NAME_PREFIX; + YY_BREAK +case 12: +YY_RULE_SETUP +#line 99 "scan-gram.l" +return PERCENT_NO_LINES; + YY_BREAK +case 13: +YY_RULE_SETUP +#line 100 "scan-gram.l" +return PERCENT_NONASSOC; + YY_BREAK +case 14: +YY_RULE_SETUP +#line 101 "scan-gram.l" +return PERCENT_NTERM; + YY_BREAK +case 15: +YY_RULE_SETUP +#line 102 "scan-gram.l" +return PERCENT_OUTPUT; + YY_BREAK +case 16: +YY_RULE_SETUP +#line 103 "scan-gram.l" +return PERCENT_PREC; + YY_BREAK +case 17: +YY_RULE_SETUP +#line 104 "scan-gram.l" +return PERCENT_PURE_PARSER; + YY_BREAK +case 18: +YY_RULE_SETUP +#line 105 "scan-gram.l" +return PERCENT_RIGHT; + YY_BREAK +case 19: +YY_RULE_SETUP +#line 106 "scan-gram.l" +return PERCENT_SKELETON; + YY_BREAK +case 20: +YY_RULE_SETUP +#line 107 "scan-gram.l" +return PERCENT_START; + YY_BREAK +case 21: +YY_RULE_SETUP +#line 108 "scan-gram.l" +return PERCENT_TOKEN; + YY_BREAK +case 22: +YY_RULE_SETUP +#line 109 "scan-gram.l" +return PERCENT_TOKEN; + YY_BREAK +case 23: +YY_RULE_SETUP +#line 110 "scan-gram.l" +return PERCENT_TOKEN_TABLE; + YY_BREAK +case 24: +YY_RULE_SETUP +#line 111 "scan-gram.l" +return PERCENT_TYPE; + YY_BREAK +case 25: +YY_RULE_SETUP +#line 112 "scan-gram.l" +return PERCENT_UNION; + YY_BREAK +case 26: +YY_RULE_SETUP +#line 113 "scan-gram.l" +return PERCENT_VERBOSE; + YY_BREAK +case 27: +YY_RULE_SETUP +#line 114 "scan-gram.l" +return PERCENT_YACC; + YY_BREAK +case 28: +YY_RULE_SETUP +#line 116 "scan-gram.l" +return EQUAL; + YY_BREAK +case 29: +YY_RULE_SETUP +#line 117 "scan-gram.l" +return COLON; + YY_BREAK +case 30: +YY_RULE_SETUP +#line 118 "scan-gram.l" +return PIPE; + YY_BREAK +case 31: +YY_RULE_SETUP +#line 119 "scan-gram.l" +return SEMICOLON; + YY_BREAK +case 32: +YY_RULE_SETUP +#line 121 "scan-gram.l" +YY_LINES; YY_STEP; + YY_BREAK +case 33: +YY_RULE_SETUP +#line 122 "scan-gram.l" +YY_STEP; + YY_BREAK +case 34: +YY_RULE_SETUP +#line 123 "scan-gram.l" +{ + YY_INIT; YY_GROW; YY_FINISH; + yylval->symbol = getsym (yylval->string); + return ID; + } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 129 "scan-gram.l" +yylval->integer = strtol (yytext, 0, 10); return INT; + YY_BREAK +/* Characters. We don't check there is only one. */ +case 36: +YY_RULE_SETUP +#line 132 "scan-gram.l" +YY_INIT; YY_GROW; yy_push_state (SC_ESCAPED_CHARACTER); + YY_BREAK +/* Strings. */ +case 37: +YY_RULE_SETUP +#line 135 "scan-gram.l" +YY_INIT; YY_GROW; yy_push_state (SC_ESCAPED_STRING); + YY_BREAK +/* Comments. */ +case 38: +YY_RULE_SETUP +#line 138 "scan-gram.l" +yy_push_state (SC_COMMENT); + YY_BREAK +case 39: +YY_RULE_SETUP +#line 139 "scan-gram.l" +YY_STEP; + YY_BREAK +/* Prologue. */ +case 40: +YY_RULE_SETUP +#line 142 "scan-gram.l" +YY_INIT; yy_push_state (SC_PROLOGUE); + YY_BREAK +/* Code in between braces. */ +case 41: +YY_RULE_SETUP +#line 145 "scan-gram.l" +YY_INIT; YY_GROW; ++braces_level; yy_push_state (SC_BRACED_CODE); + YY_BREAK +/* A type. */ +case 42: +YY_RULE_SETUP +#line 148 "scan-gram.l" +YY_INIT; obstack_grow (&string_obstack, yytext + 1, yyleng - 2); YY_FINISH; return TYPE; + YY_BREAK +case 43: +YY_RULE_SETUP +#line 150 "scan-gram.l" +{ + if (++percent_percent_count == 2) + yy_push_state (SC_EPILOGUE); + return PERCENT_PERCENT; + } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 156 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": invalid character: `%c'\n", *yytext); + YY_STEP; + } + YY_BREAK + +/*------------------------------------------------------------. + | Whatever the start condition (but those which correspond to | + | entity `swallowed' by Bison: SC_ESCAPED_STRING and | + | SC_ESCAPED_CHARACTER), no M4 character must escape as is. | + `------------------------------------------------------------*/ + + +case 45: +YY_RULE_SETUP +#line 172 "scan-gram.l" +obstack_sgrow (&string_obstack, "@<:@"); + YY_BREAK +case 46: +YY_RULE_SETUP +#line 173 "scan-gram.l" +obstack_sgrow (&string_obstack, "@:>@"); + YY_BREAK + +/*-----------------------------------------------------------. + | Scanning a C comment. The initial `/ *' is already eaten. | + `-----------------------------------------------------------*/ + + +case 47: +YY_RULE_SETUP +#line 184 "scan-gram.l" +{ /* End of the comment. */ + if (yy_top_state () == INITIAL) + { + YY_STEP; + } + else + { + YY_GROW; + } + yy_pop_state (); + } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 196 "scan-gram.l" +if (yy_top_state () != INITIAL) YY_GROW; + YY_BREAK +case 49: +YY_RULE_SETUP +#line 197 "scan-gram.l" +if (yy_top_state () != INITIAL) YY_GROW; YY_LINES; + YY_BREAK +case 50: +YY_RULE_SETUP +#line 198 "scan-gram.l" +/* Stray `*'. */if (yy_top_state () != INITIAL) YY_GROW; + YY_BREAK +case YY_STATE_EOF(SC_COMMENT): +#line 200 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a comment\n"); + yy_pop_state (); + } + YY_BREAK + +/*----------------------------------------------------------------. + | Scanning a C string, including its escapes. The initial `"' is | + | already eaten. | + `----------------------------------------------------------------*/ + + +case 51: +YY_RULE_SETUP +#line 215 "scan-gram.l" +{ + assert (yy_top_state () == INITIAL); + YY_GROW; + YY_FINISH; + yy_pop_state (); + return STRING; + } + YY_BREAK +case 52: +YY_RULE_SETUP +#line 223 "scan-gram.l" +YY_GROW; + YY_BREAK +case 53: +YY_RULE_SETUP +#line 225 "scan-gram.l" +obstack_1grow (&string_obstack, '\n'); YY_LINES; + YY_BREAK +case YY_STATE_EOF(SC_ESCAPED_STRING): +#line 227 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a string\n"); + assert (yy_top_state () == INITIAL); + YY_FINISH; + yy_pop_state (); + return STRING; + } + YY_BREAK + +/*---------------------------------------------------------------. + | Scanning a C character, decoding its escapes. The initial "'" | + | is already eaten. | + `---------------------------------------------------------------*/ + + +case 54: +YY_RULE_SETUP +#line 244 "scan-gram.l" +{ + YY_GROW; + assert (yy_top_state () == INITIAL); + { + char c; + YY_FINISH; + c = yylval->string[1]; + yylval->symbol = getsym (yylval->string); + symbol_class_set (yylval->symbol, token_sym); + symbol_user_token_number_set (yylval->symbol, (unsigned int) c); + yy_pop_state (); + return ID; + } + } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 259 "scan-gram.l" +YY_GROW; + YY_BREAK +case 56: +YY_RULE_SETUP +#line 261 "scan-gram.l" +obstack_1grow (&string_obstack, '\n'); YY_LINES; + YY_BREAK +case YY_STATE_EOF(SC_ESCAPED_CHARACTER): +#line 263 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a character\n"); + assert (yy_top_state () == INITIAL); + YY_FINISH; + yy_pop_state (); + return CHARACTER; + } + YY_BREAK + +/*----------------------------. + | Decode escaped characters. | + `----------------------------*/ + + +case 57: +YY_RULE_SETUP +#line 280 "scan-gram.l" +{ + long c = strtol (yytext + 1, 0, 8); + if (c > 255) + { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": invalid escape: %s\n", yytext); + YY_STEP; + } + else + obstack_1grow (&string_obstack, c); + } + YY_BREAK +case 58: +YY_RULE_SETUP +#line 292 "scan-gram.l" +{ + obstack_1grow (&string_obstack, strtol (yytext + 2, 0, 16)); + } + YY_BREAK +case 59: +YY_RULE_SETUP +#line 296 "scan-gram.l" +obstack_1grow (&string_obstack, '\a'); + YY_BREAK +case 60: +YY_RULE_SETUP +#line 297 "scan-gram.l" +obstack_1grow (&string_obstack, '\b'); + YY_BREAK +case 61: +YY_RULE_SETUP +#line 298 "scan-gram.l" +obstack_1grow (&string_obstack, '\f'); + YY_BREAK +case 62: +YY_RULE_SETUP +#line 299 "scan-gram.l" +obstack_1grow (&string_obstack, '\n'); + YY_BREAK +case 63: +YY_RULE_SETUP +#line 300 "scan-gram.l" +obstack_1grow (&string_obstack, '\r'); + YY_BREAK +case 64: +YY_RULE_SETUP +#line 301 "scan-gram.l" +obstack_1grow (&string_obstack, '\t'); + YY_BREAK +case 65: +YY_RULE_SETUP +#line 302 "scan-gram.l" +obstack_1grow (&string_obstack, '\v'); + YY_BREAK +case 66: +YY_RULE_SETUP +#line 303 "scan-gram.l" +obstack_1grow (&string_obstack, yytext[1]); + YY_BREAK +case 67: +YY_RULE_SETUP +#line 304 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unrecognized escape: %s\n", yytext); + YY_GROW; + } + YY_BREAK + +/*----------------------------------------------------------. + | Scanning a C character without decoding its escapes. The | + | initial "'" is already eaten. | + `----------------------------------------------------------*/ + + +case 68: +YY_RULE_SETUP +#line 319 "scan-gram.l" +{ + YY_GROW; + assert (yy_top_state () != INITIAL); + yy_pop_state (); + } + YY_BREAK +case 69: +YY_RULE_SETUP +#line 325 "scan-gram.l" +YY_GROW; + YY_BREAK +case 70: +YY_RULE_SETUP +#line 326 "scan-gram.l" +YY_GROW; + YY_BREAK +case 71: +YY_RULE_SETUP +#line 328 "scan-gram.l" +YY_GROW; YY_LINES; + YY_BREAK +case YY_STATE_EOF(SC_CHARACTER): +#line 330 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a character\n"); + assert (yy_top_state () != INITIAL); + yy_pop_state (); + } + YY_BREAK + +/*----------------------------------------------------------------. + | Scanning a C string, without decoding its escapes. The initial | + | `"' is already eaten. | + `----------------------------------------------------------------*/ + + +case 72: +YY_RULE_SETUP +#line 346 "scan-gram.l" +{ + assert (yy_top_state () != INITIAL); + YY_GROW; + yy_pop_state (); + } + YY_BREAK +case 73: +YY_RULE_SETUP +#line 352 "scan-gram.l" +YY_GROW; + YY_BREAK +case 74: +YY_RULE_SETUP +#line 353 "scan-gram.l" +YY_GROW; + YY_BREAK +case 75: +YY_RULE_SETUP +#line 355 "scan-gram.l" +YY_GROW; YY_LINES; + YY_BREAK +case YY_STATE_EOF(SC_STRING): +#line 357 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a string\n"); + assert (yy_top_state () != INITIAL); + yy_pop_state (); + } + YY_BREAK + +/*---------------------------------------------------. + | Strings, comments etc. can be found in user code. | + `---------------------------------------------------*/ + + +/* Characters. We don't check there is only one. */ +case 76: +YY_RULE_SETUP +#line 373 "scan-gram.l" +YY_GROW; yy_push_state (SC_CHARACTER); + YY_BREAK +/* Strings. */ +case 77: +YY_RULE_SETUP +#line 376 "scan-gram.l" +YY_GROW; yy_push_state (SC_STRING); + YY_BREAK +/* Comments. */ +case 78: +YY_RULE_SETUP +#line 379 "scan-gram.l" +YY_GROW; yy_push_state (SC_COMMENT); + YY_BREAK +case 79: +YY_RULE_SETUP +#line 380 "scan-gram.l" +YY_GROW; + YY_BREAK + +/*---------------------------------------------------------------. + | Scanning some code in braces (%union and actions). The initial | + | "{" is already eaten. | + `---------------------------------------------------------------*/ + + +case 80: +YY_RULE_SETUP +#line 391 "scan-gram.l" +{ + YY_GROW; + if (--braces_level == 0) + { + yy_pop_state (); + YY_FINISH; + return BRACED_CODE; + } + } + YY_BREAK +case 81: +YY_RULE_SETUP +#line 401 "scan-gram.l" +YY_GROW; braces_level++; + YY_BREAK +case 82: +YY_RULE_SETUP +#line 403 "scan-gram.l" +{ handle_dollar (yytext); } + YY_BREAK +case 83: +YY_RULE_SETUP +#line 404 "scan-gram.l" +{ handle_at (yytext); } + YY_BREAK +case 84: +YY_RULE_SETUP +#line 406 "scan-gram.l" +YY_GROW; + YY_BREAK +case 85: +YY_RULE_SETUP +#line 407 "scan-gram.l" +YY_GROW; YY_LINES; + YY_BREAK +/* A lose $, or /, or etc. */ +case 86: +YY_RULE_SETUP +#line 410 "scan-gram.l" +YY_GROW; + YY_BREAK +case YY_STATE_EOF(SC_BRACED_CODE): +#line 412 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a braced code\n"); + yy_pop_state (); + YY_FINISH; + return PROLOGUE; + } + YY_BREAK + +/*--------------------------------------------------------------. + | Scanning some prologue: from "%{" (already scanned) to "%}". | + `--------------------------------------------------------------*/ + + +case 87: +YY_RULE_SETUP +#line 429 "scan-gram.l" +{ + yy_pop_state (); + YY_FINISH; + return PROLOGUE; + } + YY_BREAK +case 88: +YY_RULE_SETUP +#line 435 "scan-gram.l" +YY_GROW; + YY_BREAK +case 89: +YY_RULE_SETUP +#line 436 "scan-gram.l" +YY_GROW; + YY_BREAK +case 90: +YY_RULE_SETUP +#line 437 "scan-gram.l" +YY_GROW; YY_LINES; + YY_BREAK +case YY_STATE_EOF(SC_PROLOGUE): +#line 439 "scan-gram.l" +{ + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a prologue\n"); + yy_pop_state (); + YY_FINISH; + return PROLOGUE; + } + YY_BREAK + +/*---------------------------------------------------------------. + | Scanning the epilogue (everything after the second "%%", which | + | has already been eaten. | + `---------------------------------------------------------------*/ + + +case 91: +YY_RULE_SETUP +#line 457 "scan-gram.l" +YY_GROW; + YY_BREAK +case YY_STATE_EOF(SC_EPILOGUE): +#line 459 "scan-gram.l" +{ + yy_pop_state (); + YY_FINISH; + return EPILOGUE; + } + YY_BREAK + +case 92: +YY_RULE_SETUP +#line 467 "scan-gram.l" +YY_FATAL_ERROR( "flex scanner jammed" ); + YY_BREAK +#line 1749 "scan-gram.c" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between yy_current_buffer and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yy_n_chars = yy_current_buffer->yy_n_chars; + yy_current_buffer->yy_input_file = yyin; + yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_c_buf_p; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = + yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of yylex */ + + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + { + register char *dest = yy_current_buffer->yy_ch_buf; + register char *source = yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( yy_current_buffer->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_current_buffer->yy_n_chars = yy_n_chars = 0; + + else + { + int num_to_read = + yy_current_buffer->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ +#ifdef YY_USES_REJECT + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); +#else + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = yy_current_buffer; + + int yy_c_buf_p_offset = + (int) (yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yy_flex_realloc( (void *) b->yy_ch_buf, + b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = yy_current_buffer->yy_buf_size - + number_to_move - 1; +#endif + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; + + return ret_val; + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +static yy_state_type yy_get_previous_state() + { + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = yy_start; + + for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 355 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +yy_state_type yy_current_state; +#endif + { + register int yy_is_jam; + register char *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 355 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 354); + + return yy_is_jam ? 0 : yy_current_state; + } + + +#ifndef YY_NO_UNPUT +#ifdef YY_USE_PROTOS +static void yyunput( int c, register char *yy_bp ) +#else +static void yyunput( c, yy_bp ) +int c; +register char *yy_bp; +#endif + { + register char *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = yy_n_chars + 2; + register char *dest = &yy_current_buffer->yy_ch_buf[ + yy_current_buffer->yy_buf_size + 2]; + register char *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + yy_current_buffer->yy_n_chars = + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + + yytext_ptr = yy_bp; + yy_hold_char = *yy_cp; + yy_c_buf_p = yy_cp; + } +#endif /* ifndef YY_NO_UNPUT */ + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + { + int c; + + *yy_c_buf_p = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* This was really a NUL. */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yy_c_buf_p - yytext_ptr; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /* fall through */ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + return EOF; + + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ + *yy_c_buf_p = '\0'; /* preserve yytext */ + yy_hold_char = *++yy_c_buf_p; + + + return c; + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + { + if ( ! yy_current_buffer ) + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* Flush out information for old buffer. */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + { + if ( ! b ) + return; + + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yy_flex_free( (void *) b->yy_ch_buf ); + + yy_flex_free( (void *) b ); + } + + +#ifndef YY_ALWAYS_INTERACTIVE +#ifndef YY_NEVER_INTERACTIVE +extern int isatty YY_PROTO(( int )); +#endif +#endif + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + + { + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + +#if YY_ALWAYS_INTERACTIVE + b->yy_is_interactive = 1; +#else +#if YY_NEVER_INTERACTIVE + b->yy_is_interactive = 0; +#else + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; +#endif +#endif + } + + +#ifdef YY_USE_PROTOS +void yy_flush_buffer( YY_BUFFER_STATE b ) +#else +void yy_flush_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == yy_current_buffer ) + yy_load_buffer_state(); + } + + +#ifndef YY_NO_SCAN_BUFFER +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) +#else +YY_BUFFER_STATE yy_scan_buffer( base, size ) +char *base; +yy_size_t size; +#endif + { + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; + } +#endif + + +#ifndef YY_NO_SCAN_STRING +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) +#else +YY_BUFFER_STATE yy_scan_string( yy_str ) +yyconst char *yy_str; +#endif + { + int len; + for ( len = 0; yy_str[len]; ++len ) + ; + + return yy_scan_bytes( yy_str, len ); + } +#endif + + +#ifndef YY_NO_SCAN_BYTES +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) +#else +YY_BUFFER_STATE yy_scan_bytes( bytes, len ) +yyconst char *bytes; +int len; +#endif + { + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = len + 2; + buf = (char *) yy_flex_alloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < len; ++i ) + buf[i] = bytes[i]; + + buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; + } +#endif + + +#ifndef YY_NO_PUSH_STATE +#ifdef YY_USE_PROTOS +static void yy_push_state( int new_state ) +#else +static void yy_push_state( new_state ) +int new_state; +#endif + { + if ( yy_start_stack_ptr >= yy_start_stack_depth ) + { + yy_size_t new_size; + + yy_start_stack_depth += YY_START_STACK_INCR; + new_size = yy_start_stack_depth * sizeof( int ); + + if ( ! yy_start_stack ) + yy_start_stack = (int *) yy_flex_alloc( new_size ); + + else + yy_start_stack = (int *) yy_flex_realloc( + (void *) yy_start_stack, new_size ); + + if ( ! yy_start_stack ) + YY_FATAL_ERROR( + "out of memory expanding start-condition stack" ); + } + + yy_start_stack[yy_start_stack_ptr++] = YY_START; + + BEGIN(new_state); + } +#endif + + +#ifndef YY_NO_POP_STATE +static void yy_pop_state() + { + if ( --yy_start_stack_ptr < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN(yy_start_stack[yy_start_stack_ptr]); + } +#endif + + +#ifndef YY_NO_TOP_STATE +static int yy_top_state() + { + return yy_start_stack[yy_start_stack_ptr - 1]; + } +#endif + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +#ifdef YY_USE_PROTOS +static void yy_fatal_error( yyconst char msg[] ) +#else +static void yy_fatal_error( msg ) +char msg[]; +#endif + { + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); + } + + + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + yytext[yyleng] = yy_hold_char; \ + yy_c_buf_p = yytext + n; \ + yy_hold_char = *yy_c_buf_p; \ + *yy_c_buf_p = '\0'; \ + yyleng = n; \ + } \ + while ( 0 ) + + +/* Internal utility routines. */ + +#ifndef yytext_ptr +#ifdef YY_USE_PROTOS +static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) +#else +static void yy_flex_strncpy( s1, s2, n ) +char *s1; +yyconst char *s2; +int n; +#endif + { + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; + } +#endif + +#ifdef YY_NEED_STRLEN +#ifdef YY_USE_PROTOS +static int yy_flex_strlen( yyconst char *s ) +#else +static int yy_flex_strlen( s ) +yyconst char *s; +#endif + { + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; + } +#endif + + +#ifdef YY_USE_PROTOS +static void *yy_flex_alloc( yy_size_t size ) +#else +static void *yy_flex_alloc( size ) +yy_size_t size; +#endif + { + return (void *) malloc( size ); + } + +#ifdef YY_USE_PROTOS +static void *yy_flex_realloc( void *ptr, yy_size_t size ) +#else +static void *yy_flex_realloc( ptr, size ) +void *ptr; +yy_size_t size; +#endif + { + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); + } + +#ifdef YY_USE_PROTOS +static void yy_flex_free( void *ptr ) +#else +static void yy_flex_free( ptr ) +void *ptr; +#endif + { + free( ptr ); + } + +#if YY_MAIN +int main() + { + yylex(); + return 0; + } +#endif +#line 467 "scan-gram.l" + + +/*------------------------------------------------------------------. +| CP is pointing to a wannabee semantic value (i.e., a `$'). | +| | +| Possible inputs: $[]($|integer) | +| | +| Output to the STRING_OBSTACK a reference to this semantic value. | +`------------------------------------------------------------------*/ + +static void +handle_dollar (char *cp) +{ + const char *type_name = NULL; + + /* RULE_LENGTH is the number of values in the current rule so far, + which says where to find `$0' with respect to the top of the + stack. It is not the same as the rule->length in the case of mid + rule actions. */ + int rule_length = 0; + symbol_list *rhs; + for (rhs = current_rule->next; rhs; rhs = rhs->next) + ++rule_length; + + ++cp; + + /* Get the type name if explicit. */ + if (*cp == '<') + { + type_name = ++cp; + while (*cp != '>') + ++cp; + *cp = '\0'; + ++cp; + } + + if (*cp == '$') + { + if (!type_name) + type_name = get_type_name (0, current_rule); + if (!type_name && typed) + complain (_("$$ of `%s' has no declared type"), + current_rule->sym->tag); + if (!type_name) + type_name = ""; + obstack_fgrow1 (&string_obstack, + "]b4_lhs_value([%s])[", type_name); + } + else if (isdigit (*cp) || *cp == '-') + { + int n = strtol (cp, &cp, 10); + + if (n > rule_length) + complain (_("invalid value: %s%d"), "$", n); + else + { + if (!type_name && n > 0) + type_name = get_type_name (n, current_rule); + if (!type_name && typed) + complain (_("$%d of `%s' has no declared type"), + n, current_rule->sym->tag); + if (!type_name) + type_name = ""; + obstack_fgrow3 (&string_obstack, + "]b4_rhs_value([%d], [%d], [%s])[", + rule_length, n, type_name); + } + } + else + { + char buf[] = "$c"; + buf[1] = *cp; + complain (_("%s is invalid"), quote (buf)); + } +} + +/*-------------------------------------------------------. +| CP is pointing to a location (i.e., a `@'). Output to | +| STRING_OBSTACK a reference to this location. | +`-------------------------------------------------------*/ + +static void +handle_at (char *cp) +{ + /* RULE_LENGTH is the number of values in the current rule so far, + which says where to find `$0' with respect to the top of the + stack. It is not the same as the rule->length in the case of mid + rule actions. */ + int rule_length = 0; + symbol_list *rhs; + for (rhs = current_rule->next; rhs; rhs = rhs->next) + ++rule_length; + + locations_flag = 1; + ++cp; + + if (*cp == '$') + { + obstack_sgrow (&string_obstack, "]b4_lhs_location["); + } + else if (isdigit (*cp) || *cp == '-') + { + int n = strtol (cp, &cp, 10); + if (n > rule_length) + complain (_("invalid value: %s%d"), "@", n); + else + obstack_fgrow2 (&string_obstack, "]b4_rhs_location([%d], [%d])[", + rule_length, n); + } + else + { + char buf[] = "@c"; + buf[1] = *cp; + complain (_("%s is invalid"), quote (buf)); + } +} diff --git a/src/scan-gram.l b/src/scan-gram.l new file mode 100644 index 00000000..e6abed5f --- /dev/null +++ b/src/scan-gram.l @@ -0,0 +1,582 @@ +/* Bison Grammar Scanner -*- C -*- + Copyright (C) 2002 Free Software Foundation, Inc. + + This file is part of Bison, the GNU Compiler Compiler. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +%option debug nodefault noyywrap nounput never-interactive stack +%option prefix="gram_" outfile="lex.yy.c" + +%{ +#include "system.h" +#include "complain.h" +#include "quote.h" +#include "getargs.h" +#include "gram.h" +#include "reader.h" + +/* Each time we match a string, move the end cursor to its end. */ +#define YY_USER_ACTION LOCATION_COLUMNS (*yylloc, yyleng) +#define YY_LINES LOCATION_LINES (*yylloc, yyleng); lineno += yyleng; +#define YY_STEP LOCATION_STEP (*yylloc) + +/* Appending to the STRING_OBSTACK. */ +#define YY_INIT obstack_init (&string_obstack) +#define YY_GROW obstack_grow (&string_obstack, yytext, yyleng) +#define YY_FINISH obstack_1grow (&string_obstack, '\0'); yylval->string = obstack_finish (&string_obstack); + +/* This is only to avoid GCC warnings. */ +#define YY_USER_INIT if (yycontrol) {;}; + +static struct obstack string_obstack; +static int braces_level = 0; +static int percent_percent_count = 0; + +static void handle_dollar PARAMS ((char *cp)); +static void handle_at PARAMS ((char *cp)); + +%} +%x SC_COMMENT +%x SC_STRING SC_CHARACTER +%x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER +%x SC_BRACED_CODE SC_PROLOGUE SC_EPILOGUE + +id [.a-zA-Z][.a-zA-Z_0-9]* +int [0-9]+ +eols (\n|\r|\n\r|\r\n)+ +blanks [ \t\f]+ + +%% +%{ + /* At each yylex invocation, mark the current position as the + start of the next token. */ +#define TR_POS 0 +#if TR_POS + fprintf (stderr, "FOO1: "); + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, "\n"); +#endif + YY_STEP; +#if TR_POS + fprintf (stderr, "BAR1: "); + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, "\n"); +#endif +%} + + + /*----------------------------. + | Scanning Bison directives. | + `----------------------------*/ + +{ + "%binary" return PERCENT_NONASSOC; + "%debug" return PERCENT_DEBUG; + "%define" return PERCENT_DEFINE; + "%defines" return PERCENT_DEFINES; + "%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE; + "%expect" return PERCENT_EXPECT; + "%file-prefix" return PERCENT_FILE_PREFIX; + "%fixed"[-_]"output"[-_]"files" return PERCENT_YACC; + "%left" return PERCENT_LEFT; + "%locations" return PERCENT_LOCATIONS; + "%name"[-_]"prefix" return PERCENT_NAME_PREFIX; + "%no"[-_]"lines" return PERCENT_NO_LINES; + "%nonassoc" return PERCENT_NONASSOC; + "%nterm" return PERCENT_NTERM; + "%output" return PERCENT_OUTPUT; + "%prec" return PERCENT_PREC; + "%pure"[-_]"parser" return PERCENT_PURE_PARSER; + "%right" return PERCENT_RIGHT; + "%skeleton" return PERCENT_SKELETON; + "%start" return PERCENT_START; + "%term" return PERCENT_TOKEN; + "%token" return PERCENT_TOKEN; + "%token"[-_]"table" return PERCENT_TOKEN_TABLE; + "%type" return PERCENT_TYPE; + "%union" return PERCENT_UNION; + "%verbose" return PERCENT_VERBOSE; + "%yacc" return PERCENT_YACC; + + "=" return EQUAL; + ":" return COLON; + "|" return PIPE; + ";" return SEMICOLON; + + {eols} YY_LINES; YY_STEP; + {blanks} YY_STEP; + {id} { + YY_INIT; YY_GROW; YY_FINISH; + yylval->symbol = getsym (yylval->string); + return ID; + } + + {int} yylval->integer = strtol (yytext, 0, 10); return INT; + + /* Characters. We don't check there is only one. */ + \' YY_INIT; YY_GROW; yy_push_state (SC_ESCAPED_CHARACTER); + + /* Strings. */ + \" YY_INIT; YY_GROW; yy_push_state (SC_ESCAPED_STRING); + + /* Comments. */ + "/*" yy_push_state (SC_COMMENT); + "//".* YY_STEP; + + /* Prologue. */ + "%{" YY_INIT; yy_push_state (SC_PROLOGUE); + + /* Code in between braces. */ + "{" YY_INIT; YY_GROW; ++braces_level; yy_push_state (SC_BRACED_CODE); + + /* A type. */ + "<"[^>]+">" YY_INIT; obstack_grow (&string_obstack, yytext + 1, yyleng - 2); YY_FINISH; return TYPE; + + "%%" { + if (++percent_percent_count == 2) + yy_push_state (SC_EPILOGUE); + return PERCENT_PERCENT; + } + + . { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": invalid character: `%c'\n", *yytext); + YY_STEP; + } +} + + + /*------------------------------------------------------------. + | Whatever the start condition (but those which correspond to | + | entity `swallowed' by Bison: SC_ESCAPED_STRING and | + | SC_ESCAPED_CHARACTER), no M4 character must escape as is. | + `------------------------------------------------------------*/ + + +{ + \[ obstack_sgrow (&string_obstack, "@<:@"); + \] obstack_sgrow (&string_obstack, "@:>@"); +} + + + + /*-----------------------------------------------------------. + | Scanning a C comment. The initial `/ *' is already eaten. | + `-----------------------------------------------------------*/ + + +{ + "*/" { /* End of the comment. */ + if (yy_top_state () == INITIAL) + { + YY_STEP; + } + else + { + YY_GROW; + } + yy_pop_state (); + } + + [^\[\]*\n\r]+ if (yy_top_state () != INITIAL) YY_GROW; + {eols} if (yy_top_state () != INITIAL) YY_GROW; YY_LINES; + . /* Stray `*'. */if (yy_top_state () != INITIAL) YY_GROW; + + <> { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a comment\n"); + yy_pop_state (); + } +} + + + /*----------------------------------------------------------------. + | Scanning a C string, including its escapes. The initial `"' is | + | already eaten. | + `----------------------------------------------------------------*/ + + +{ + \" { + assert (yy_top_state () == INITIAL); + YY_GROW; + YY_FINISH; + yy_pop_state (); + return STRING; + } + + [^\"\n\r\\]+ YY_GROW; + + {eols} obstack_1grow (&string_obstack, '\n'); YY_LINES; + + <> { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a string\n"); + assert (yy_top_state () == INITIAL); + YY_FINISH; + yy_pop_state (); + return STRING; + } +} + + /*---------------------------------------------------------------. + | Scanning a C character, decoding its escapes. The initial "'" | + | is already eaten. | + `---------------------------------------------------------------*/ + + +{ + \' { + YY_GROW; + assert (yy_top_state () == INITIAL); + { + char c; + YY_FINISH; + c = yylval->string[1]; + yylval->symbol = getsym (yylval->string); + symbol_class_set (yylval->symbol, token_sym); + symbol_user_token_number_set (yylval->symbol, (unsigned int) c); + yy_pop_state (); + return ID; + } + } + + [^\'\n\r\\] YY_GROW; + + {eols} obstack_1grow (&string_obstack, '\n'); YY_LINES; + + <> { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a character\n"); + assert (yy_top_state () == INITIAL); + YY_FINISH; + yy_pop_state (); + return CHARACTER; + } +} + + + /*----------------------------. + | Decode escaped characters. | + `----------------------------*/ + + +{ + \\[0-7]{3} { + long c = strtol (yytext + 1, 0, 8); + if (c > 255) + { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": invalid escape: %s\n", yytext); + YY_STEP; + } + else + obstack_1grow (&string_obstack, c); + } + + \\x[0-9a-fA-F]{2} { + obstack_1grow (&string_obstack, strtol (yytext + 2, 0, 16)); + } + + \\a obstack_1grow (&string_obstack, '\a'); + \\b obstack_1grow (&string_obstack, '\b'); + \\f obstack_1grow (&string_obstack, '\f'); + \\n obstack_1grow (&string_obstack, '\n'); + \\r obstack_1grow (&string_obstack, '\r'); + \\t obstack_1grow (&string_obstack, '\t'); + \\v obstack_1grow (&string_obstack, '\v'); + \\[\\""] obstack_1grow (&string_obstack, yytext[1]); + \\. { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unrecognized escape: %s\n", yytext); + YY_GROW; + } +} + + + /*----------------------------------------------------------. + | Scanning a C character without decoding its escapes. The | + | initial "'" is already eaten. | + `----------------------------------------------------------*/ + + +{ + \' { + YY_GROW; + assert (yy_top_state () != INITIAL); + yy_pop_state (); + } + + [^\[\]\'\n\r\\] YY_GROW; + \\. YY_GROW; + + {eols} YY_GROW; YY_LINES; + + <> { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a character\n"); + assert (yy_top_state () != INITIAL); + yy_pop_state (); + } +} + + + /*----------------------------------------------------------------. + | Scanning a C string, without decoding its escapes. The initial | + | `"' is already eaten. | + `----------------------------------------------------------------*/ + + +{ + \" { + assert (yy_top_state () != INITIAL); + YY_GROW; + yy_pop_state (); + } + + [^\[\]\"\n\r\\]+ YY_GROW; + \\. YY_GROW; + + {eols} YY_GROW; YY_LINES; + + <> { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a string\n"); + assert (yy_top_state () != INITIAL); + yy_pop_state (); + } +} + + + /*---------------------------------------------------. + | Strings, comments etc. can be found in user code. | + `---------------------------------------------------*/ + + +{ + /* Characters. We don't check there is only one. */ + \' YY_GROW; yy_push_state (SC_CHARACTER); + + /* Strings. */ + \" YY_GROW; yy_push_state (SC_STRING); + + /* Comments. */ + "/*" YY_GROW; yy_push_state (SC_COMMENT); + "//".* YY_GROW; +} + + + /*---------------------------------------------------------------. + | Scanning some code in braces (%union and actions). The initial | + | "{" is already eaten. | + `---------------------------------------------------------------*/ + + +{ + "}" { + YY_GROW; + if (--braces_level == 0) + { + yy_pop_state (); + YY_FINISH; + return BRACED_CODE; + } + } + + "{" YY_GROW; braces_level++; + + "$"("<".*">")?(-?[0-9]+|"$") { handle_dollar (yytext); } + "@"(-?[0-9]+|"$") { handle_at (yytext); } + + [^\[\]$/\'\"@\{\}\n\r]+ YY_GROW; + {eols} YY_GROW; YY_LINES; + + /* A lose $, or /, or etc. */ + . YY_GROW; + + <> { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a braced code\n"); + yy_pop_state (); + YY_FINISH; + return PROLOGUE; + } + +} + + + /*--------------------------------------------------------------. + | Scanning some prologue: from "%{" (already scanned) to "%}". | + `--------------------------------------------------------------*/ + + +{ + "%}" { + yy_pop_state (); + YY_FINISH; + return PROLOGUE; + } + + [^\[\]%\n\r]+ YY_GROW; + "%"+[^%\}\n\r]+ YY_GROW; + {eols} YY_GROW; YY_LINES; + + <> { + LOCATION_PRINT (stderr, *yylloc); + fprintf (stderr, ": unexpected end of file in a prologue\n"); + yy_pop_state (); + YY_FINISH; + return PROLOGUE; + } + +} + + + /*---------------------------------------------------------------. + | Scanning the epilogue (everything after the second "%%", which | + | has already been eaten. | + `---------------------------------------------------------------*/ + + +{ + ([^\[\]]|{eols})+ YY_GROW; + + <> { + yy_pop_state (); + YY_FINISH; + return EPILOGUE; + } +} + + +%% + +/*------------------------------------------------------------------. +| CP is pointing to a wannabee semantic value (i.e., a `$'). | +| | +| Possible inputs: $[]($|integer) | +| | +| Output to the STRING_OBSTACK a reference to this semantic value. | +`------------------------------------------------------------------*/ + +static void +handle_dollar (char *cp) +{ + const char *type_name = NULL; + + /* RULE_LENGTH is the number of values in the current rule so far, + which says where to find `$0' with respect to the top of the + stack. It is not the same as the rule->length in the case of mid + rule actions. */ + int rule_length = 0; + symbol_list *rhs; + for (rhs = current_rule->next; rhs; rhs = rhs->next) + ++rule_length; + + ++cp; + + /* Get the type name if explicit. */ + if (*cp == '<') + { + type_name = ++cp; + while (*cp != '>') + ++cp; + *cp = '\0'; + ++cp; + } + + if (*cp == '$') + { + if (!type_name) + type_name = get_type_name (0, current_rule); + if (!type_name && typed) + complain (_("$$ of `%s' has no declared type"), + current_rule->sym->tag); + if (!type_name) + type_name = ""; + obstack_fgrow1 (&string_obstack, + "]b4_lhs_value([%s])[", type_name); + } + else if (isdigit (*cp) || *cp == '-') + { + int n = strtol (cp, &cp, 10); + + if (n > rule_length) + complain (_("invalid value: %s%d"), "$", n); + else + { + if (!type_name && n > 0) + type_name = get_type_name (n, current_rule); + if (!type_name && typed) + complain (_("$%d of `%s' has no declared type"), + n, current_rule->sym->tag); + if (!type_name) + type_name = ""; + obstack_fgrow3 (&string_obstack, + "]b4_rhs_value([%d], [%d], [%s])[", + rule_length, n, type_name); + } + } + else + { + char buf[] = "$c"; + buf[1] = *cp; + complain (_("%s is invalid"), quote (buf)); + } +} + +/*-------------------------------------------------------. +| CP is pointing to a location (i.e., a `@'). Output to | +| STRING_OBSTACK a reference to this location. | +`-------------------------------------------------------*/ + +static void +handle_at (char *cp) +{ + /* RULE_LENGTH is the number of values in the current rule so far, + which says where to find `$0' with respect to the top of the + stack. It is not the same as the rule->length in the case of mid + rule actions. */ + int rule_length = 0; + symbol_list *rhs; + for (rhs = current_rule->next; rhs; rhs = rhs->next) + ++rule_length; + + locations_flag = 1; + ++cp; + + if (*cp == '$') + { + obstack_sgrow (&string_obstack, "]b4_lhs_location["); + } + else if (isdigit (*cp) || *cp == '-') + { + int n = strtol (cp, &cp, 10); + if (n > rule_length) + complain (_("invalid value: %s%d"), "@", n); + else + obstack_fgrow2 (&string_obstack, "]b4_rhs_location([%d], [%d])[", + rule_length, n); + } + else + { + char buf[] = "@c"; + buf[1] = *cp; + complain (_("%s is invalid"), quote (buf)); + } +} diff --git a/src/symtab.c b/src/symtab.c index 1c45965e..3c588a73 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -54,36 +54,46 @@ symbol_new (const char *tag) res->class = unknown_sym; nsyms++; - return res; } -/*-----------------------------------------. -| Set the TYPE_NAME associated to SYMBOL. | -`-----------------------------------------*/ +/*------------------------------------------------------------------. +| Set the TYPE_NAME associated to SYMBOL. Does nothing if passed 0 | +| as TYPE_NAME. | +`------------------------------------------------------------------*/ void symbol_type_set (symbol_t *symbol, char *type_name) { - if (symbol->type_name) - complain (_("type redeclaration for %s"), symbol->tag); - symbol->type_name = type_name; + if (type_name) + { + if (symbol->type_name) + complain (_("type redeclaration for %s"), symbol->tag); + symbol->type_name = type_name; + } } -/*------------------------------------------. -| Set the PRECEDENCE associated to SYMBOL. | -`------------------------------------------*/ +/*------------------------------------------------------------------. +| Set the PRECEDENCE associated to SYMBOL. Does nothing if invoked | +| with UNDEF_ASSOC as ASSOC. | +`------------------------------------------------------------------*/ void symbol_precedence_set (symbol_t *symbol, int prec, associativity assoc) { - if (symbol->prec != 0) - complain (_("redefining precedence of %s"), symbol->tag); - symbol->prec = prec; - symbol->assoc = assoc; + if (assoc != undef_assoc) + { + if (symbol->prec != 0) + complain (_("redefining precedence of %s"), symbol->tag); + symbol->prec = prec; + symbol->assoc = assoc; + } + + /* Only terminals have a precedence. */ + symbol_class_set (symbol, token_sym); } @@ -176,7 +186,7 @@ symbol_check_defined (symbol_t *this) `-------------------------------------------------------------------*/ void -symbol_make_alias (symbol_t *symbol, symbol_t *symval, char *typename) +symbol_make_alias (symbol_t *symbol, symbol_t *symval) { if (symval->alias) warn (_("symbol `%s' used more than once as a literal string"), @@ -187,7 +197,6 @@ symbol_make_alias (symbol_t *symbol, symbol_t *symval, char *typename) else { symval->class = token_sym; - symval->type_name = typename; symval->user_token_number = symbol->user_token_number; symbol->user_token_number = USER_NUMBER_ALIAS; symval->alias = symbol; @@ -226,8 +235,12 @@ symbol_check_alias_consistence (symbol_t *this) if (this->assoc != this->alias->assoc) { - if (this->assoc != 0 && this->alias->assoc != 0) - complain (_("conflicting assoc values for %s and %s"), + /* FIXME: For some reason (probably the S/R => keep the S), + the right assoc is chosen has the ``not set''. This is + not nice, fix this! */ + if (this->assoc != right_assoc + && this->alias->assoc != right_assoc) + complain (_("conflicting associativities for %s and %s"), this->tag, this->alias->tag); if (this->assoc != 0) this->alias->assoc = this->assoc; diff --git a/src/symtab.h b/src/symtab.h index eb45f1de..3f167d9f 100644 --- a/src/symtab.h +++ b/src/symtab.h @@ -29,6 +29,7 @@ /* Associativity values for tokens and rules. */ typedef enum { + undef_assoc, right_assoc, left_assoc, non_assoc @@ -84,15 +85,15 @@ struct symbol_s /* Fetch (or create) the symbol associated to KEY. */ symbol_t *getsym PARAMS ((const char *key)); -/* Declare the new SYMBOL. Make it an alias of SYMVAL, and type */ -/* them with TYPENAME. */ -void symbol_make_alias PARAMS ((symbol_t *symbol, symbol_t *symval, - char *typename)); +/* Declare the new SYMBOL. Make it an alias of SYMVAL. */ +void symbol_make_alias PARAMS ((symbol_t *symbol, symbol_t *symval)); -/* Set the TYPE_NAME associated to SYMBOL. */ +/* Set the TYPE_NAME associated to SYMBOL. Does nothing if passed 0 as + TYPE_NAME. */ void symbol_type_set PARAMS ((symbol_t *symbol, char *type_name)); -/* Set the PRECEDENCE associated to SYMBOL. */ +/* Set the PRECEDENCE associated to SYMBOL. Ensures that SYMBOL is a + terminal. Does nothing if invoked with UNDEF_ASSOC as ASSOC. */ void symbol_precedence_set PARAMS ((symbol_t *symbol, int prec, associativity assoc)); @@ -131,8 +132,8 @@ void symbols_do PARAMS ((symbol_processor processor, void *processor_data)); /* Free all the memory allocated for symbols. */ void symbols_free PARAMS ((void)); -/* Check that all the symbols are defined. Report any undefined */ -/* symbols and consider them nonterminals. */ +/* Check that all the symbols are defined. Report any undefined + symbols and consider them nonterminals. */ void symbols_check_defined PARAMS ((void)); /* Perform various sanity checks, assign symbol numbers, and set up diff --git a/src/system.h b/src/system.h index 8cd8bba1..bdf6becb 100644 --- a/src/system.h +++ b/src/system.h @@ -144,14 +144,22 @@ void *memrchr PARAMS ((const void *s, int c, size_t n)); (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ # define __attribute__(Spec) /* empty */ # endif +#endif + /* The __-protected variants of `format' and `printf' attributes are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif +#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __format__ format +# define __printf__ printf #endif +#ifndef ATTRIBUTE_NORETURN +# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) +#endif + +#ifndef ATTRIBUTE_UNUSED +# define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +#endif /*------. | NLS. | diff --git a/tests/calc.at b/tests/calc.at index 4ea26354..28e16f95 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -89,7 +89,7 @@ char quote[] = "@:>@@:>@,"; %type exp /* Exercise quotes in strings. */ -%token "fake @>:@@>:@," +%token FAKE "fake @>:@@>:@," %nonassoc '=' /* comparison */ %left '-' '+' diff --git a/tests/reduce.at b/tests/reduce.at index b3a79ba2..24911943 100644 --- a/tests/reduce.at +++ b/tests/reduce.at @@ -204,6 +204,7 @@ not_reachable: useful { /* A not reachable action. */ } non_productive: non_productive useless_token { /* Another non productive action. */ } ; +%% ]]) AT_CHECK([[bison not-reduced.y]], 0, [], @@ -244,6 +245,7 @@ exp: useful { /* A useful action. */ } //non_productive: non_productive useless_token // { /* Another non productive action. */ } // ; +%% ]]) AT_CHECK([[bison reduced.y]]) diff --git a/tests/regression.at b/tests/regression.at index 1adce973..4edd0186 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -287,40 +287,23 @@ AT_DATA([input.y], [[%% ? default: 'a' } -%{ %& %a %- +%{ ]]) AT_CHECK([bison input.y], [1], [], -[[input.y:2: invalid input: `?' -input.y:3: invalid input: `}' -input.y:4: invalid input: `%{' -input.y:5: invalid input: `%&' -input.y:6: invalid input: `%a' -input.y:7: invalid input: `%-' -]]) - -AT_CLEANUP - - - -## -------------------- ## -## Invalid %directive. ## -## -------------------- ## - - -AT_SETUP([Invalid %directive]) - -AT_DATA([input.y], -[[%invalid -]]) - -AT_CHECK([bison input.y], [1], [], -[[input.y:1: unrecognized: %invalid -input.y:1: Skipping to next % -input.y:2: fatal error: no input grammar +[[input.y:2.1: invalid character: `?' +input.y:3.14: invalid character: `}' +input.y:4.1: invalid character: `%' +input.y:4.2: invalid character: `&' +input.y:5.1: invalid character: `%' +input.y:6.1: invalid character: `%' +input.y:6.2: invalid character: `-' +input.y:7.1-8.0: unexpected end of file in a prologue +input.y:7.1-8.0: parse error, unexpected PROLOGUE, expecting ";" or "|" +input.y:8: symbol a is used, but is not defined as a token and has no rules ]]) AT_CLEANUP @@ -340,13 +323,11 @@ AT_DATA([input.y], void yyerror (const char *s); int yylex (void); %} -[%token "end of file" +[%token YYEOF 0 "end of file" %token 'a' "a" -%token "b" 'b' -%token "c" c -%token d "d" -%token e 'e' -%token 'f' e +%token b "b" +%token c 'c' +%token 'd' d %% exp: "a"; ]]) diff --git a/tests/synclines.at b/tests/synclines.at index a1243511..ea6f9688 100644 --- a/tests/synclines.at +++ b/tests/synclines.at @@ -33,7 +33,7 @@ AT_DATA([[input.y]], [$2]) AT_CHECK([bison input.y -o input.c]) -AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 1, [], [stderr]) +AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c], 1, [], [stderr]) # In case GCC displays column information, strip it down. # # input.y:4:2: #error "4" or input.y:4.2: #error "4" diff --git a/tests/torture.at b/tests/torture.at index 2e0cfc92..f536e4b4 100644 --- a/tests/torture.at +++ b/tests/torture.at @@ -57,7 +57,7 @@ EOF for my $size (1 .. $max) { - print "%token \"$size\" ", $size, "\n"; + print "%token t$size $size \"$size\"\n"; }; print < ", " ", - map { "token$_" } (1 .. $max)), + map { "n$_" } (1 .. $max)), "\n"; for my $count (1 .. $max) { - print "%token \"$count\" $count\n"; + print "%token t$count $count \"$count\"\n"; }; print <