2000-10-02 Akim Demaille <akim@epita.fr>
+ The location tracking mechanism is precious for parse error
+ messages. Nevertheless, it is enabled only when `@n' is used in
+ the grammar, which is a different issue (you can use it in error
+ message, but not in the grammar per se). Therefore, there should
+ be another means to enable it.
+
+ * src/getargs.c (getargs): Support `--locations'.
+ (usage): Report it.
+ * src/getargs.h (locationsflag): Export it.
+ * src/lex.c (percent_table): Support `%locations'.
+ * src/reader.c (yylsp_needed): Remove this variable, now replaced
+ with `locationsflag'.
+ * doc/bison.texinfo: Document `--locations' and `%locations'.
+ Sort the options.
+ * tests/calc.m4: Test it.
+
+ For regularity of the names, replace each
+ (nolineflag, toknumflag, rawtokenumflag, noparserflag): with...
+ (no_lineflag, token_tableflag, rawflag, no_parserflag): this.
+ In addition replace each `flag' with `_flag'.
+
+
+2000-10-02 Akim Demaille <akim@epita.fr>
+
Also test parse error messages, including with YYERROR_VERBOSE.
* tests/calc.m4 (calc.y): Add support for `exp = exp' (non
(@pxref{Type Decl, ,Nonterminal Symbols}).
@item %start
-Specify the grammar's start symbol (@pxref{Start Decl, ,The Start-Symbol}).
+Specify the grammar's start symbol (@pxref{Start Decl, ,The
+Start-Symbol}).
@item %expect
Declare the expected number of shift-reduce conflicts
(@pxref{Expect Decl, ,Suppressing Conflict Warnings}).
+@item %locations
+Generate the code processing the locations (@pxref{Action Features,
+,Special Features for Use in Actions}). This mode is enabled as soon as
+the grammar uses the special @samp{@@@var{n}} tokens, but if your
+grammar does not use it, using @samp{%locations} allows for more
+accurate parse error messages.
+
@item %pure_parser
-Request a pure (reentrant) parser program (@pxref{Pure Decl, ,A Pure (Reentrant) Parser}).
+Request a pure (reentrant) parser program (@pxref{Pure Decl, ,A Pure
+(Reentrant) Parser}).
@item %no_lines
Don't generate any @code{#line} preprocessor commands in the parser
@subsection Textual Positions of Tokens
@vindex yylloc
-If you are using the @samp{@@@var{n}}-feature (@pxref{Action Features, ,Special Features for Use in Actions}) in
-actions to keep track of the textual locations of tokens and groupings,
-then you must provide this information in @code{yylex}. The function
-@code{yyparse} expects to find the textual location of a token just parsed
-in the global variable @code{yylloc}. So @code{yylex} must store the
-proper data in that variable. The value of @code{yylloc} is a structure
-and you need only initialize the members that are going to be used by the
-actions. The four members are called @code{first_line},
-@code{first_column}, @code{last_line} and @code{last_column}. Note that
-the use of this feature makes the parser noticeably slower.
+If you are using the @samp{@@@var{n}}-feature (@pxref{Action Features,
+,Special Features for Use in Actions}) in actions to keep track of the
+textual locations of tokens and groupings, then you must provide this
+information in @code{yylex}. The function @code{yyparse} expects to
+find the textual location of a token just parsed in the global variable
+@code{yylloc}. So @code{yylex} must store the proper data in that
+variable. The value of @code{yylloc} is a structure and you need only
+initialize the members that are going to be used by the actions. The
+four members are called @code{first_line}, @code{first_column},
+@code{last_line} and @code{last_column}. Note that the use of this
+feature makes the parser noticeably slower.
@tindex YYLTYPE
The data type of @code{yylloc} has the name @code{YYLTYPE}.
short option. It is followed by a cross key alphabetized by long
option.
-@table @samp
-@item -b @var{file-prefix}
-@itemx --file-prefix=@var{prefix}
-Specify a prefix to use for all Bison output file names. The names are
-chosen as if the input file were named @file{@var{prefix}.c}.
+@c Please, keep this ordered as in `bison --help'.
+@noindent
+Operations modes:
+@table @option
+@item -h
+@itemx --help
+Print a summary of the command-line options to Bison and exit.
-@item -d
-@itemx --defines
-Write an extra output file containing macro definitions for the token
-type names defined in the grammar and the semantic value type
-@code{YYSTYPE}, as well as a few @code{extern} variable declarations.
+@item -V
+@itemx --version
+Print the version number of Bison and exit.
-If the parser output file is named @file{@var{name}.c} then this file
-is named @file{@var{name}.h}.@refill
+@need 1750
+@item -y
+@itemx --yacc
+@itemx --fixed-output-files
+Equivalent to @samp{-o y.tab.c}; the parser output file is called
+@file{y.tab.c}, and the other outputs are called @file{y.output} and
+@file{y.tab.h}. The purpose of this option is to imitate Yacc's output
+file name conventions. Thus, the following shell script can substitute
+for Yacc:@refill
-This output file is essential if you wish to put the definition of
-@code{yylex} in a separate source file, because @code{yylex} needs to
-be able to refer to token type codes and the variable
-@code{yylval}. @xref{Token Values, ,Semantic Values of Tokens}.@refill
+@example
+bison -y $*
+@end example
+@end table
+
+@noindent
+Tuning the parser:
+
+@table @option
+@item -t
+@itemx --debug
+Output a definition of the macro @code{YYDEBUG} into the parser file,
+so that the debugging facilities are compiled. @xref{Debugging, ,Debugging Your Parser}.
+
+@item --locations
+Pretend that @code{%locactions} was specified. @xref{Decl Summary}.
+
+@item -p @var{prefix}
+@itemx --name-prefix=@var{prefix}
+Rename the external symbols used in the parser so that they start with
+@var{prefix} instead of @samp{yy}. The precise list of symbols renamed
+is @code{yyparse}, @code{yylex}, @code{yyerror}, @code{yynerrs},
+@code{yylval}, @code{yychar} and @code{yydebug}.
+
+For example, if you use @samp{-p c}, the names become @code{cparse},
+@code{clex}, and so on.
+
+@xref{Multiple Parsers, ,Multiple Parsers in the Same Program}.
@item -l
@itemx --no-lines
into a file named @file{@var{filename}.act}, in the form of a
brace-surrounded body fit for a @code{switch} statement.
-@item -o @var{outfile}
-@itemx --output-file=@var{outfile}
-Specify the name @var{outfile} for the parser file.
+@item -r
+@itemx --raw
+Pretend that @code{%raw} was specified. @xref{Decl Summary}.
-The other output files' names are constructed from @var{outfile}
-as described under the @samp{-v} and @samp{-d} options.
+@item -k
+@itemx --token-table
+Pretend that @code{%token_table} was specified. @xref{Decl Summary}.
+@end table
-@item -p @var{prefix}
-@itemx --name-prefix=@var{prefix}
-Rename the external symbols used in the parser so that they start with
-@var{prefix} instead of @samp{yy}. The precise list of symbols renamed
-is @code{yyparse}, @code{yylex}, @code{yyerror}, @code{yynerrs},
-@code{yylval}, @code{yychar} and @code{yydebug}.
+@noindent
+Adjust the output:
-For example, if you use @samp{-p c}, the names become @code{cparse},
-@code{clex}, and so on.
+@table @option
+@item -d
+@itemx --defines
+Write an extra output file containing macro definitions for the token
+type names defined in the grammar and the semantic value type
+@code{YYSTYPE}, as well as a few @code{extern} variable declarations.
-@xref{Multiple Parsers, ,Multiple Parsers in the Same Program}.
+If the parser output file is named @file{@var{name}.c} then this file
+is named @file{@var{name}.h}.@refill
-@item -r
-@itemx --raw
-Pretend that @code{%raw} was specified. @xref{Decl Summary}.
+This output file is essential if you wish to put the definition of
+@code{yylex} in a separate source file, because @code{yylex} needs to
+be able to refer to token type codes and the variable
+@code{yylval}. @xref{Token Values, ,Semantic Values of Tokens}.@refill
-@item -t
-@itemx --debug
-Output a definition of the macro @code{YYDEBUG} into the parser file,
-so that the debugging facilities are compiled. @xref{Debugging, ,Debugging Your Parser}.
+@item -b @var{file-prefix}
+@itemx --file-prefix=@var{prefix}
+Specify a prefix to use for all Bison output file names. The names are
+chosen as if the input file were named @file{@var{prefix}.c}.
@item -v
@itemx --verbose
called @file{foo.tab.c} by default. As a consequence, the verbose
output file is called @file{foo.output}.@refill
-@item -V
-@itemx --version
-Print the version number of Bison and exit.
-
-@item -h
-@itemx --help
-Print a summary of the command-line options to Bison and exit.
-
-@need 1750
-@item -y
-@itemx --yacc
-@itemx --fixed-output-files
-Equivalent to @samp{-o y.tab.c}; the parser output file is called
-@file{y.tab.c}, and the other outputs are called @file{y.output} and
-@file{y.tab.h}. The purpose of this option is to imitate Yacc's output
-file name conventions. Thus, the following shell script can substitute
-for Yacc:@refill
+@item -o @var{outfile}
+@itemx --output-file=@var{outfile}
+Specify the name @var{outfile} for the parser file.
-@example
-bison -y $*
-@end example
+The other output files' names are constructed from @var{outfile}
+as described under the @samp{-v} and @samp{-d} options.
@end table
@node Environment Variables, Option Cross Key, Bison Options, Invocation
@xref{Grammar Layout, ,The Overall Layout of a Bison Grammar}.
@item %@{ %@}
-All code listed between @samp{%@{} and @samp{%@}} is copied directly
-to the output file uninterpreted. Such code forms the ``C
-declarations'' section of the input file. @xref{Grammar Outline, ,Outline of a Bison Grammar}.
+All code listed between @samp{%@{} and @samp{%@}} is copied directly to
+the output file uninterpreted. Such code forms the ``C declarations''
+section of the input file. @xref{Grammar Outline, ,Outline of a Bison
+Grammar}.
@item /*@dots{}*/
Comment delimiters, as in C.
@item :
-Separates a rule's result from its components. @xref{Rules, ,Syntax of Grammar Rules}.
+Separates a rule's result from its components. @xref{Rules, ,Syntax of
+Grammar Rules}.
@item ;
Terminates a rule. @xref{Rules, ,Syntax of Grammar Rules}.
@table @asis
@item Backus-Naur Form (BNF)
Formal method of specifying context-free grammars. BNF was first used
-in the @cite{ALGOL-60} report, 1963. @xref{Language and Grammar, ,Languages and Context-Free Grammars}.
+in the @cite{ALGOL-60} report, 1963. @xref{Language and Grammar,
+,Languages and Context-Free Grammars}.
@item Context-free grammars
Grammars specified as rules that can be applied regardless of context.
Thus, if there is a rule which says that an integer can be used as an
expression, integers are allowed @emph{anywhere} an expression is
-permitted. @xref{Language and Grammar, ,Languages and Context-Free Grammars}.
+permitted. @xref{Language and Grammar, ,Languages and Context-Free
+Grammars}.
@item Dynamic allocation
Allocation of memory that occurs during execution, rather than at
@samp{c}. @xref{Precedence, ,Operator Precedence}.
@item Left recursion
-A rule whose result symbol is also its first component symbol;
-for example, @samp{expseq1 : expseq1 ',' exp;}. @xref{Recursion, ,Recursive Rules}.
+A rule whose result symbol is also its first component symbol; for
+example, @samp{expseq1 : expseq1 ',' exp;}. @xref{Recursion, ,Recursive
+Rules}.
@item Left-to-right parsing
Parsing a sentence of a language by analyzing it token by token from
@xref{Symbols}.
@item Look-ahead token
-A token already read but not yet shifted. @xref{Look-Ahead, ,Look-Ahead Tokens}.
+A token already read but not yet shifted. @xref{Look-Ahead, ,Look-Ahead
+Tokens}.
@item LALR(1)
The class of context-free grammars that Bison (like most other parser
@item Reduction
Replacing a string of nonterminals and/or terminals with a single
-nonterminal, according to a grammar rule. @xref{Algorithm, ,The Bison Parser Algorithm }.
+nonterminal, according to a grammar rule. @xref{Algorithm, ,The Bison
+Parser Algorithm }.
@item Reentrant
A reentrant subprogram is a subprogram which can be in invoked any
A language in which all operators are postfix operators.
@item Right recursion
-A rule whose result symbol is also its last component symbol;
-for example, @samp{expseq1: exp ',' expseq1;}. @xref{Recursion, ,Recursive Rules}.
+A rule whose result symbol is also its last component symbol; for
+example, @samp{expseq1: exp ',' expseq1;}. @xref{Recursion, ,Recursive
+Rules}.
@item Semantics
In computer languages, the semantics are specified by the actions
the lexical analyzer. @xref{Symbols}.
@item Terminal symbol
-A grammar symbol that has no rules in the grammar and therefore
-is grammatically indivisible. The piece of text it represents
-is a token. @xref{Language and Grammar, ,Languages and Context-Free Grammars}.
+A grammar symbol that has no rules in the grammar and therefore is
+grammatically indivisible. The piece of text it represents is a token.
+@xref{Language and Grammar, ,Languages and Context-Free Grammars}.
@end table
@node Index, , Glossary, Top
static inline void
log_resolution (int state, int LAno, int token, char *resolution)
{
- if (verboseflag)
+ if (verbose_flag)
fprintf (foutput,
_("\
Conflict in state %d between rule %d and token %s resolved as %s.\n"),
src_total += src_count;
rrc_total += rrc_count;
- if (verboseflag)
+ if (verbose_flag)
{
fprintf (foutput, _("State %d contains"), i);
conflict_report (foutput, src_count, rrc_count);
}
/* Report the total number of conflicts on STDERR. */
- if (yaccflag)
+ if (yacc_flag)
{
/* If invoked with `--yacc', use the output format specified by
POSIX. */
static char FIXED_NAME_BASE[] = "y.y";
- name_base = yaccflag ? FIXED_NAME_BASE : infile;
+ name_base = yacc_flag ? FIXED_NAME_BASE : infile;
/* BASE_LENGTH gets length of NAME_BASE, sans ".y" suffix if any. */
finput = xfopen (infile, "r");
- if (!noparserflag)
+ if (!no_parser_flag)
{
filename = getenv ("BISON_SIMPLE");
#ifdef MSDOS
fparser = xfopen (filename ? filename : PFILE, "r");
}
- if (verboseflag)
+ if (verbose_flag)
{
#ifdef MSDOS
outfile = stringappend (name_base, short_base_length, ".out");
foutput = xfopen (outfile, "w");
}
- if (noparserflag)
+ if (no_parser_flag)
{
/* use permanent name for actions file */
actfile = stringappend (name_base, short_base_length, ".act");
}
#ifdef MSDOS
- if (!noparserflag)
+ if (!no_parser_flag)
actfile = mktemp (stringappend (tmp_base, tmp_len, "acXXXXXX"));
tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "atXXXXXX"));
tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "taXXXXXX"));
tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "deXXXXXX"));
#else
- if (!noparserflag)
+ if (!no_parser_flag)
actfile = mktemp (stringappend (tmp_base, tmp_len, "act.XXXXXX"));
tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "attrs.XXXXXX"));
tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "tab.XXXXXX"));
tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "defs.XXXXXX"));
#endif /* not MSDOS */
- if (!noparserflag)
+ if (!no_parser_flag)
faction = xfopen (actfile, "w+");
fattrs = xfopen (tmpattrsfile, "w+");
ftable = xfopen (tmptabfile, "w+");
- if (definesflag)
+ if (defines_flag)
{
defsfile = stringappend (name_base, base_length, ".h");
fdefines = xfopen (tmpdefsfile, "w+");
}
#if !(defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__)))
- if (!noparserflag)
+ if (!no_parser_flag)
unlink (actfile);
unlink (tmpattrsfile);
unlink (tmptabfile);
xfclose (fparser);
- if (!noparserflag)
+ if (!no_parser_flag)
{
filename = (char *) getenv ("BISON_HAIRY");
#ifdef MSDOS
xfclose (ftmp);
xfclose (ftable);
- if (definesflag)
+ if (defines_flag)
{
ftmp = xfopen (defsfile, "w");
fflush (fdefines);
}
#if defined (VMS) & !defined (__VMS_POSIX)
- if (faction && !noparserflag)
+ if (faction && !no_parser_flag)
delete (actfile);
if (fattrs)
delete (tmpattrsfile);
sys$exit(SS$_ABORT); */
#else
#if (defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__)))
- if (actfile && !noparserflag)
+ if (actfile && !no_parser_flag)
unlink (actfile);
if (tmpattrsfile)
unlink (tmpattrsfile);
char *spec_file_prefix; /* for -b. */
char *spec_name_prefix; /* for -p. */
-int debugflag = 0;
-int definesflag = 0;
-int nolinesflag = 0;
-int noparserflag = 0;
-int rawtoknumflag = 0;
-int toknumflag = 0;
-int verboseflag = 0;
-int statisticsflag = 0;
-int yaccflag = 0; /* for -y */
+int debug_flag = 0;
+int defines_flag = 0;
+int locations_flag = 0;
+int no_lines_flag = 0;
+int no_parser_flag = 0;
+int raw_flag = 0;
+int token_table_flag = 0;
+int verbose_flag = 0;
+int statistics_flag = 0;
+int yacc_flag = 0; /* for -y */
extern char *program_name;
static struct option longopts[] =
{
- {"debug", 0, &debugflag, 1},
- {"defines", 0, &definesflag, 1},
+ {"debug", 0, &debug_flag, 1},
+ {"defines", 0, &defines_flag, 1},
{"file-prefix", 1, 0, 'b'},
- {"fixed-output-files", 0, &yaccflag, 1},
+ {"fixed-output-files", 0, &yacc_flag, 1},
{"help", 0, 0, 'h'},
{"name-prefix", 1, 0, 'p'}, /* was 'a'; apparently unused -wjh */
- {"no-lines", 0, &nolinesflag, 1},
- {"no-parser", 0, &noparserflag, 1},
+ {"locations", 0, &locations_flag, 1},
+ {"no-lines", 0, &no_lines_flag, 1},
+ {"no-parser", 0, &no_parser_flag, 1},
{"output", 1, 0, 'o'},
{"output-file", 1, 0, 'o'},
- {"raw", 0, &rawtoknumflag, 1},
- {"token-table", 0, &toknumflag, 1},
- {"verbose", 0, &verboseflag, 1},
+ {"raw", 0, &raw_flag, 1},
+ {"statistics", 0, &statistics_flag, 1},
+ {"token-table", 0, &token_table_flag, 1},
+ {"verbose", 0, &verbose_flag, 1},
{"version", 0, 0, 'V'},
- {"yacc", 0, &yaccflag, 1},
- {"statistics", 0, &statisticsflag, 1},
+ {"yacc", 0, &yacc_flag, 1},
{0, 0, 0, 0}
};
fputs (_("\
Parser:\n\
-t, --debug instrument the parser for debugging\n\
+ --locations enable locations computation\n\
-p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
-l, --no-lines don't generate `#line' directives\n\
-n, --no-parser generate the tables only\n\
break;
case 'y':
- yaccflag = 1;
+ yacc_flag = 1;
break;
case 'h':
exit (0);
case 'v':
- verboseflag = 1;
+ verbose_flag = 1;
break;
case 'd':
- definesflag = 1;
+ defines_flag = 1;
break;
case 'l':
- nolinesflag = 1;
+ no_lines_flag = 1;
break;
case 'k':
- toknumflag = 1;
+ token_table_flag = 1;
break;
case 'r':
- rawtoknumflag = 1;
+ raw_flag = 1;
break;
case 'n':
- noparserflag = 1;
+ no_parser_flag = 1;
break;
case 't':
- debugflag = 1;
+ debug_flag = 1;
break;
case 'o':
extern char *spec_file_prefix; /* for -b */
extern char *spec_name_prefix; /* for -p */
-extern int debugflag; /* for -t */
-extern int definesflag; /* for -d */
-extern int nolinesflag; /* for -l */
-extern int noparserflag; /* for -n */
-extern int rawtoknumflag; /* for -r */
-extern int statisticsflag;
-extern int toknumflag; /* for -k */
-extern int verboseflag; /* for -v */
-extern int yaccflag; /* for -y */
+extern int debug_flag; /* for -t */
+extern int defines_flag; /* for -d */
+extern int locations_flag;
+extern int no_lines_flag; /* for -l */
+extern int no_parser_flag; /* for -n */
+extern int raw_flag; /* for -r */
+extern int statistics_flag;
+extern int token_table_flag; /* for -k */
+extern int verbose_flag; /* for -v */
+extern int yacc_flag; /* for -y */
void getargs PARAMS ((int argc, char *argv[]));
}
/* the following table dictates the action taken for the various %
- directives. A setflag value causes the named flag to be set. A
+ directives. A set_flag value causes the named flag to be set. A
retval action returns the code. */
struct percent_table_struct
{
const char *name;
- void *setflag;
+ void *set_flag;
int retval;
}
percent_table[] =
{ "semantic_parser", NULL, SEMANTIC_PARSER },
{ "pure_parser", NULL, PURE_PARSER },
{ "prec", NULL, PREC },
- { "no_lines", &nolinesflag, NOOP}, /* -l */
- { "raw", &rawtoknumflag, NOOP }, /* -r */
- { "token_table", &toknumflag, NOOP}, /* -k */
+ { "locations", &locations_flag, NOOP}, /* -l */
+ { "no_lines", &no_lines_flag, NOOP}, /* -l */
+ { "raw", &raw_flag, NOOP }, /* -r */
+ { "token_table", &token_table_flag, NOOP}, /* -k */
#if 0
/* These can be utilized after main is reoganized so
open_files() is deferred 'til after read_declarations().
But %{ and %union both put information into files
that have to be opened before read_declarations().
*/
- { "yacc", &yaccflag, NOOP}, /* -y */
- { "fixed_output_files", &yaccflag, NOOP}, /* -y */
- { "defines", &definesflag, NOOP}, /* -d */
- { "no_parser", &noparserflag, NOOP}, /* -n */
+ { "yacc", &yacc_flag, NOOP}, /* -y */
+ { "fixed_output_files", &yacc_flag, NOOP}, /* -y */
+ { "defines", &defines_flag, NOOP}, /* -d */
+ { "no_parser", &no_parser_flag, NOOP}, /* -n */
{ "output_file", &spec_outfile, SETOPT}, /* -o */
{ "file_prefix", &spec_file_prefix, SETOPT}, /* -b */
{ "name_prefix", &spec_name_prefix, SETOPT}, /* -p */
/* These would be acceptable, but they do not affect processing */
- { "verbose", &verboseflag, NOOP}, /* -v */
- { "debug", &debugflag, NOOP}, /* -t */
+ { "verbose", &verbose_flag, NOOP}, /* -v */
+ { "debug", &debug_flag, NOOP}, /* -t */
/* {"help", <print usage stmt>, NOOP}, *//* -h */
/* {"version", <print version number> , NOOP}, *//* -V */
#endif
break;
if (tx->retval == SETOPT)
{
- *((char **) (tx->setflag)) = optarg;
+ *((char **) (tx->set_flag)) = optarg;
return NOOP;
}
- if (tx->setflag)
+ if (tx->set_flag)
{
- *((int *) (tx->setflag)) = 1;
+ *((int *) (tx->set_flag)) = 1;
return NOOP;
}
return tx->retval;
if (semantic_parser)
fprintf (fguard, GUARDSTR, attrsfile);
- if (noparserflag)
+ if (no_parser_flag)
return;
fprintf (faction, (semantic_parser ? ACTSTR : ACTSTR_SIMPLE), attrsfile);
fprintf (faction, "\n");
- if (noparserflag)
+ if (no_parser_flag)
return;
if (semantic_parser)
/* With the ordinary parser,
yyprhs and yyrhs are needed only for yydebug. */
- /* With the noparser option, all tables are generated */
- if (!semantic_parser && !noparserflag)
+ /* With the no_parser option, all tables are generated */
+ if (!semantic_parser && !no_parser_flag)
fprintf (ftable, "\n#if YYDEBUG != 0\n");
output_short_table (ftable, "yyprhs", rrhs,
fprintf (ftable, "\n};\n");
- if (!semantic_parser && !noparserflag)
+ if (!semantic_parser && !no_parser_flag)
fprintf (ftable, "\n#endif\n");
}
fputs ("#endif\n\n", ftable);
- if (toknumflag || noparserflag)
+ if (token_table_flag || no_parser_flag)
{
fprintf (ftable, "#define YYNTOKENS %d\n", ntokens);
fprintf (ftable, "#define YYNNTS %d\n", nvars);
fprintf (ftable, "#define YYMAXUTOK %d\n\n", max_user_token_number);
}
- if (!toknumflag && !noparserflag)
+ if (!token_table_flag && !no_parser_flag)
fprintf (ftable, "\n#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)\n\n");
/* Output the table of symbol names. */
/* add a NULL entry to list of tokens */
fprintf (ftable, ", NULL\n};\n");
- if (!toknumflag && !noparserflag)
+ if (!token_table_flag && !no_parser_flag)
fprintf (ftable, "#endif\n\n");
/* Output YYTOKNUM. */
- if (toknumflag)
+ if (token_table_flag)
{
output_short_table (ftable, "yytoknum", user_toknums,
0, 1, ntokens + 1);
/* See if the line starts with `#line.
If so, set write_line to 0. */
- if (nolinesflag)
+ if (no_lines_flag)
if (c == '#')
{
c = getc (fpars);
{
int c;
- if (!nolinesflag)
+ if (!no_lines_flag)
fprintf (ftable, "#line %d \"%s\"\n", lineno, infile);
c = getc (finput);
putc (c, ftable);
}
reader_output_yylsp (ftable);
- if (debugflag)
+ if (debug_flag)
fputs ("\
#ifndef YYDEBUG\n\
# define YYDEBUG 1\n\
if (semantic_parser)
fprintf (ftable, "#include \"%s\"\n", attrsfile);
- if (!noparserflag)
+ if (!no_parser_flag)
fprintf (ftable, "#include <stdio.h>\n\n");
/* Make "const" do nothing if not in ANSI C. */
output_stos ();
output_rule_data ();
output_actions ();
- if (!noparserflag)
+ if (!no_parser_flag)
output_parser ();
output_program ();
}
if (any_conflicts)
print_conflicts ();
- if (verboseflag)
+ if (verbose_flag)
print_grammar ();
- if (verboseflag)
+ if (verbose_flag)
for (i = 0; i < nstates; i++)
print_state (i);
}
static bucket *errtoken;
static bucket *undeftoken;
-
-/* Nonzero if any action or guard uses the @n construct. */
-static int yylsp_needed;
\f
/*===================\
if (c == '$')
{
fprintf (fout, "yyloc");
- yylsp_needed = 1;
+ locations_flag = 1;
}
else if (isdigit (c) || c == '-')
{
n = read_signed_integer (fin);
fprintf (fout, "yylsp[%d]", n - stack_offset);
- yylsp_needed = 1;
+ locations_flag = 1;
}
else
complain (_("@%s is invalid"), printable_version (c));
/* -1 while reading a character if prev char was %. */
int after_percent;
- if (!nolinesflag)
+ if (!no_lines_flag)
fprintf (fattrs, "#line %d \"%s\"\n", lineno, infile);
after_percent = 0;
typed = 1;
- if (!nolinesflag)
+ if (!no_lines_flag)
fprintf (fattrs, "\n#line %d \"%s\"\n", lineno, infile);
else
fprintf (fattrs, "\n");
stack_offset = 0;
fprintf (faction, "\ncase %d:\n", nrules);
- if (!nolinesflag)
+ if (!no_lines_flag)
fprintf (faction, "#line %d \"%s\"\n", lineno, infile);
putc ('{', faction);
stack_offset = 0;
fprintf (fguard, "\ncase %d:\n", nrules);
- if (!nolinesflag)
+ if (!no_lines_flag)
fprintf (fguard, "#line %d \"%s\"\n", lineno, infile);
putc ('{', fguard);
{
if (t == IDENTIFIER || t == BAR)
{
- int actionflag = 0;
+ int action_flag = 0;
int rulelength = 0; /* number of symbols in rhs of this rule so far */
int xactions = 0; /* JF for error checking */
bucket *first_rhs = 0;
/* If we just passed an action, that action was in the middle
of a rule, so make a dummy rule to reduce it to a
non-terminal. */
- if (actionflag)
+ if (action_flag)
{
bucket *sdummy;
p1->next = p;
p1 = p;
- actionflag = 0;
+ action_flag = 0;
}
if (t == IDENTIFIER)
else /* handle an action. */
{
copy_action (crule, rulelength);
- actionflag = 1;
+ action_flag = 1;
xactions++; /* JF */
}
rulelength++;
else if (t == LEFT_CURLY)
{
/* This case never occurs -wjh */
- if (actionflag)
+ if (action_flag)
complain (_("two actions at end of one rule"));
copy_action (crule, rulelength);
- actionflag = 1;
+ action_flag = 1;
xactions++; /* -wjh */
t = lex ();
}
continue;
fprintf (file, "#define\t%s\t%d\n", symbol,
- ((translations && !rawtoknumflag)
+ ((translations && !raw_flag)
? bp->user_token_number : bp->value));
if (semantic_parser)
fprintf (file, "#define\tT%s\t%d\n", symbol, bp->value);
error_token_number = errtoken->value;
- if (!noparserflag)
+ if (!no_parser_flag)
output_token_defines (ftable);
if (startval->class == unknown_sym)
start_symbol = startval->value;
- if (definesflag)
+ if (defines_flag)
{
output_token_defines (fdefines);
semantic_parser = 0;
pure_parser = 0;
- yylsp_needed = 0;
grammar = NULL;
fprintf (ftable, "\
/* %s, made from %s\n\
by GNU bison %s. */\n\
-\n", noparserflag ? "Bison-generated parse tables" : "A Bison parser", infile, VERSION);
+\n", no_parser_flag ? "Bison-generated parse tables" : "A Bison parser", infile, VERSION);
fputs ("#define YYBISON 1 /* Identify Bison output. */\n\n", ftable);
read_declarations ();
reader_output_yylsp (fdefines);
/* Write closing delimiters for actions and guards. */
output_trailers ();
- if (yylsp_needed)
+ if (locations_flag)
fputs ("#define YYLSP_NEEDED\n\n", ftable);
/* Assign the symbols their symbol numbers. Write #defines for the
token symbols into FDEFINES if requested. */
void
reader_output_yylsp (FILE *f)
{
- if (yylsp_needed)
+ if (locations_flag)
fputs ("\
\n\
#ifndef YYLTYPE\n\
-typedef\n\
- struct yyltype\n\
-\
- {\n\
- int timestamp;\n\
- int first_line;\n\
- int first_column;\
+typedef struct yyltype\n\
+{\n\
+ int timestamp;\n\
+ int first_line;\n\
+ int first_column;\
\n\
- int last_line;\n\
- int last_column;\n\
- char *text;\n\
- }\n\
-\
- yyltype;\n\
+ int last_line;\n\
+ int last_column;\n\
+ char *text;\n\
+} yyltype;\n\
\n\
-#define YYLTYPE yyltype\n\
+# define YYLTYPE yyltype\n\
#endif\n\
\n",
f);
static void
print_notices (void)
{
- if (yaccflag && nuseless_productions)
+ if (yacc_flag && nuseless_productions)
fprintf (stderr, _("%d rules never reduced\n"), nuseless_productions);
fprintf (stderr, _("%s contains "), infile);
reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0);
- if (verboseflag)
+ if (verbose_flag)
print_results ();
if (reduced == FALSE)
reduce_grammar_tables ();
#if 0
- if (verboseflag)
+ if (verbose_flag)
{
fprintf (foutput, "REDUCED GRAMMAR\n\n");
dump_grammar ();
}
#endif
- if (statisticsflag)
+ if (statistics_flag)
fprintf (stderr, _("reduced %s defines %d terminal%s, %d nonterminal%s\
, and %d production%s.\n"),
infile,
* VMS version of getargs: Uses DCL command parsing
* (argc and argv are ignored)
*/
-int verboseflag;
-int definesflag;
-int debugflag;
-int nolinesflag;
-extern int noparserflag;
-extern int toknumflag;
-extern int rawtoknumflag;
-extern int yaccflag;
+int verbose_flag;
+int defines_flag;
+int debug_flag;
+int no_lines_flag;
+extern int no_parser_flag;
+extern int token_table_flag;
+extern int raw_flag;
+extern int yacc_flag;
extern char * version_string;
/* Allocate storgate and initialize, since bison uses them elsewhere. */
static char output_spec[256], name_prefix_spec[256], file_prefix_spec[256];
extern char *infile;
- verboseflag = 0;
- definesflag = 0;
- debugflag = 0;
- yaccflag = 0;
- nolinesflag = 0;
- noparserflag = 0;
- toknumflag = 0;
- rawtoknumflag = 0;
+ verbose_flag = 0;
+ defines_flag = 0;
+ debug_flag = 0;
+ yacc_flag = 0;
+ no_lines_flag = 0;
+ no_parser_flag = 0;
+ token_table_flag = 0;
+ raw_flag = 0;
/*
* Check for /VERBOSE qualifier
*/
- if (cli_present("BISON$VERBOSE")) verboseflag = 1;
+ if (cli_present("BISON$VERBOSE")) verbose_flag = 1;
/*
* Check for /DEFINES qualifier
*/
- if (cli_present("BISON$DEFINES")) definesflag = 1;
+ if (cli_present("BISON$DEFINES")) defines_flag = 1;
/*
* Check for /FIXED_OUTFILES qualifier
*/
- if (cli_present("BISON$FIXED_OUTFILES")) yaccflag = 1;
- if (cli_present("BISON$YACC")) yaccflag = 1;
+ if (cli_present("BISON$FIXED_OUTFILES")) yacc_flag = 1;
+ if (cli_present("BISON$YACC")) yacc_flag = 1;
/*
* Check for /VERSION qualifier
*/
/*
* Check for /NOLINES qualifier
*/
- if (cli_present("BISON$NOLINES")) nolinesflag = 1;
+ if (cli_present("BISON$NOLINES")) no_lines_flag = 1;
/*
* Check for /NOPARSER qualifier
*/
- if (cli_present("BISON$NOPARSER")) noparserflag = 1;
+ if (cli_present("BISON$NOPARSER")) no_parser_flag = 1;
/*
* Check for /RAW qualifier
*/
- if (cli_present("BISON$RAW")) rawtoknumflag = 1;
+ if (cli_present("BISON$RAW")) raw_flag = 1;
/*
* Check for /TOKEN_TABLE qualifier
*/
- if (cli_present("BISON$TOKEN_TABLE")) toknumflag = 1;
+ if (cli_present("BISON$TOKEN_TABLE")) token_table_flag = 1;
/*
* Check for /DEBUG qualifier
*/
- if (cli_present("BISON$DEBUG")) debugflag = 1;
+ if (cli_present("BISON$DEBUG")) debug_flag = 1;
/*
* Get the filename
*/
]$4[
static int power (int base, int exponent);
-static int read_signed_integer (FILE *stream);
static void yyerror (const char *s);
static int yylex (void);
extern void perror (const char *s);
static void
yyerror (const char *s)
{
+#ifdef YYLSP_NEEDED
+ fprintf (stderr, "%d.%d:%d.%d: ",
+ yylloc.first_line, yylloc.first_column,
+ yylloc.last_line, yylloc.last_column);
+#endif
fprintf (stderr, "%s\n", s);
}
static int
-read_signed_integer (FILE *stream)
+yygetc ()
+{
+ int res = getc (yyin);
+#ifdef YYLSP_NEEDED
+ if (res == '\n')
+ {
+ yylloc.last_line++;
+ yylloc.last_column = 0;
+ }
+ else
+ yylloc.last_column++;
+#endif
+ return res;
+}
+
+
+static void
+yyungetc (int c)
+{
+#ifdef YYLSP_NEEDED
+ /* Wrong when C == `\n'. */
+ yylloc.last_column--;
+#endif
+ ungetc (c, yyin);
+}
+
+static int
+read_signed_integer (void)
{
- int c = getc (stream);
+ int c = yygetc ();
int sign = 1;
int n = 0;
if (c == '-')
{
- c = getc (stream);
+ c = yygetc ();
sign = -1;
}
while (isdigit (c))
{
n = 10 * n + (c - '0');
- c = getc (stream);
+ c = yygetc ();
}
- ungetc (c, stream);
+ yyungetc (c);
return sign * n;
}
+
+
/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number. Skips all |
{
int c;
+#ifdef YYLSP_NEEDED
+ yylloc.first_column = yylloc.last_column;
+ yylloc.first_line = yylloc.last_line;
+#endif
+
/* Skip white space. */
- while ((c = getc (yyin)) == ' ' || c == '\t')
- ;
+ while ((c = yygetc ()) == ' ' || c == '\t')
+ {
+#ifdef YYLSP_NEEDED
+ yylloc.first_column = yylloc.last_column;
+ yylloc.first_line = yylloc.last_line;
+#endif
+ }
+
/* process numbers */
if (c == '.' || isdigit (c))
{
- ungetc (c, yyin);
- yylval = read_signed_integer (yyin);
+ yyungetc (c);
+ yylval = read_signed_integer ();
return NUM;
}
+
/* Return end-of-file. */
if (c == EOF)
return 0;
+
/* Return single chars. */
return c;
}
if (argn == 2)
yyin = fopen (argv[1], "r");
else
- yyin = stdin;
+ yyin = stdin;
if (!stdin)
{
#if YYDEBUG
yydebug = 1;
#endif
+#ifdef YYLSP_NEEDED
+ yylloc.last_column = 0;
+ yylloc.last_line = 1;
+#endif
yyparse ();
return 0;
}
[1], [], [])])])
-# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, INPUT, [IF-YYERROR-VERBOSE])
-# ----------------------------------------------------------------
+# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, INPUT,
+# [ERROR-LOCATION], [IF-YYERROR-VERBOSE])
+# ------------------------------------------------------------
# Run `calc' on INPUT, and expect STDERR.
AT_DEFINE([_AT_CHECK_CALC_ERROR],
[AT_CHECK([echo "$2" | calc 2>&1 >/dev/null | grep 'parse error' >&2], 0,
[],
- [parse error[]ifelse(regexp([$1], [--yyerror-verbose]),
- [-1], [], [$3])
+[ifelse(regexp([$1], [--location]),
+ [-1], [], [$3: ])[]dnl
+parse error[]dnl
+ifelse(regexp([$1], [--yyerror-verbose]),
+ [-1], [], [$4])[]dnl
+
])])
# Some parse errors.
_AT_CHECK_CALC_ERROR([$1], [+1],
+ [1.0:1.1],
[, unexpected `'+''])
_AT_CHECK_CALC_ERROR([$1], [1//2],
+ [1.2:1.3],
[, unexpected `'/'', expecting `NUM' or `'-'' or `'(''])
_AT_CHECK_CALC_ERROR([$1], [error],
+ [1.0:1.1],
[, unexpected `$undefined.'])
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3],
+ [1.6:1.7],
[, unexpected `'=''])
+_AT_CHECK_CALC_ERROR([$1],
+ [
++1],
+ [2.0:2.1],
+ [, unexpected `'+''])
AT_CLEANUP(calc calc.c calc.h calc.output)
])# AT_CHECK_CALC
AT_CHECK_CALC([--raw])
AT_CHECK_CALC([--defines])
+AT_CHECK_CALC([--locations])
AT_CHECK_CALC([--name-prefix=calc])
AT_CHECK_CALC([--verbose])
AT_CHECK_CALC([--yacc])
AT_CHECK_CALC([--yyerror-verbose])
-AT_CHECK_CALC([--defines --name-prefix=calc --verbose --yacc --yyerror-verbose])
-# When --debug, a lot of data is sent to STDERR, we can't test it.
+AT_CHECK_CALC([--locations --yyerror-verbose])
+
+AT_CHECK_CALC([--defines --locations --name-prefix=calc --verbose --yacc --yyerror-verbose])
+
AT_CHECK_CALC([--debug])
-AT_CHECK_CALC([--debug --defines --name-prefix=calc --verbose --yacc --yyerror-verbose])
+AT_CHECK_CALC([--debug --defines --locations --name-prefix=calc --verbose --yacc --yyerror-verbose])