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'.
This commit is contained in:
Akim Demaille
2000-10-02 10:20:59 +00:00
parent d6c2cba06d
commit 89cab50df1
13 changed files with 377 additions and 251 deletions

View File

@@ -1,3 +1,27 @@
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> 2000-10-02 Akim Demaille <akim@epita.fr>
Also test parse error messages, including with YYERROR_VERBOSE. Also test parse error messages, including with YYERROR_VERBOSE.

View File

@@ -3180,14 +3180,23 @@ Declare the type of semantic values for a nonterminal symbol
(@pxref{Type Decl, ,Nonterminal Symbols}). (@pxref{Type Decl, ,Nonterminal Symbols}).
@item %start @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 @item %expect
Declare the expected number of shift-reduce conflicts Declare the expected number of shift-reduce conflicts
(@pxref{Expect Decl, ,Suppressing Conflict Warnings}). (@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 @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 @item %no_lines
Don't generate any @code{#line} preprocessor commands in the parser Don't generate any @code{#line} preprocessor commands in the parser
@@ -3474,16 +3483,17 @@ then the code in @code{yylex} might look like this:
@subsection Textual Positions of Tokens @subsection Textual Positions of Tokens
@vindex yylloc @vindex yylloc
If you are using the @samp{@@@var{n}}-feature (@pxref{Action Features, ,Special Features for Use in Actions}) in If you are using the @samp{@@@var{n}}-feature (@pxref{Action Features,
actions to keep track of the textual locations of tokens and groupings, ,Special Features for Use in Actions}) in actions to keep track of the
then you must provide this information in @code{yylex}. The function textual locations of tokens and groupings, then you must provide this
@code{yyparse} expects to find the textual location of a token just parsed information in @code{yylex}. The function @code{yyparse} expects to
in the global variable @code{yylloc}. So @code{yylex} must store the find the textual location of a token just parsed in the global variable
proper data in that variable. The value of @code{yylloc} is a structure @code{yylloc}. So @code{yylex} must store the proper data in that
and you need only initialize the members that are going to be used by the variable. The value of @code{yylloc} is a structure and you need only
actions. The four members are called @code{first_line}, initialize the members that are going to be used by the actions. The
@code{first_column}, @code{last_line} and @code{last_column}. Note that four members are called @code{first_line}, @code{first_column},
the use of this feature makes the parser noticeably slower. @code{last_line} and @code{last_column}. Note that the use of this
feature makes the parser noticeably slower.
@tindex YYLTYPE @tindex YYLTYPE
The data type of @code{yylloc} has the name @code{YYLTYPE}. The data type of @code{yylloc} has the name @code{YYLTYPE}.
@@ -4894,25 +4904,56 @@ Here is a list of options that can be used with Bison, alphabetized by
short option. It is followed by a cross key alphabetized by long short option. It is followed by a cross key alphabetized by long
option. option.
@table @samp @c Please, keep this ordered as in `bison --help'.
@item -b @var{file-prefix} @noindent
@itemx --file-prefix=@var{prefix} Operations modes:
Specify a prefix to use for all Bison output file names. The names are @table @option
chosen as if the input file were named @file{@var{prefix}.c}. @item -h
@itemx --help
Print a summary of the command-line options to Bison and exit.
@item -d @item -V
@itemx --defines @itemx --version
Write an extra output file containing macro definitions for the token Print the version number of Bison and exit.
type names defined in the grammar and the semantic value type
@code{YYSTYPE}, as well as a few @code{extern} variable declarations.
If the parser output file is named @file{@var{name}.c} then this file @need 1750
is named @file{@var{name}.h}.@refill @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 @example
@code{yylex} in a separate source file, because @code{yylex} needs to bison -y $*
be able to refer to token type codes and the variable @end example
@code{yylval}. @xref{Token Values, ,Semantic Values of Tokens}.@refill @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 @item -l
@itemx --no-lines @itemx --no-lines
@@ -4932,33 +4973,37 @@ This option also tells Bison to write the C code for the grammar actions
into a file named @file{@var{filename}.act}, in the form of a into a file named @file{@var{filename}.act}, in the form of a
brace-surrounded body fit for a @code{switch} statement. 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.
The other output files' names are constructed from @var{outfile}
as described under the @samp{-v} and @samp{-d} options.
@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 -r @item -r
@itemx --raw @itemx --raw
Pretend that @code{%raw} was specified. @xref{Decl Summary}. Pretend that @code{%raw} was specified. @xref{Decl Summary}.
@item -t @item -k
@itemx --debug @itemx --token-table
Output a definition of the macro @code{YYDEBUG} into the parser file, Pretend that @code{%token_table} was specified. @xref{Decl Summary}.
so that the debugging facilities are compiled. @xref{Debugging, ,Debugging Your Parser}. @end table
@noindent
Adjust the output:
@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.
If the parser output file is named @file{@var{name}.c} then this file
is named @file{@var{name}.h}.@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
@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 @item -v
@itemx --verbose @itemx --verbose
@@ -4976,27 +5021,12 @@ Therefore, if the input file is @file{foo.y}, then the parser file is
called @file{foo.tab.c} by default. As a consequence, the verbose called @file{foo.tab.c} by default. As a consequence, the verbose
output file is called @file{foo.output}.@refill output file is called @file{foo.output}.@refill
@item -V @item -o @var{outfile}
@itemx --version @itemx --output-file=@var{outfile}
Print the version number of Bison and exit. Specify the name @var{outfile} for the parser file.
@item -h The other output files' names are constructed from @var{outfile}
@itemx --help as described under the @samp{-v} and @samp{-d} options.
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
@example
bison -y $*
@end example
@end table @end table
@node Environment Variables, Option Cross Key, Bison Options, Invocation @node Environment Variables, Option Cross Key, Bison Options, Invocation
@@ -5280,15 +5310,17 @@ Bison declarations section or the additional C code section.
@xref{Grammar Layout, ,The Overall Layout of a Bison Grammar}. @xref{Grammar Layout, ,The Overall Layout of a Bison Grammar}.
@item %@{ %@} @item %@{ %@}
All code listed between @samp{%@{} and @samp{%@}} is copied directly All code listed between @samp{%@{} and @samp{%@}} is copied directly to
to the output file uninterpreted. Such code forms the ``C the output file uninterpreted. Such code forms the ``C declarations''
declarations'' section of the input file. @xref{Grammar Outline, ,Outline of a Bison Grammar}. section of the input file. @xref{Grammar Outline, ,Outline of a Bison
Grammar}.
@item /*@dots{}*/ @item /*@dots{}*/
Comment delimiters, as in C. Comment delimiters, as in C.
@item : @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 ; @item ;
Terminates a rule. @xref{Rules, ,Syntax of Grammar Rules}. Terminates a rule. @xref{Rules, ,Syntax of Grammar Rules}.
@@ -5305,13 +5337,15 @@ Separates alternate rules for the same result nonterminal.
@table @asis @table @asis
@item Backus-Naur Form (BNF) @item Backus-Naur Form (BNF)
Formal method of specifying context-free grammars. BNF was first used 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 @item Context-free grammars
Grammars specified as rules that can be applied regardless of context. 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 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 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 @item Dynamic allocation
Allocation of memory that occurs during execution, rather than at Allocation of memory that occurs during execution, rather than at
@@ -5352,8 +5386,9 @@ Operators having left associativity are analyzed from left to right:
@samp{c}. @xref{Precedence, ,Operator Precedence}. @samp{c}. @xref{Precedence, ,Operator Precedence}.
@item Left recursion @item Left recursion
A rule whose result symbol is also its first component symbol; A rule whose result symbol is also its first component symbol; for
for example, @samp{expseq1 : expseq1 ',' exp;}. @xref{Recursion, ,Recursive Rules}. example, @samp{expseq1 : expseq1 ',' exp;}. @xref{Recursion, ,Recursive
Rules}.
@item Left-to-right parsing @item Left-to-right parsing
Parsing a sentence of a language by analyzing it token by token from Parsing a sentence of a language by analyzing it token by token from
@@ -5372,7 +5407,8 @@ A token which consists of two or more fixed characters.
@xref{Symbols}. @xref{Symbols}.
@item Look-ahead token @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) @item LALR(1)
The class of context-free grammars that Bison (like most other parser The class of context-free grammars that Bison (like most other parser
@@ -5403,7 +5439,8 @@ performs some operation.
@item Reduction @item Reduction
Replacing a string of nonterminals and/or terminals with a single 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 @item Reentrant
A reentrant subprogram is a subprogram which can be in invoked any A reentrant subprogram is a subprogram which can be in invoked any
@@ -5414,8 +5451,9 @@ invocations. @xref{Pure Decl, ,A Pure (Reentrant) Parser}.
A language in which all operators are postfix operators. A language in which all operators are postfix operators.
@item Right recursion @item Right recursion
A rule whose result symbol is also its last component symbol; A rule whose result symbol is also its last component symbol; for
for example, @samp{expseq1: exp ',' expseq1;}. @xref{Recursion, ,Recursive Rules}. example, @samp{expseq1: exp ',' expseq1;}. @xref{Recursion, ,Recursive
Rules}.
@item Semantics @item Semantics
In computer languages, the semantics are specified by the actions In computer languages, the semantics are specified by the actions
@@ -5449,9 +5487,9 @@ The input of the Bison parser is a stream of tokens which comes from
the lexical analyzer. @xref{Symbols}. the lexical analyzer. @xref{Symbols}.
@item Terminal symbol @item Terminal symbol
A grammar symbol that has no rules in the grammar and therefore A grammar symbol that has no rules in the grammar and therefore is
is grammatically indivisible. The piece of text it represents grammatically indivisible. The piece of text it represents is a token.
is a token. @xref{Language and Grammar, ,Languages and Context-Free Grammars}. @xref{Language and Grammar, ,Languages and Context-Free Grammars}.
@end table @end table
@node Index, , Glossary, Top @node Index, , Glossary, Top

View File

@@ -45,7 +45,7 @@ static int rrc_count;
static inline void static inline void
log_resolution (int state, int LAno, int token, char *resolution) log_resolution (int state, int LAno, int token, char *resolution)
{ {
if (verboseflag) if (verbose_flag)
fprintf (foutput, fprintf (foutput,
_("\ _("\
Conflict in state %d between rule %d and token %s resolved as %s.\n"), Conflict in state %d between rule %d and token %s resolved as %s.\n"),
@@ -456,7 +456,7 @@ print_conflicts (void)
src_total += src_count; src_total += src_count;
rrc_total += rrc_count; rrc_total += rrc_count;
if (verboseflag) if (verbose_flag)
{ {
fprintf (foutput, _("State %d contains"), i); fprintf (foutput, _("State %d contains"), i);
conflict_report (foutput, src_count, rrc_count); conflict_report (foutput, src_count, rrc_count);
@@ -465,7 +465,7 @@ print_conflicts (void)
} }
/* Report the total number of conflicts on STDERR. */ /* Report the total number of conflicts on STDERR. */
if (yaccflag) if (yacc_flag)
{ {
/* If invoked with `--yacc', use the output format specified by /* If invoked with `--yacc', use the output format specified by
POSIX. */ POSIX. */

View File

@@ -232,7 +232,7 @@ open_files (void)
static char FIXED_NAME_BASE[] = "y.y"; 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. */ /* BASE_LENGTH gets length of NAME_BASE, sans ".y" suffix if any. */
@@ -255,7 +255,7 @@ open_files (void)
finput = xfopen (infile, "r"); finput = xfopen (infile, "r");
if (!noparserflag) if (!no_parser_flag)
{ {
filename = getenv ("BISON_SIMPLE"); filename = getenv ("BISON_SIMPLE");
#ifdef MSDOS #ifdef MSDOS
@@ -273,7 +273,7 @@ open_files (void)
fparser = xfopen (filename ? filename : PFILE, "r"); fparser = xfopen (filename ? filename : PFILE, "r");
} }
if (verboseflag) if (verbose_flag)
{ {
#ifdef MSDOS #ifdef MSDOS
outfile = stringappend (name_base, short_base_length, ".out"); outfile = stringappend (name_base, short_base_length, ".out");
@@ -285,7 +285,7 @@ open_files (void)
foutput = xfopen (outfile, "w"); foutput = xfopen (outfile, "w");
} }
if (noparserflag) if (no_parser_flag)
{ {
/* use permanent name for actions file */ /* use permanent name for actions file */
actfile = stringappend (name_base, short_base_length, ".act"); actfile = stringappend (name_base, short_base_length, ".act");
@@ -293,32 +293,32 @@ open_files (void)
} }
#ifdef MSDOS #ifdef MSDOS
if (!noparserflag) if (!no_parser_flag)
actfile = mktemp (stringappend (tmp_base, tmp_len, "acXXXXXX")); actfile = mktemp (stringappend (tmp_base, tmp_len, "acXXXXXX"));
tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "atXXXXXX")); tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "atXXXXXX"));
tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "taXXXXXX")); tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "taXXXXXX"));
tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "deXXXXXX")); tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "deXXXXXX"));
#else #else
if (!noparserflag) if (!no_parser_flag)
actfile = mktemp (stringappend (tmp_base, tmp_len, "act.XXXXXX")); actfile = mktemp (stringappend (tmp_base, tmp_len, "act.XXXXXX"));
tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "attrs.XXXXXX")); tmpattrsfile = mktemp (stringappend (tmp_base, tmp_len, "attrs.XXXXXX"));
tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "tab.XXXXXX")); tmptabfile = mktemp (stringappend (tmp_base, tmp_len, "tab.XXXXXX"));
tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "defs.XXXXXX")); tmpdefsfile = mktemp (stringappend (tmp_base, tmp_len, "defs.XXXXXX"));
#endif /* not MSDOS */ #endif /* not MSDOS */
if (!noparserflag) if (!no_parser_flag)
faction = xfopen (actfile, "w+"); faction = xfopen (actfile, "w+");
fattrs = xfopen (tmpattrsfile, "w+"); fattrs = xfopen (tmpattrsfile, "w+");
ftable = xfopen (tmptabfile, "w+"); ftable = xfopen (tmptabfile, "w+");
if (definesflag) if (defines_flag)
{ {
defsfile = stringappend (name_base, base_length, ".h"); defsfile = stringappend (name_base, base_length, ".h");
fdefines = xfopen (tmpdefsfile, "w+"); fdefines = xfopen (tmpdefsfile, "w+");
} }
#if !(defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__))) #if !(defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__)))
if (!noparserflag) if (!no_parser_flag)
unlink (actfile); unlink (actfile);
unlink (tmpattrsfile); unlink (tmpattrsfile);
unlink (tmptabfile); unlink (tmptabfile);
@@ -364,7 +364,7 @@ open_extra_files (void)
xfclose (fparser); xfclose (fparser);
if (!noparserflag) if (!no_parser_flag)
{ {
filename = (char *) getenv ("BISON_HAIRY"); filename = (char *) getenv ("BISON_HAIRY");
#ifdef MSDOS #ifdef MSDOS
@@ -417,7 +417,7 @@ done (void)
xfclose (ftmp); xfclose (ftmp);
xfclose (ftable); xfclose (ftable);
if (definesflag) if (defines_flag)
{ {
ftmp = xfopen (defsfile, "w"); ftmp = xfopen (defsfile, "w");
fflush (fdefines); fflush (fdefines);
@@ -430,7 +430,7 @@ done (void)
} }
#if defined (VMS) & !defined (__VMS_POSIX) #if defined (VMS) & !defined (__VMS_POSIX)
if (faction && !noparserflag) if (faction && !no_parser_flag)
delete (actfile); delete (actfile);
if (fattrs) if (fattrs)
delete (tmpattrsfile); delete (tmpattrsfile);
@@ -442,7 +442,7 @@ done (void)
sys$exit(SS$_ABORT); */ sys$exit(SS$_ABORT); */
#else #else
#if (defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__))) #if (defined (MSDOS) || (defined(_WIN32) && !defined(__CYGWIN32__)))
if (actfile && !noparserflag) if (actfile && !no_parser_flag)
unlink (actfile); unlink (actfile);
if (tmpattrsfile) if (tmpattrsfile)
unlink (tmpattrsfile); unlink (tmpattrsfile);

View File

@@ -27,36 +27,38 @@
char *spec_file_prefix; /* for -b. */ char *spec_file_prefix; /* for -b. */
char *spec_name_prefix; /* for -p. */ char *spec_name_prefix; /* for -p. */
int debugflag = 0; int debug_flag = 0;
int definesflag = 0; int defines_flag = 0;
int nolinesflag = 0; int locations_flag = 0;
int noparserflag = 0; int no_lines_flag = 0;
int rawtoknumflag = 0; int no_parser_flag = 0;
int toknumflag = 0; int raw_flag = 0;
int verboseflag = 0; int token_table_flag = 0;
int statisticsflag = 0; int verbose_flag = 0;
int yaccflag = 0; /* for -y */ int statistics_flag = 0;
int yacc_flag = 0; /* for -y */
extern char *program_name; extern char *program_name;
static struct option longopts[] = static struct option longopts[] =
{ {
{"debug", 0, &debugflag, 1}, {"debug", 0, &debug_flag, 1},
{"defines", 0, &definesflag, 1}, {"defines", 0, &defines_flag, 1},
{"file-prefix", 1, 0, 'b'}, {"file-prefix", 1, 0, 'b'},
{"fixed-output-files", 0, &yaccflag, 1}, {"fixed-output-files", 0, &yacc_flag, 1},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"name-prefix", 1, 0, 'p'}, /* was 'a'; apparently unused -wjh */ {"name-prefix", 1, 0, 'p'}, /* was 'a'; apparently unused -wjh */
{"no-lines", 0, &nolinesflag, 1}, {"locations", 0, &locations_flag, 1},
{"no-parser", 0, &noparserflag, 1}, {"no-lines", 0, &no_lines_flag, 1},
{"no-parser", 0, &no_parser_flag, 1},
{"output", 1, 0, 'o'}, {"output", 1, 0, 'o'},
{"output-file", 1, 0, 'o'}, {"output-file", 1, 0, 'o'},
{"raw", 0, &rawtoknumflag, 1}, {"raw", 0, &raw_flag, 1},
{"token-table", 0, &toknumflag, 1}, {"statistics", 0, &statistics_flag, 1},
{"verbose", 0, &verboseflag, 1}, {"token-table", 0, &token_table_flag, 1},
{"verbose", 0, &verbose_flag, 1},
{"version", 0, 0, 'V'}, {"version", 0, 0, 'V'},
{"yacc", 0, &yaccflag, 1}, {"yacc", 0, &yacc_flag, 1},
{"statistics", 0, &statisticsflag, 1},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
@@ -93,6 +95,7 @@ Operation modes:\n\
fputs (_("\ fputs (_("\
Parser:\n\ Parser:\n\
-t, --debug instrument the parser for debugging\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\ -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\
-l, --no-lines don't generate `#line' directives\n\ -l, --no-lines don't generate `#line' directives\n\
-n, --no-parser generate the tables only\n\ -n, --no-parser generate the tables only\n\
@@ -159,7 +162,7 @@ getargs (int argc, char *argv[])
break; break;
case 'y': case 'y':
yaccflag = 1; yacc_flag = 1;
break; break;
case 'h': case 'h':
@@ -171,31 +174,31 @@ getargs (int argc, char *argv[])
exit (0); exit (0);
case 'v': case 'v':
verboseflag = 1; verbose_flag = 1;
break; break;
case 'd': case 'd':
definesflag = 1; defines_flag = 1;
break; break;
case 'l': case 'l':
nolinesflag = 1; no_lines_flag = 1;
break; break;
case 'k': case 'k':
toknumflag = 1; token_table_flag = 1;
break; break;
case 'r': case 'r':
rawtoknumflag = 1; raw_flag = 1;
break; break;
case 'n': case 'n':
noparserflag = 1; no_parser_flag = 1;
break; break;
case 't': case 't':
debugflag = 1; debug_flag = 1;
break; break;
case 'o': case 'o':

View File

@@ -25,15 +25,16 @@
extern char *spec_file_prefix; /* for -b */ extern char *spec_file_prefix; /* for -b */
extern char *spec_name_prefix; /* for -p */ extern char *spec_name_prefix; /* for -p */
extern int debugflag; /* for -t */ extern int debug_flag; /* for -t */
extern int definesflag; /* for -d */ extern int defines_flag; /* for -d */
extern int nolinesflag; /* for -l */ extern int locations_flag;
extern int noparserflag; /* for -n */ extern int no_lines_flag; /* for -l */
extern int rawtoknumflag; /* for -r */ extern int no_parser_flag; /* for -n */
extern int statisticsflag; extern int raw_flag; /* for -r */
extern int toknumflag; /* for -k */ extern int statistics_flag;
extern int verboseflag; /* for -v */ extern int token_table_flag; /* for -k */
extern int yaccflag; /* for -y */ extern int verbose_flag; /* for -v */
extern int yacc_flag; /* for -y */
void getargs PARAMS ((int argc, char *argv[])); void getargs PARAMS ((int argc, char *argv[]));

View File

@@ -513,12 +513,12 @@ lex (void)
} }
/* the following table dictates the action taken for the various % /* 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. */ retval action returns the code. */
struct percent_table_struct struct percent_table_struct
{ {
const char *name; const char *name;
void *setflag; void *set_flag;
int retval; int retval;
} }
percent_table[] = percent_table[] =
@@ -539,25 +539,26 @@ percent_table[] =
{ "semantic_parser", NULL, SEMANTIC_PARSER }, { "semantic_parser", NULL, SEMANTIC_PARSER },
{ "pure_parser", NULL, PURE_PARSER }, { "pure_parser", NULL, PURE_PARSER },
{ "prec", NULL, PREC }, { "prec", NULL, PREC },
{ "no_lines", &nolinesflag, NOOP}, /* -l */ { "locations", &locations_flag, NOOP}, /* -l */
{ "raw", &rawtoknumflag, NOOP }, /* -r */ { "no_lines", &no_lines_flag, NOOP}, /* -l */
{ "token_table", &toknumflag, NOOP}, /* -k */ { "raw", &raw_flag, NOOP }, /* -r */
{ "token_table", &token_table_flag, NOOP}, /* -k */
#if 0 #if 0
/* These can be utilized after main is reoganized so /* These can be utilized after main is reoganized so
open_files() is deferred 'til after read_declarations(). open_files() is deferred 'til after read_declarations().
But %{ and %union both put information into files But %{ and %union both put information into files
that have to be opened before read_declarations(). that have to be opened before read_declarations().
*/ */
{ "yacc", &yaccflag, NOOP}, /* -y */ { "yacc", &yacc_flag, NOOP}, /* -y */
{ "fixed_output_files", &yaccflag, NOOP}, /* -y */ { "fixed_output_files", &yacc_flag, NOOP}, /* -y */
{ "defines", &definesflag, NOOP}, /* -d */ { "defines", &defines_flag, NOOP}, /* -d */
{ "no_parser", &noparserflag, NOOP}, /* -n */ { "no_parser", &no_parser_flag, NOOP}, /* -n */
{ "output_file", &spec_outfile, SETOPT}, /* -o */ { "output_file", &spec_outfile, SETOPT}, /* -o */
{ "file_prefix", &spec_file_prefix, SETOPT}, /* -b */ { "file_prefix", &spec_file_prefix, SETOPT}, /* -b */
{ "name_prefix", &spec_name_prefix, SETOPT}, /* -p */ { "name_prefix", &spec_name_prefix, SETOPT}, /* -p */
/* These would be acceptable, but they do not affect processing */ /* These would be acceptable, but they do not affect processing */
{ "verbose", &verboseflag, NOOP}, /* -v */ { "verbose", &verbose_flag, NOOP}, /* -v */
{ "debug", &debugflag, NOOP}, /* -t */ { "debug", &debug_flag, NOOP}, /* -t */
/* {"help", <print usage stmt>, NOOP}, *//* -h */ /* {"help", <print usage stmt>, NOOP}, *//* -h */
/* {"version", <print version number> , NOOP}, *//* -V */ /* {"version", <print version number> , NOOP}, *//* -V */
#endif #endif
@@ -629,12 +630,12 @@ parse_percent_token (void)
break; break;
if (tx->retval == SETOPT) if (tx->retval == SETOPT)
{ {
*((char **) (tx->setflag)) = optarg; *((char **) (tx->set_flag)) = optarg;
return NOOP; return NOOP;
} }
if (tx->setflag) if (tx->set_flag)
{ {
*((int *) (tx->setflag)) = 1; *((int *) (tx->set_flag)) = 1;
return NOOP; return NOOP;
} }
return tx->retval; return tx->retval;

View File

@@ -203,7 +203,7 @@ output_headers (void)
if (semantic_parser) if (semantic_parser)
fprintf (fguard, GUARDSTR, attrsfile); fprintf (fguard, GUARDSTR, attrsfile);
if (noparserflag) if (no_parser_flag)
return; return;
fprintf (faction, (semantic_parser ? ACTSTR : ACTSTR_SIMPLE), attrsfile); fprintf (faction, (semantic_parser ? ACTSTR : ACTSTR_SIMPLE), attrsfile);
@@ -238,7 +238,7 @@ output_trailers (void)
fprintf (faction, "\n"); fprintf (faction, "\n");
if (noparserflag) if (no_parser_flag)
return; return;
if (semantic_parser) if (semantic_parser)
@@ -300,8 +300,8 @@ output_gram (void)
/* With the ordinary parser, /* With the ordinary parser,
yyprhs and yyrhs are needed only for yydebug. */ yyprhs and yyrhs are needed only for yydebug. */
/* With the noparser option, all tables are generated */ /* With the no_parser option, all tables are generated */
if (!semantic_parser && !noparserflag) if (!semantic_parser && !no_parser_flag)
fprintf (ftable, "\n#if YYDEBUG != 0\n"); fprintf (ftable, "\n#if YYDEBUG != 0\n");
output_short_table (ftable, "yyprhs", rrhs, output_short_table (ftable, "yyprhs", rrhs,
@@ -332,7 +332,7 @@ output_gram (void)
fprintf (ftable, "\n};\n"); fprintf (ftable, "\n};\n");
if (!semantic_parser && !noparserflag) if (!semantic_parser && !no_parser_flag)
fprintf (ftable, "\n#endif\n"); fprintf (ftable, "\n#endif\n");
} }
@@ -361,7 +361,7 @@ output_rule_data (void)
fputs ("#endif\n\n", ftable); 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 YYNTOKENS %d\n", ntokens);
fprintf (ftable, "#define YYNNTS %d\n", nvars); fprintf (ftable, "#define YYNNTS %d\n", nvars);
@@ -370,7 +370,7 @@ output_rule_data (void)
fprintf (ftable, "#define YYMAXUTOK %d\n\n", max_user_token_number); 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"); fprintf (ftable, "\n#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)\n\n");
/* Output the table of symbol names. */ /* Output the table of symbol names. */
@@ -436,11 +436,11 @@ output_rule_data (void)
/* add a NULL entry to list of tokens */ /* add a NULL entry to list of tokens */
fprintf (ftable, ", NULL\n};\n"); fprintf (ftable, ", NULL\n};\n");
if (!toknumflag && !noparserflag) if (!token_table_flag && !no_parser_flag)
fprintf (ftable, "#endif\n\n"); fprintf (ftable, "#endif\n\n");
/* Output YYTOKNUM. */ /* Output YYTOKNUM. */
if (toknumflag) if (token_table_flag)
{ {
output_short_table (ftable, "yytoknum", user_toknums, output_short_table (ftable, "yytoknum", user_toknums,
0, 1, ntokens + 1); 0, 1, ntokens + 1);
@@ -1195,7 +1195,7 @@ output_parser (void)
/* See if the line starts with `#line. /* See if the line starts with `#line.
If so, set write_line to 0. */ If so, set write_line to 0. */
if (nolinesflag) if (no_lines_flag)
if (c == '#') if (c == '#')
{ {
c = getc (fpars); c = getc (fpars);
@@ -1254,7 +1254,7 @@ output_program (void)
{ {
int c; int c;
if (!nolinesflag) if (!no_lines_flag)
fprintf (ftable, "#line %d \"%s\"\n", lineno, infile); fprintf (ftable, "#line %d \"%s\"\n", lineno, infile);
c = getc (finput); c = getc (finput);
@@ -1298,7 +1298,7 @@ output (void)
putc (c, ftable); putc (c, ftable);
} }
reader_output_yylsp (ftable); reader_output_yylsp (ftable);
if (debugflag) if (debug_flag)
fputs ("\ fputs ("\
#ifndef YYDEBUG\n\ #ifndef YYDEBUG\n\
# define YYDEBUG 1\n\ # define YYDEBUG 1\n\
@@ -1309,7 +1309,7 @@ output (void)
if (semantic_parser) if (semantic_parser)
fprintf (ftable, "#include \"%s\"\n", attrsfile); fprintf (ftable, "#include \"%s\"\n", attrsfile);
if (!noparserflag) if (!no_parser_flag)
fprintf (ftable, "#include <stdio.h>\n\n"); fprintf (ftable, "#include <stdio.h>\n\n");
/* Make "const" do nothing if not in ANSI C. */ /* Make "const" do nothing if not in ANSI C. */
@@ -1333,7 +1333,7 @@ output (void)
output_stos (); output_stos ();
output_rule_data (); output_rule_data ();
output_actions (); output_actions ();
if (!noparserflag) if (!no_parser_flag)
output_parser (); output_parser ();
output_program (); output_program ();
} }

View File

@@ -351,10 +351,10 @@ print_results (void)
if (any_conflicts) if (any_conflicts)
print_conflicts (); print_conflicts ();
if (verboseflag) if (verbose_flag)
print_grammar (); print_grammar ();
if (verboseflag) if (verbose_flag)
for (i = 0; i < nstates; i++) for (i = 0; i < nstates; i++)
print_state (i); print_state (i);
} }

View File

@@ -67,9 +67,6 @@ static int gensym_count;
static bucket *errtoken; static bucket *errtoken;
static bucket *undeftoken; static bucket *undeftoken;
/* Nonzero if any action or guard uses the @n construct. */
static int yylsp_needed;
/*===================\ /*===================\
@@ -256,7 +253,7 @@ copy_at (FILE *fin, FILE *fout, int stack_offset)
if (c == '$') if (c == '$')
{ {
fprintf (fout, "yyloc"); fprintf (fout, "yyloc");
yylsp_needed = 1; locations_flag = 1;
} }
else if (isdigit (c) || c == '-') else if (isdigit (c) || c == '-')
{ {
@@ -266,7 +263,7 @@ copy_at (FILE *fin, FILE *fout, int stack_offset)
n = read_signed_integer (fin); n = read_signed_integer (fin);
fprintf (fout, "yylsp[%d]", n - stack_offset); fprintf (fout, "yylsp[%d]", n - stack_offset);
yylsp_needed = 1; locations_flag = 1;
} }
else else
complain (_("@%s is invalid"), printable_version (c)); complain (_("@%s is invalid"), printable_version (c));
@@ -284,7 +281,7 @@ copy_definition (void)
/* -1 while reading a character if prev char was %. */ /* -1 while reading a character if prev char was %. */
int after_percent; int after_percent;
if (!nolinesflag) if (!no_lines_flag)
fprintf (fattrs, "#line %d \"%s\"\n", lineno, infile); fprintf (fattrs, "#line %d \"%s\"\n", lineno, infile);
after_percent = 0; after_percent = 0;
@@ -631,7 +628,7 @@ parse_union_decl (void)
typed = 1; typed = 1;
if (!nolinesflag) if (!no_lines_flag)
fprintf (fattrs, "\n#line %d \"%s\"\n", lineno, infile); fprintf (fattrs, "\n#line %d \"%s\"\n", lineno, infile);
else else
fprintf (fattrs, "\n"); fprintf (fattrs, "\n");
@@ -919,7 +916,7 @@ copy_action (symbol_list * rule, int stack_offset)
stack_offset = 0; stack_offset = 0;
fprintf (faction, "\ncase %d:\n", nrules); fprintf (faction, "\ncase %d:\n", nrules);
if (!nolinesflag) if (!no_lines_flag)
fprintf (faction, "#line %d \"%s\"\n", lineno, infile); fprintf (faction, "#line %d \"%s\"\n", lineno, infile);
putc ('{', faction); putc ('{', faction);
@@ -1058,7 +1055,7 @@ copy_guard (symbol_list * rule, int stack_offset)
stack_offset = 0; stack_offset = 0;
fprintf (fguard, "\ncase %d:\n", nrules); fprintf (fguard, "\ncase %d:\n", nrules);
if (!nolinesflag) if (!no_lines_flag)
fprintf (fguard, "#line %d \"%s\"\n", lineno, infile); fprintf (fguard, "#line %d \"%s\"\n", lineno, infile);
putc ('{', fguard); putc ('{', fguard);
@@ -1303,7 +1300,7 @@ readgram (void)
{ {
if (t == IDENTIFIER || t == BAR) 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 rulelength = 0; /* number of symbols in rhs of this rule so far */
int xactions = 0; /* JF for error checking */ int xactions = 0; /* JF for error checking */
bucket *first_rhs = 0; bucket *first_rhs = 0;
@@ -1399,7 +1396,7 @@ readgram (void)
/* If we just passed an action, that action was in the middle /* 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 of a rule, so make a dummy rule to reduce it to a
non-terminal. */ non-terminal. */
if (actionflag) if (action_flag)
{ {
bucket *sdummy; bucket *sdummy;
@@ -1433,7 +1430,7 @@ readgram (void)
p1->next = p; p1->next = p;
p1 = p; p1 = p;
actionflag = 0; action_flag = 0;
} }
if (t == IDENTIFIER) if (t == IDENTIFIER)
@@ -1447,7 +1444,7 @@ readgram (void)
else /* handle an action. */ else /* handle an action. */
{ {
copy_action (crule, rulelength); copy_action (crule, rulelength);
actionflag = 1; action_flag = 1;
xactions++; /* JF */ xactions++; /* JF */
} }
rulelength++; rulelength++;
@@ -1478,10 +1475,10 @@ readgram (void)
else if (t == LEFT_CURLY) else if (t == LEFT_CURLY)
{ {
/* This case never occurs -wjh */ /* This case never occurs -wjh */
if (actionflag) if (action_flag)
complain (_("two actions at end of one rule")); complain (_("two actions at end of one rule"));
copy_action (crule, rulelength); copy_action (crule, rulelength);
actionflag = 1; action_flag = 1;
xactions++; /* -wjh */ xactions++; /* -wjh */
t = lex (); t = lex ();
} }
@@ -1622,7 +1619,7 @@ output_token_defines (FILE *file)
continue; continue;
fprintf (file, "#define\t%s\t%d\n", symbol, fprintf (file, "#define\t%s\t%d\n", symbol,
((translations && !rawtoknumflag) ((translations && !raw_flag)
? bp->user_token_number : bp->value)); ? bp->user_token_number : bp->value));
if (semantic_parser) if (semantic_parser)
fprintf (file, "#define\tT%s\t%d\n", symbol, bp->value); fprintf (file, "#define\tT%s\t%d\n", symbol, bp->value);
@@ -1750,7 +1747,7 @@ packsymbols (void)
error_token_number = errtoken->value; error_token_number = errtoken->value;
if (!noparserflag) if (!no_parser_flag)
output_token_defines (ftable); output_token_defines (ftable);
if (startval->class == unknown_sym) if (startval->class == unknown_sym)
@@ -1760,7 +1757,7 @@ packsymbols (void)
start_symbol = startval->value; start_symbol = startval->value;
if (definesflag) if (defines_flag)
{ {
output_token_defines (fdefines); output_token_defines (fdefines);
@@ -1892,7 +1889,6 @@ reader (void)
semantic_parser = 0; semantic_parser = 0;
pure_parser = 0; pure_parser = 0;
yylsp_needed = 0;
grammar = NULL; grammar = NULL;
@@ -1918,7 +1914,7 @@ reader (void)
fprintf (ftable, "\ fprintf (ftable, "\
/* %s, made from %s\n\ /* %s, made from %s\n\
by GNU bison %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); fputs ("#define YYBISON 1 /* Identify Bison output. */\n\n", ftable);
read_declarations (); read_declarations ();
@@ -1933,7 +1929,7 @@ reader (void)
reader_output_yylsp (fdefines); reader_output_yylsp (fdefines);
/* Write closing delimiters for actions and guards. */ /* Write closing delimiters for actions and guards. */
output_trailers (); output_trailers ();
if (yylsp_needed) if (locations_flag)
fputs ("#define YYLSP_NEEDED\n\n", ftable); fputs ("#define YYLSP_NEEDED\n\n", ftable);
/* Assign the symbols their symbol numbers. Write #defines for the /* Assign the symbols their symbol numbers. Write #defines for the
token symbols into FDEFINES if requested. */ token symbols into FDEFINES if requested. */
@@ -1949,26 +1945,22 @@ reader (void)
void void
reader_output_yylsp (FILE *f) reader_output_yylsp (FILE *f)
{ {
if (yylsp_needed) if (locations_flag)
fputs ("\ fputs ("\
\n\ \n\
#ifndef YYLTYPE\n\ #ifndef YYLTYPE\n\
typedef\n\ typedef struct yyltype\n\
struct yyltype\n\ {\n\
\ int timestamp;\n\
{\n\ int first_line;\n\
int timestamp;\n\ int first_column;\
int first_line;\n\
int first_column;\
\n\ \n\
int last_line;\n\ int last_line;\n\
int last_column;\n\ int last_column;\n\
char *text;\n\ char *text;\n\
}\n\ } yyltype;\n\
\
yyltype;\n\
\n\ \n\
#define YYLTYPE yyltype\n\ # define YYLTYPE yyltype\n\
#endif\n\ #endif\n\
\n", \n",
f); f);

View File

@@ -483,7 +483,7 @@ dump_grammar (void)
static void static void
print_notices (void) print_notices (void)
{ {
if (yaccflag && nuseless_productions) if (yacc_flag && nuseless_productions)
fprintf (stderr, _("%d rules never reduced\n"), nuseless_productions); fprintf (stderr, _("%d rules never reduced\n"), nuseless_productions);
fprintf (stderr, _("%s contains "), infile); fprintf (stderr, _("%s contains "), infile);
@@ -523,7 +523,7 @@ reduce_grammar (void)
reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0); reduced = (bool) (nuseless_nonterminals + nuseless_productions > 0);
if (verboseflag) if (verbose_flag)
print_results (); print_results ();
if (reduced == FALSE) if (reduced == FALSE)
@@ -537,14 +537,14 @@ reduce_grammar (void)
reduce_grammar_tables (); reduce_grammar_tables ();
#if 0 #if 0
if (verboseflag) if (verbose_flag)
{ {
fprintf (foutput, "REDUCED GRAMMAR\n\n"); fprintf (foutput, "REDUCED GRAMMAR\n\n");
dump_grammar (); dump_grammar ();
} }
#endif #endif
if (statisticsflag) if (statistics_flag)
fprintf (stderr, _("reduced %s defines %d terminal%s, %d nonterminal%s\ fprintf (stderr, _("reduced %s defines %d terminal%s, %d nonterminal%s\
, and %d production%s.\n"), , and %d production%s.\n"),
infile, infile,

View File

@@ -27,14 +27,14 @@ Boston, MA 02111-1307, USA. */
* VMS version of getargs: Uses DCL command parsing * VMS version of getargs: Uses DCL command parsing
* (argc and argv are ignored) * (argc and argv are ignored)
*/ */
int verboseflag; int verbose_flag;
int definesflag; int defines_flag;
int debugflag; int debug_flag;
int nolinesflag; int no_lines_flag;
extern int noparserflag; extern int no_parser_flag;
extern int toknumflag; extern int token_table_flag;
extern int rawtoknumflag; extern int raw_flag;
extern int yaccflag; extern int yacc_flag;
extern char * version_string; extern char * version_string;
/* Allocate storgate and initialize, since bison uses them elsewhere. */ /* Allocate storgate and initialize, since bison uses them elsewhere. */
@@ -50,27 +50,27 @@ getargs(argc,argv)
static char output_spec[256], name_prefix_spec[256], file_prefix_spec[256]; static char output_spec[256], name_prefix_spec[256], file_prefix_spec[256];
extern char *infile; extern char *infile;
verboseflag = 0; verbose_flag = 0;
definesflag = 0; defines_flag = 0;
debugflag = 0; debug_flag = 0;
yaccflag = 0; yacc_flag = 0;
nolinesflag = 0; no_lines_flag = 0;
noparserflag = 0; no_parser_flag = 0;
toknumflag = 0; token_table_flag = 0;
rawtoknumflag = 0; raw_flag = 0;
/* /*
* Check for /VERBOSE qualifier * Check for /VERBOSE qualifier
*/ */
if (cli_present("BISON$VERBOSE")) verboseflag = 1; if (cli_present("BISON$VERBOSE")) verbose_flag = 1;
/* /*
* Check for /DEFINES qualifier * Check for /DEFINES qualifier
*/ */
if (cli_present("BISON$DEFINES")) definesflag = 1; if (cli_present("BISON$DEFINES")) defines_flag = 1;
/* /*
* Check for /FIXED_OUTFILES qualifier * Check for /FIXED_OUTFILES qualifier
*/ */
if (cli_present("BISON$FIXED_OUTFILES")) yaccflag = 1; if (cli_present("BISON$FIXED_OUTFILES")) yacc_flag = 1;
if (cli_present("BISON$YACC")) yaccflag = 1; if (cli_present("BISON$YACC")) yacc_flag = 1;
/* /*
* Check for /VERSION qualifier * Check for /VERSION qualifier
*/ */
@@ -78,23 +78,23 @@ getargs(argc,argv)
/* /*
* Check for /NOLINES 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 * Check for /NOPARSER qualifier
*/ */
if (cli_present("BISON$NOPARSER")) noparserflag = 1; if (cli_present("BISON$NOPARSER")) no_parser_flag = 1;
/* /*
* Check for /RAW qualifier * Check for /RAW qualifier
*/ */
if (cli_present("BISON$RAW")) rawtoknumflag = 1; if (cli_present("BISON$RAW")) raw_flag = 1;
/* /*
* Check for /TOKEN_TABLE qualifier * 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 * Check for /DEBUG qualifier
*/ */
if (cli_present("BISON$DEBUG")) debugflag = 1; if (cli_present("BISON$DEBUG")) debug_flag = 1;
/* /*
* Get the filename * Get the filename
*/ */

View File

@@ -38,7 +38,6 @@ AT_DATA([calc.y],
]$4[ ]$4[
static int power (int base, int exponent); static int power (int base, int exponent);
static int read_signed_integer (FILE *stream);
static void yyerror (const char *s); static void yyerror (const char *s);
static int yylex (void); static int yylex (void);
extern void perror (const char *s); extern void perror (const char *s);
@@ -88,33 +87,67 @@ FILE *yyin;
static void static void
yyerror (const char *s) 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); fprintf (stderr, "%s\n", s);
} }
static int static int
read_signed_integer (FILE *stream) yygetc ()
{ {
int c = getc (stream); 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 = yygetc ();
int sign = 1; int sign = 1;
int n = 0; int n = 0;
if (c == '-') if (c == '-')
{ {
c = getc (stream); c = yygetc ();
sign = -1; sign = -1;
} }
while (isdigit (c)) while (isdigit (c))
{ {
n = 10 * n + (c - '0'); n = 10 * n + (c - '0');
c = getc (stream); c = yygetc ();
} }
ungetc (c, stream); yyungetc (c);
return sign * n; return sign * n;
} }
/*---------------------------------------------------------------. /*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token | | Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number. Skips all | | NUM, or the ASCII character read if not a number. Skips all |
@@ -126,19 +159,32 @@ yylex (void)
{ {
int c; int c;
#ifdef YYLSP_NEEDED
yylloc.first_column = yylloc.last_column;
yylloc.first_line = yylloc.last_line;
#endif
/* Skip white space. */ /* 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 */ /* process numbers */
if (c == '.' || isdigit (c)) if (c == '.' || isdigit (c))
{ {
ungetc (c, yyin); yyungetc (c);
yylval = read_signed_integer (yyin); yylval = read_signed_integer ();
return NUM; return NUM;
} }
/* Return end-of-file. */ /* Return end-of-file. */
if (c == EOF) if (c == EOF)
return 0; return 0;
/* Return single chars. */ /* Return single chars. */
return c; return c;
} }
@@ -160,7 +206,7 @@ main (int argn, const char **argv)
if (argn == 2) if (argn == 2)
yyin = fopen (argv[1], "r"); yyin = fopen (argv[1], "r");
else else
yyin = stdin; yyin = stdin;
if (!stdin) if (!stdin)
{ {
@@ -170,6 +216,10 @@ main (int argn, const char **argv)
#if YYDEBUG #if YYDEBUG
yydebug = 1; yydebug = 1;
#endif
#ifdef YYLSP_NEEDED
yylloc.last_column = 0;
yylloc.last_line = 1;
#endif #endif
yyparse (); yyparse ();
return 0; return 0;
@@ -204,14 +254,19 @@ AT_DEFINE([_AT_CHECK_CALC],
[1], [], [])])]) [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. # Run `calc' on INPUT, and expect STDERR.
AT_DEFINE([_AT_CHECK_CALC_ERROR], AT_DEFINE([_AT_CHECK_CALC_ERROR],
[AT_CHECK([echo "$2" | calc 2>&1 >/dev/null | grep 'parse error' >&2], 0, [AT_CHECK([echo "$2" | calc 2>&1 >/dev/null | grep 'parse error' >&2], 0,
[], [],
[parse error[]ifelse(regexp([$1], [--yyerror-verbose]), [ifelse(regexp([$1], [--location]),
[-1], [], [$3]) [-1], [], [$3: ])[]dnl
parse error[]dnl
ifelse(regexp([$1], [--yyerror-verbose]),
[-1], [], [$4])[]dnl
])]) ])])
@@ -248,13 +303,22 @@ _AT_CHECK_CALC([$1],
# Some parse errors. # Some parse errors.
_AT_CHECK_CALC_ERROR([$1], [+1], _AT_CHECK_CALC_ERROR([$1], [+1],
[1.0:1.1],
[, unexpected `'+'']) [, unexpected `'+''])
_AT_CHECK_CALC_ERROR([$1], [1//2], _AT_CHECK_CALC_ERROR([$1], [1//2],
[1.2:1.3],
[, unexpected `'/'', expecting `NUM' or `'-'' or `'('']) [, unexpected `'/'', expecting `NUM' or `'-'' or `'(''])
_AT_CHECK_CALC_ERROR([$1], [error], _AT_CHECK_CALC_ERROR([$1], [error],
[1.0:1.1],
[, unexpected `$undefined.']) [, unexpected `$undefined.'])
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], _AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3],
[1.6:1.7],
[, unexpected `'='']) [, unexpected `'=''])
_AT_CHECK_CALC_ERROR([$1],
[
+1],
[2.0:2.1],
[, unexpected `'+''])
AT_CLEANUP(calc calc.c calc.h calc.output) AT_CLEANUP(calc calc.c calc.h calc.output)
])# AT_CHECK_CALC ])# AT_CHECK_CALC
@@ -271,12 +335,15 @@ AT_CHECK_CALC()
AT_CHECK_CALC([--raw]) AT_CHECK_CALC([--raw])
AT_CHECK_CALC([--defines]) AT_CHECK_CALC([--defines])
AT_CHECK_CALC([--locations])
AT_CHECK_CALC([--name-prefix=calc]) AT_CHECK_CALC([--name-prefix=calc])
AT_CHECK_CALC([--verbose]) AT_CHECK_CALC([--verbose])
AT_CHECK_CALC([--yacc]) AT_CHECK_CALC([--yacc])
AT_CHECK_CALC([--yyerror-verbose]) 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])
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])