Since we now use obstacks, more % directives can be enabled.

* src/lex.c (percent_table): Also accept `%yacc',
`%fixed_output_files', `%defines', `%no_parser', `%verbose', and
`%debug'.
Handle the actions for `%semantic_parser' and `%pure_parser' here,
instead of returning a token.
* src/lex.h (SEMANTIC_PARSER, PURE_PARSER): Remove, unused.
* src/reader.c (read_declarations): Adjust.
* src/files.c (open_files): Don't call `compute_base_names', don't
compute `attrsfile' since they depend upon data which might be
*in* the input file now.
(output_files): Do it here.
* src/output.c (output_headers): Document the fact that this patch
introduces a guaranteed SEGV for semantic parsers.
* doc/bison.texinfo: Document them.
* tests/suite.at: Exercise these %options.
This commit is contained in:
Akim Demaille
2001-01-18 14:47:09 +00:00
parent dde188fc64
commit 6deb44470e
14 changed files with 496 additions and 388 deletions

View File

@@ -1,3 +1,23 @@
2001-01-18 Akim Demaille <akim@epita.fr>
Since we now use obstacks, more % directives can be enabled.
* src/lex.c (percent_table): Also accept `%yacc',
`%fixed_output_files', `%defines', `%no_parser', `%verbose', and
`%debug'.
Handle the actions for `%semantic_parser' and `%pure_parser' here,
instead of returning a token.
* src/lex.h (SEMANTIC_PARSER, PURE_PARSER): Remove, unused.
* src/reader.c (read_declarations): Adjust.
* src/files.c (open_files): Don't call `compute_base_names', don't
compute `attrsfile' since they depend upon data which might be
*in* the input file now.
(output_files): Do it here.
* src/output.c (output_headers): Document the fact that this patch
introduces a guaranteed SEGV for semantic parsers.
* doc/bison.texinfo: Document them.
* tests/suite.at: Exercise these %options.
2000-12-20 Akim Demaille <akim@epita.fr>
Also handle the output file (--verbose) with obstacks.

5
NEWS
View File

@@ -10,6 +10,10 @@ Changes in version 1.28a:
* Added the old Bison reference card.
* Added `--locations' and `%locations'.
* New directives.
`%yacc', `%fixed_output_files', `%defines', `%no_parser', `%verbose', and
`%debug'.
Changes in version 1.28:
@@ -84,4 +88,3 @@ Changes in version 1.22:
Changes in version 1.20:
Output file does not redefine const for C++.

View File

@@ -33,8 +33,8 @@ Indirect:
bison.info-1: 1306
bison.info-2: 50276
bison.info-3: 98079
bison.info-4: 147374
bison.info-5: 197192
bison.info-4: 147596
bison.info-5: 191991

Tag Table:
(Indirect)
@@ -93,42 +93,42 @@ Node: Expect Decl110281
Node: Start Decl111827
Node: Pure Decl112205
Node: Decl Summary113882
Node: Multiple Parsers117718
Node: Interface119212
Node: Parser Function120084
Node: Lexical120919
Node: Calling Convention122325
Node: Token Values125096
Node: Token Positions126245
Node: Pure Calling127137
Node: Error Reporting130069
Node: Action Features132191
Node: Algorithm135852
Node: Look-Ahead138145
Node: Shift/Reduce140277
Node: Precedence143189
Node: Why Precedence143840
Node: Using Precedence145705
Node: Precedence Examples146673
Node: How Precedence147374
Node: Contextual Precedence148523
Node: Parser States150314
Node: Reduce/Reduce151557
Node: Mystery Conflicts155118
Node: Stack Overflow158504
Node: Error Recovery159877
Node: Context Dependency165013
Node: Semantic Tokens165861
Node: Lexical Tie-ins168878
Node: Tie-in Recovery170426
Node: Debugging172598
Node: Invocation175899
Node: Bison Options176629
Node: Environment Variables180983
Node: Option Cross Key181831
Node: VMS Invocation182721
Node: Table of Symbols183505
Node: Glossary190902
Node: Index197192
Node: Multiple Parsers119609
Node: Interface121103
Node: Parser Function121975
Node: Lexical122810
Node: Calling Convention124216
Node: Token Values126987
Node: Token Positions128136
Node: Pure Calling129028
Node: Error Reporting131960
Node: Action Features134082
Node: Algorithm137743
Node: Look-Ahead140036
Node: Shift/Reduce142168
Node: Precedence145080
Node: Why Precedence145731
Node: Using Precedence147596
Node: Precedence Examples148564
Node: How Precedence149265
Node: Contextual Precedence150414
Node: Parser States152205
Node: Reduce/Reduce153448
Node: Mystery Conflicts157009
Node: Stack Overflow160395
Node: Error Recovery161768
Node: Context Dependency166904
Node: Semantic Tokens167752
Node: Lexical Tie-ins170769
Node: Tie-in Recovery172317
Node: Debugging174489
Node: Invocation177790
Node: Bison Options178520
Node: Environment Variables181893
Node: Option Cross Key182741
Node: VMS Invocation183631
Node: Table of Symbols184415
Node: Glossary191991
Node: Index198281

End Tag Table

View File

@@ -465,6 +465,11 @@ Bison Declaration Summary
Declare the expected number of shift-reduce conflicts (*note
Suppressing Conflict Warnings: Expect Decl.).
`%yacc'
`%fixed_output_files'
Pretend the option `--yacc' was given, i.e., imitate Yacc,
including its naming conventions. *Note Bison Options::, for more.
`%locations'
Generate the code processing the locations (*note Special Features
for Use in Actions: Action Features.). This mode is enabled as
@@ -476,6 +481,15 @@ Bison Declaration Summary
Request a pure (reentrant) parser program (*note A Pure
(Reentrant) Parser: Pure Decl.).
`%no_parser'
Do not include any C code in the parser file; generate tables
only. The parser file contains just `#define' directives and
static variable declarations.
This option also tells Bison to write the C code for the grammar
actions into a file named `FILENAME.act', in the form of a
brace-surrounded body fit for a `switch' statement.
`%no_lines'
Don't generate any `#line' preprocessor commands in the parser
file. Ordinarily Bison writes these commands in the parser file
@@ -484,6 +498,39 @@ Bison Declaration Summary
directive causes them to associate errors with the parser file,
treating it an independent source file in its own right.
`%debug'
Output a definition of the macro `YYDEBUG' into the parser file, so
that the debugging facilities are compiled. *Note Debugging Your
Parser: Debugging.
`%defines'
Write an extra output file containing macro definitions for the
token type names defined in the grammar and the semantic value type
`YYSTYPE', as well as a few `extern' variable declarations.
If the parser output file is named `NAME.c' then this file is
named `NAME.h'.
This output file is essential if you wish to put the definition of
`yylex' in a separate source file, because `yylex' needs to be
able to refer to token type codes and the variable `yylval'.
*Note Semantic Values of Tokens: Token Values.
`%verbose'
Write an extra output file containing verbose descriptions of the
parser states and what is done for each type of look-ahead token in
that state.
This file also describes all the conflicts, both those resolved by
operator precedence and the unresolved ones.
The file's name is made by removing `.tab.c' or `.c' from the
parser output file name, and adding `.output' instead.
Therefore, if the input file is `foo.y', then the parser file is
called `foo.tab.c' by default. As a consequence, the verbose
output file is called `foo.output'.
`%raw'
The output file `NAME.h' normally defines the tokens with
Yacc-compatible token numbers. If this option is specified, the
@@ -1248,48 +1295,3 @@ of left or right association is a matter of whether the parser chooses
to shift or reduce when the stack contains `1 - 2' and the look-ahead
token is `-': shifting makes right-associativity.

File: bison.info, Node: Using Precedence, Next: Precedence Examples, Prev: Why Precedence, Up: Precedence
Specifying Operator Precedence
------------------------------
Bison allows you to specify these choices with the operator
precedence declarations `%left' and `%right'. Each such declaration
contains a list of tokens, which are operators whose precedence and
associativity is being declared. The `%left' declaration makes all
those operators left-associative and the `%right' declaration makes
them right-associative. A third alternative is `%nonassoc', which
declares that it is a syntax error to find the same operator twice "in a
row".
The relative precedence of different operators is controlled by the
order in which they are declared. The first `%left' or `%right'
declaration in the file declares the operators whose precedence is
lowest, the next such declaration declares the operators whose
precedence is a little higher, and so on.

File: bison.info, Node: Precedence Examples, Next: How Precedence, Prev: Using Precedence, Up: Precedence
Precedence Examples
-------------------
In our example, we would want the following declarations:
%left '<'
%left '-'
%left '*'
In a more complete example, which supports other operators as well,
we would declare them in groups of equal precedence. For example,
`'+'' is declared with `'-'':
%left '<' '>' '=' NE LE GE
%left '+' '-'
%left '*' '/'
(Here `NE' and so on stand for the operators for "not equal" and so on.
We assume that these tokens are more than one character long and
therefore are represented by names, not character literals.)

View File

@@ -28,6 +28,51 @@ License", "Conditions for Using Bison" and this permission notice may be
included in translations approved by the Free Software Foundation
instead of in the original English.

File: bison.info, Node: Using Precedence, Next: Precedence Examples, Prev: Why Precedence, Up: Precedence
Specifying Operator Precedence
------------------------------
Bison allows you to specify these choices with the operator
precedence declarations `%left' and `%right'. Each such declaration
contains a list of tokens, which are operators whose precedence and
associativity is being declared. The `%left' declaration makes all
those operators left-associative and the `%right' declaration makes
them right-associative. A third alternative is `%nonassoc', which
declares that it is a syntax error to find the same operator twice "in a
row".
The relative precedence of different operators is controlled by the
order in which they are declared. The first `%left' or `%right'
declaration in the file declares the operators whose precedence is
lowest, the next such declaration declares the operators whose
precedence is a little higher, and so on.

File: bison.info, Node: Precedence Examples, Next: How Precedence, Prev: Using Precedence, Up: Precedence
Precedence Examples
-------------------
In our example, we would want the following declarations:
%left '<'
%left '-'
%left '*'
In a more complete example, which supports other operators as well,
we would declare them in groups of equal precedence. For example,
`'+'' is declared with `'-'':
%left '<' '>' '=' NE LE GE
%left '+' '-'
%left '*' '/'
(Here `NE' and so on stand for the operators for "not equal" and so on.
We assume that these tokens are more than one character long and
therefore are represented by names, not character literals.)

File: bison.info, Node: How Precedence, Prev: Precedence Examples, Up: Precedence
@@ -803,9 +848,9 @@ Tuning the parser:
`-t'
`--debug'
Output a definition of the macro `YYDEBUG' into the parser file,
so that the debugging facilities are compiled. *Note Debugging
Your Parser: Debugging.
Output a definition of the macro `YYDEBUG' into the parser file, so
that the debugging facilities are compiled. *Note Debugging Your
Parser: Debugging.
`--locations'
Pretend that `%locactions' was specified. *Note Decl Summary::.
@@ -833,13 +878,7 @@ Tuning the parser:
`-n'
`--no-parser'
Do not include any C code in the parser file; generate tables
only. The parser file contains just `#define' directives and
static variable declarations.
This option also tells Bison to write the C code for the grammar
actions into a file named `FILENAME.act', in the form of a
brace-surrounded body fit for a `switch' statement.
Pretend that `%no_parser' was specified. *Note Decl Summary::.
`-r'
`--raw'
@@ -853,17 +892,10 @@ Adjust the output:
`-d'
`--defines'
Write an extra output file containing macro definitions for the
token type names defined in the grammar and the semantic value type
`YYSTYPE', as well as a few `extern' variable declarations.
If the parser output file is named `NAME.c' then this file is
named `NAME.h'.
This output file is essential if you wish to put the definition of
`yylex' in a separate source file, because `yylex' needs to be
able to refer to token type codes and the variable `yylval'.
*Note Semantic Values of Tokens: Token Values.
Pretend that `%verbose' was specified, i.e., write an extra output
file containing macro definitions for the token type names defined
in the grammar and the semantic value type `YYSTYPE', as well as a
few `extern' variable declarations. *Note Decl Summary::.
`-b FILE-PREFIX'
`--file-prefix=PREFIX'
@@ -872,19 +904,9 @@ Adjust the output:
`-v'
`--verbose'
Write an extra output file containing verbose descriptions of the
parser states and what is done for each type of look-ahead token in
that state.
This file also describes all the conflicts, both those resolved by
operator precedence and the unresolved ones.
The file's name is made by removing `.tab.c' or `.c' from the
parser output file name, and adding `.output' instead.
Therefore, if the input file is `foo.y', then the parser file is
called `foo.tab.c' by default. As a consequence, the verbose
output file is called `foo.output'.
Pretend that `%verbose' was specified, i.e, write an extra output
file containing verbose descriptions of the grammar and parser.
*Note Decl Summary::, for more.
`-o OUTFILE'
`--output-file=OUTFILE'
@@ -1093,6 +1115,13 @@ Bison Symbols
The parser function produced by Bison; call this function to start
parsing. *Note The Parser Function `yyparse': Parser Function.
`%debug'
Equip the parser for debugging. *Note Decl Summary::.
`%defines'
Bison declaration to create a header file meant for the scanner.
*Note Decl Summary::.
`%left'
Bison declaration to assign left associativity to token(s). *Note
Operator Precedence: Precedence Decl.
@@ -1169,169 +1198,3 @@ Bison Symbols
Separates alternate rules for the same result nonterminal. *Note
Syntax of Grammar Rules: Rules.

File: bison.info, Node: Glossary, Next: Index, Prev: Table of Symbols, Up: Top
Glossary
********
Backus-Naur Form (BNF)
Formal method of specifying context-free grammars. BNF was first
used in the `ALGOL-60' report, 1963. *Note Languages and
Context-Free Grammars: Language and Grammar.
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 _anywhere_ an
expression is permitted. *Note Languages and Context-Free
Grammars: Language and Grammar.
Dynamic allocation
Allocation of memory that occurs during execution, rather than at
compile time or on entry to a function.
Empty string
Analogous to the empty set in set theory, the empty string is a
character string of length zero.
Finite-state stack machine
A "machine" that has discrete states in which it is said to exist
at each instant in time. As input to the machine is processed, the
machine moves from state to state as specified by the logic of the
machine. In the case of the parser, the input is the language
being parsed, and the states correspond to various stages in the
grammar rules. *Note The Bison Parser Algorithm: Algorithm.
Grouping
A language construct that is (in general) grammatically divisible;
for example, `expression' or `declaration' in C. *Note Languages
and Context-Free Grammars: Language and Grammar.
Infix operator
An arithmetic operator that is placed between the operands on
which it performs some operation.
Input stream
A continuous flow of data between devices or programs.
Language construct
One of the typical usage schemas of the language. For example,
one of the constructs of the C language is the `if' statement.
*Note Languages and Context-Free Grammars: Language and Grammar.
Left associativity
Operators having left associativity are analyzed from left to
right: `a+b+c' first computes `a+b' and then combines with `c'.
*Note Operator Precedence: Precedence.
Left recursion
A rule whose result symbol is also its first component symbol; for
example, `expseq1 : expseq1 ',' exp;'. *Note Recursive Rules:
Recursion.
Left-to-right parsing
Parsing a sentence of a language by analyzing it token by token
from left to right. *Note The Bison Parser Algorithm: Algorithm.
Lexical analyzer (scanner)
A function that reads an input stream and returns tokens one by
one. *Note The Lexical Analyzer Function `yylex': Lexical.
Lexical tie-in
A flag, set by actions in the grammar rules, which alters the way
tokens are parsed. *Note Lexical Tie-ins::.
Literal string token
A token which consists of two or more fixed characters. *Note
Symbols::.
Look-ahead token
A token already read but not yet shifted. *Note Look-Ahead
Tokens: Look-Ahead.
LALR(1)
The class of context-free grammars that Bison (like most other
parser generators) can handle; a subset of LR(1). *Note
Mysterious Reduce/Reduce Conflicts: Mystery Conflicts.
LR(1)
The class of context-free grammars in which at most one token of
look-ahead is needed to disambiguate the parsing of any piece of
input.
Nonterminal symbol
A grammar symbol standing for a grammatical construct that can be
expressed through rules in terms of smaller constructs; in other
words, a construct that is not a token. *Note Symbols::.
Parse error
An error encountered during parsing of an input stream due to
invalid syntax. *Note Error Recovery::.
Parser
A function that recognizes valid sentences of a language by
analyzing the syntax structure of a set of tokens passed to it
from a lexical analyzer.
Postfix operator
An arithmetic operator that is placed after the operands upon
which it performs some operation.
Reduction
Replacing a string of nonterminals and/or terminals with a single
nonterminal, according to a grammar rule. *Note The Bison Parser
Algorithm: Algorithm.
Reentrant
A reentrant subprogram is a subprogram which can be in invoked any
number of times in parallel, without interference between the
various invocations. *Note A Pure (Reentrant) Parser: Pure Decl.
Reverse polish notation
A language in which all operators are postfix operators.
Right recursion
A rule whose result symbol is also its last component symbol; for
example, `expseq1: exp ',' expseq1;'. *Note Recursive Rules:
Recursion.
Semantics
In computer languages, the semantics are specified by the actions
taken for each instance of the language, i.e., the meaning of each
statement. *Note Defining Language Semantics: Semantics.
Shift
A parser is said to shift when it makes the choice of analyzing
further input from the stream rather than reducing immediately some
already-recognized rule. *Note The Bison Parser Algorithm:
Algorithm.
Single-character literal
A single character that is recognized and interpreted as is.
*Note From Formal Rules to Bison Input: Grammar in Bison.
Start symbol
The nonterminal symbol that stands for a complete valid utterance
in the language being parsed. The start symbol is usually listed
as the first nonterminal symbol in a language specification.
*Note The Start-Symbol: Start Decl.
Symbol table
A data structure where symbol names and associated data are stored
during parsing to allow for recognition and use of existing
information in repeated uses of a symbol. *Note Multi-function
Calc::.
Token
A basic, grammatically indivisible unit of a language. The symbol
that describes a token in the grammar is a terminal symbol. The
input of the Bison parser is a stream of tokens which comes from
the lexical analyzer. *Note Symbols::.
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. *Note Languages and Context-Free Grammars: Language and
Grammar.

View File

@@ -28,6 +28,172 @@ License", "Conditions for Using Bison" and this permission notice may be
included in translations approved by the Free Software Foundation
instead of in the original English.

File: bison.info, Node: Glossary, Next: Index, Prev: Table of Symbols, Up: Top
Glossary
********
Backus-Naur Form (BNF)
Formal method of specifying context-free grammars. BNF was first
used in the `ALGOL-60' report, 1963. *Note Languages and
Context-Free Grammars: Language and Grammar.
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 _anywhere_ an
expression is permitted. *Note Languages and Context-Free
Grammars: Language and Grammar.
Dynamic allocation
Allocation of memory that occurs during execution, rather than at
compile time or on entry to a function.
Empty string
Analogous to the empty set in set theory, the empty string is a
character string of length zero.
Finite-state stack machine
A "machine" that has discrete states in which it is said to exist
at each instant in time. As input to the machine is processed, the
machine moves from state to state as specified by the logic of the
machine. In the case of the parser, the input is the language
being parsed, and the states correspond to various stages in the
grammar rules. *Note The Bison Parser Algorithm: Algorithm.
Grouping
A language construct that is (in general) grammatically divisible;
for example, `expression' or `declaration' in C. *Note Languages
and Context-Free Grammars: Language and Grammar.
Infix operator
An arithmetic operator that is placed between the operands on
which it performs some operation.
Input stream
A continuous flow of data between devices or programs.
Language construct
One of the typical usage schemas of the language. For example,
one of the constructs of the C language is the `if' statement.
*Note Languages and Context-Free Grammars: Language and Grammar.
Left associativity
Operators having left associativity are analyzed from left to
right: `a+b+c' first computes `a+b' and then combines with `c'.
*Note Operator Precedence: Precedence.
Left recursion
A rule whose result symbol is also its first component symbol; for
example, `expseq1 : expseq1 ',' exp;'. *Note Recursive Rules:
Recursion.
Left-to-right parsing
Parsing a sentence of a language by analyzing it token by token
from left to right. *Note The Bison Parser Algorithm: Algorithm.
Lexical analyzer (scanner)
A function that reads an input stream and returns tokens one by
one. *Note The Lexical Analyzer Function `yylex': Lexical.
Lexical tie-in
A flag, set by actions in the grammar rules, which alters the way
tokens are parsed. *Note Lexical Tie-ins::.
Literal string token
A token which consists of two or more fixed characters. *Note
Symbols::.
Look-ahead token
A token already read but not yet shifted. *Note Look-Ahead
Tokens: Look-Ahead.
LALR(1)
The class of context-free grammars that Bison (like most other
parser generators) can handle; a subset of LR(1). *Note
Mysterious Reduce/Reduce Conflicts: Mystery Conflicts.
LR(1)
The class of context-free grammars in which at most one token of
look-ahead is needed to disambiguate the parsing of any piece of
input.
Nonterminal symbol
A grammar symbol standing for a grammatical construct that can be
expressed through rules in terms of smaller constructs; in other
words, a construct that is not a token. *Note Symbols::.
Parse error
An error encountered during parsing of an input stream due to
invalid syntax. *Note Error Recovery::.
Parser
A function that recognizes valid sentences of a language by
analyzing the syntax structure of a set of tokens passed to it
from a lexical analyzer.
Postfix operator
An arithmetic operator that is placed after the operands upon
which it performs some operation.
Reduction
Replacing a string of nonterminals and/or terminals with a single
nonterminal, according to a grammar rule. *Note The Bison Parser
Algorithm: Algorithm.
Reentrant
A reentrant subprogram is a subprogram which can be in invoked any
number of times in parallel, without interference between the
various invocations. *Note A Pure (Reentrant) Parser: Pure Decl.
Reverse polish notation
A language in which all operators are postfix operators.
Right recursion
A rule whose result symbol is also its last component symbol; for
example, `expseq1: exp ',' expseq1;'. *Note Recursive Rules:
Recursion.
Semantics
In computer languages, the semantics are specified by the actions
taken for each instance of the language, i.e., the meaning of each
statement. *Note Defining Language Semantics: Semantics.
Shift
A parser is said to shift when it makes the choice of analyzing
further input from the stream rather than reducing immediately some
already-recognized rule. *Note The Bison Parser Algorithm:
Algorithm.
Single-character literal
A single character that is recognized and interpreted as is.
*Note From Formal Rules to Bison Input: Grammar in Bison.
Start symbol
The nonterminal symbol that stands for a complete valid utterance
in the language being parsed. The start symbol is usually listed
as the first nonterminal symbol in a language specification.
*Note The Start-Symbol: Start Decl.
Symbol table
A data structure where symbol names and associated data are stored
during parsing to allow for recognition and use of existing
information in repeated uses of a symbol. *Note Multi-function
Calc::.
Token
A basic, grammatically indivisible unit of a language. The symbol
that describes a token in the grammar is a terminal symbol. The
input of the Bison parser is a stream of tokens which comes from
the lexical analyzer. *Note Symbols::.
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. *Note Languages and Context-Free Grammars: Language and
Grammar.

File: bison.info, Node: Index, Prev: Glossary, Up: Top

View File

@@ -3189,6 +3189,11 @@ Start-Symbol}).
Declare the expected number of shift-reduce conflicts
(@pxref{Expect Decl, ,Suppressing Conflict Warnings}).
@item %yacc
@itemx %fixed_output_files
Pretend the option @option{--yacc} was given, i.e., imitate Yacc,
including its naming conventions. @xref{Bison Options}, for more.
@item %locations
Generate the code processing the locations (@pxref{Action Features,
,Special Features for Use in Actions}). This mode is enabled as soon as
@@ -3200,6 +3205,15 @@ accurate parse error messages.
Request a pure (reentrant) parser program (@pxref{Pure Decl, ,A Pure
(Reentrant) Parser}).
@item %no_parser
Do not include any C code in the parser file; generate tables only. The
parser file contains just @code{#define} directives and static variable
declarations.
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
brace-surrounded body fit for a @code{switch} statement.
@item %no_lines
Don't generate any @code{#line} preprocessor commands in the parser
file. Ordinarily Bison writes these commands in the parser file so that
@@ -3208,6 +3222,39 @@ your source file (the grammar file). This directive causes them to
associate errors with the parser file, treating it an independent source
file in its own right.
@item %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 %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 %verbose
Write an extra output file containing verbose descriptions of the
parser states and what is done for each type of look-ahead token in
that state.
This file also describes all the conflicts, both those resolved by
operator precedence and the unresolved ones.
The file's name is made by removing @samp{.tab.c} or @samp{.c} from
the parser output file name, and adding @samp{.output} instead.@refill
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
output file is called @file{foo.output}.@refill
@item %raw
The output file @file{@var{name}.h} normally defines the tokens with
Yacc-compatible token numbers. If this option is specified, the
@@ -4939,8 +4986,9 @@ 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}.
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}.
@@ -4967,13 +5015,7 @@ parser file, treating it as an independent source file in its own right.
@item -n
@itemx --no-parser
Do not include any C code in the parser file; generate tables only. The
parser file contains just @code{#define} directives and static variable
declarations.
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
brace-surrounded body fit for a @code{switch} statement.
Pretend that @code{%no_parser} was specified. @xref{Decl Summary}.
@item -r
@itemx --raw
@@ -4990,17 +5032,10 @@ 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
Pretend that @code{%verbose} was specified, i.e., 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{Decl Summary}.
@item -b @var{file-prefix}
@itemx --file-prefix=@var{prefix}
@@ -5009,19 +5044,9 @@ chosen as if the input file were named @file{@var{prefix}.c}.
@item -v
@itemx --verbose
Write an extra output file containing verbose descriptions of the
parser states and what is done for each type of look-ahead token in
that state.
This file also describes all the conflicts, both those resolved by
operator precedence and the unresolved ones.
The file's name is made by removing @samp{.tab.c} or @samp{.c} from
the parser output file name, and adding @samp{.output} instead.@refill
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
output file is called @file{foo.output}.@refill
Pretend that @code{%verbose} was specified, i.e, write an extra output
file containing verbose descriptions of the grammar and
parser. @xref{Decl Summary}, for more.
@item -o @var{outfile}
@itemx --output-file=@var{outfile}
@@ -5255,6 +5280,13 @@ Global variable which Bison increments each time there is a parse error.
The parser function produced by Bison; call this function to start
parsing. @xref{Parser Function, ,The Parser Function @code{yyparse}}.
@item %debug
Equip the parser for debugging. @xref{Decl Summary}.
@item %defines
Bison declaration to create a header file meant for the scanner.
@xref{Decl Summary}.
@item %left
Bison declaration to assign left associativity to token(s).
@xref{Precedence Decl, ,Operator Precedence}.

View File

@@ -1,3 +1,3 @@
@set UPDATED 15 January 2001
@set UPDATED 18 January 2001
@set EDITION 1.28a
@set VERSION 1.28a

View File

@@ -245,12 +245,8 @@ compute_base_names (void)
void
open_files (void)
{
compute_base_names ();
finput = xfopen (infile, "r");
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
/* Initialize the obstacks. */
obstack_init (&action_obstack);
obstack_init (&attrs_obstack);
@@ -271,6 +267,9 @@ output_files (void)
{
xfclose (finput);
compute_base_names ();
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
/* Output the main file. */
if (spec_outfile)
obstack_save (&table_obstack, spec_outfile);

View File

@@ -538,48 +538,47 @@ struct percent_table_struct
const char *name;
void *set_flag;
int retval;
}
percent_table[] =
};
struct percent_table_struct percent_table[] =
{
{ "token", NULL, TOKEN },
{ "term", NULL, TOKEN },
{ "nterm", NULL, NTERM },
{ "type", NULL, TYPE },
{ "guard", NULL, GUARD },
{ "union", NULL, UNION },
{ "expect", NULL, EXPECT },
{ "thong", NULL, THONG },
{ "start", NULL, START },
{ "left", NULL, LEFT },
{ "right", NULL, RIGHT },
{ "nonassoc", NULL, NONASSOC },
{ "binary", NULL, NONASSOC },
{ "semantic_parser", NULL, SEMANTIC_PARSER },
{ "pure_parser", NULL, PURE_PARSER },
{ "prec", NULL, PREC },
{ "locations", &locations_flag, NOOP}, /* -l */
{ "no_lines", &no_lines_flag, NOOP}, /* -l */
{ "raw", &raw_flag, NOOP }, /* -r */
{ "token_table", &token_table_flag, NOOP}, /* -k */
{ "token", NULL, TOKEN },
{ "term", NULL, TOKEN },
{ "nterm", NULL, NTERM },
{ "type", NULL, TYPE },
{ "guard", NULL, GUARD },
{ "union", NULL, UNION },
{ "expect", NULL, EXPECT },
{ "thong", NULL, THONG },
{ "start", NULL, START },
{ "left", NULL, LEFT },
{ "right", NULL, RIGHT },
{ "nonassoc", NULL, NONASSOC },
{ "binary", NULL, NONASSOC },
{ "prec", NULL, PREC },
{ "locations", &locations_flag, NOOP }, /* -l */
{ "no_lines", &no_lines_flag, NOOP }, /* -l */
{ "raw", &raw_flag, NOOP }, /* -r */
{ "token_table", &token_table_flag, NOOP }, /* -k */
{ "yacc", &yacc_flag, NOOP }, /* -y */
{ "fixed_output_files",&yacc_flag, NOOP }, /* -y */
{ "defines", &defines_flag, NOOP }, /* -d */
{ "no_parser", &no_parser_flag, NOOP }, /* -n */
#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", &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", &verbose_flag, NOOP}, /* -v */
{ "debug", &debug_flag, NOOP}, /* -t */
/* For the time being, this is not enabled yet, while it's possible
though, since we use obstacks. The only risk is with semantic
parsers which will output an `include' of an output file: be sure
that the naem included is indeed the name of the output file. */
{ "output_file", &spec_outfile, SETOPT }, /* -o */
{ "file_prefix", &spec_file_prefix, SETOPT }, /* -b */
{ "name_prefix", &spec_name_prefix, SETOPT }, /* -p */
#endif
{ "verbose", &verbose_flag, NOOP }, /* -v */
{ "debug", &debug_flag, NOOP }, /* -t */
{ "semantic_parser", &semantic_parser, NOOP },
{ "pure_parser", &pure_parser, NOOP },
/* {"help", <print usage stmt>, NOOP}, *//* -h */
/* {"version", <print version number> , NOOP}, *//* -V */
#endif
{ NULL, NULL, ILLEGAL}
};
@@ -646,6 +645,7 @@ parse_percent_token (void)
for (tx = percent_table; tx->name; tx++)
if (strcmp (token_buffer + 1, tx->name) == 0)
break;
if (tx->retval == SETOPT)
{
*((char **) (tx->set_flag)) = optarg;

View File

@@ -41,8 +41,6 @@
# define RIGHT 16
# define NONASSOC 17
# define PREC 18
# define SEMANTIC_PARSER 19
# define PURE_PARSER 20
# define TYPENAME 21
# define NUMBER 22
# define EXPECT 23

View File

@@ -223,10 +223,18 @@ register YYLTYPE *yylsp;\n\
void
output_headers (void)
{
char *attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile);
char *attrsfile_quoted = 0;
if (semantic_parser)
obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted);
{
/* FIXME: This is *buggy*. ATTRSFILE is not computed yet, since
we are waiting for the full input file to have been read to
be sure of the output file name. So basically, here, a SEGV
is guaranteed. OTOH, currently semantic parsers are not
supported. */
attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile);
obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted);
}
if (no_parser_flag)
return;

View File

@@ -931,6 +931,7 @@ read_declarations (void)
case EXPECT:
parse_expect_decl ();
break;
case THONG:
parse_thong_decl ();
break;
@@ -947,14 +948,6 @@ read_declarations (void)
parse_assoc_decl (non_assoc);
break;
case SEMANTIC_PARSER:
semantic_parser = 1;
break;
case PURE_PARSER:
pure_parser = 1;
break;
case NOOP:
break;

View File

@@ -9,29 +9,53 @@ AT_INIT([bison])
## Checking output file names. ##
## ---------------------------- ##
AT_SETUP([Checking output file names.])
# AT_CHECK_BISON_FLAGS(FLAGS, EXPECTED-FILES-SORTED)
# --------------------------------------------------
AT_DEFINE([AT_CHECK_BISON_FLAGS],
[AT_SETUP([Output files: $1.])
AT_DATA([foo.y],
[[%%
foo: {}
]])
# AT_CHECK_BISON_OUTPUT(FLAGS, EXPECTED-FILES-SORTED)
# ---------------------------------------------------
AT_DEFINE([AT_CHECK_BISON_OUTPUT],
[rm -rf $2
rm -rf $2
AT_CHECK([bison -dv foo.y $1], 0, ignore, ignore)
AT_CHECK([ls $2 | sort | tr '\n' ' ' | sed 's/.$//g'], 0, [$2])
rm -f $2])
AT_CHECK_BISON_OUTPUT([], [foo.output foo.tab.c foo.tab.h])
AT_CHECK_BISON_OUTPUT([-o foo.c], [foo.c foo.h foo.output])
AT_CHECK_BISON_OUTPUT([-o foo.tab.c], [foo.output foo.tab.c foo.tab.h])
AT_CHECK_BISON_OUTPUT([-y], [y.output y.tab.c y.tab.h])
AT_CHECK_BISON_OUTPUT([-b bar], [bar.output bar.tab.c bar.tab.h])
rm -f $2
AT_CLEANUP
])
AT_CHECK_BISON_FLAGS([], [foo.output foo.tab.c foo.tab.h])
AT_CHECK_BISON_FLAGS([-o foo.c], [foo.c foo.h foo.output])
AT_CHECK_BISON_FLAGS([-o foo.tab.c], [foo.output foo.tab.c foo.tab.h])
AT_CHECK_BISON_FLAGS([-y], [y.output y.tab.c y.tab.h])
AT_CHECK_BISON_FLAGS([-b bar], [bar.output bar.tab.c bar.tab.h])
# AT_CHECK_BISON_PERCENT(GRAMMAR-OPTIONS, EXPECTED-FILES-SORTED)
# --------------------------------------------------------------
AT_DEFINE([AT_CHECK_BISON_PERCENT],
[AT_SETUP([Output files: $1.])
AT_DATA([foo.y],
[[$1
%defines
%verbose
%%
foo: {}
]])
rm -rf $2
AT_CHECK([bison foo.y], 0, ignore, ignore)
AT_CHECK([ls $2 | sort | tr '\n' ' ' | sed 's/.$//g'], 0, [$2])
rm -f $2
AT_CLEANUP
])
# The sames, but using the % directives.
AT_CHECK_BISON_PERCENT([], [foo.output foo.tab.c foo.tab.h])
# AT_CHECK_BISON_PERCENT([%output foo.c], [foo.c foo.h foo.output])
# AT_CHECK_BISON_PERCENT([%output foo.tab.c], [foo.output foo.tab.c foo.tab.h])
AT_CHECK_BISON_PERCENT([%yacc], [y.output y.tab.c y.tab.h])
# AT_CHECK_BISON_PERCENT([%file_prefix bar], [bar.output bar.tab.c bar.tab.h])
AT_INCLUDE([calc.at])
AT_INCLUDE([regression.at])