+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.
* Added the old Bison reference card.
* Added `--locations' and `%locations'.
+
+* New directives.
+ `%yacc', `%fixed_output_files', `%defines', `%no_parser', `%verbose', and
+ `%debug'.
\f
Changes in version 1.28:
Changes in version 1.20:
Output file does not redefine const for C++.
-
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
\1f
Tag Table:
(Indirect)
Node: Start Decl\7f111827
Node: Pure Decl\7f112205
Node: Decl Summary\7f113882
-Node: Multiple Parsers\7f117718
-Node: Interface\7f119212
-Node: Parser Function\7f120084
-Node: Lexical\7f120919
-Node: Calling Convention\7f122325
-Node: Token Values\7f125096
-Node: Token Positions\7f126245
-Node: Pure Calling\7f127137
-Node: Error Reporting\7f130069
-Node: Action Features\7f132191
-Node: Algorithm\7f135852
-Node: Look-Ahead\7f138145
-Node: Shift/Reduce\7f140277
-Node: Precedence\7f143189
-Node: Why Precedence\7f143840
-Node: Using Precedence\7f145705
-Node: Precedence Examples\7f146673
-Node: How Precedence\7f147374
-Node: Contextual Precedence\7f148523
-Node: Parser States\7f150314
-Node: Reduce/Reduce\7f151557
-Node: Mystery Conflicts\7f155118
-Node: Stack Overflow\7f158504
-Node: Error Recovery\7f159877
-Node: Context Dependency\7f165013
-Node: Semantic Tokens\7f165861
-Node: Lexical Tie-ins\7f168878
-Node: Tie-in Recovery\7f170426
-Node: Debugging\7f172598
-Node: Invocation\7f175899
-Node: Bison Options\7f176629
-Node: Environment Variables\7f180983
-Node: Option Cross Key\7f181831
-Node: VMS Invocation\7f182721
-Node: Table of Symbols\7f183505
-Node: Glossary\7f190902
-Node: Index\7f197192
+Node: Multiple Parsers\7f119609
+Node: Interface\7f121103
+Node: Parser Function\7f121975
+Node: Lexical\7f122810
+Node: Calling Convention\7f124216
+Node: Token Values\7f126987
+Node: Token Positions\7f128136
+Node: Pure Calling\7f129028
+Node: Error Reporting\7f131960
+Node: Action Features\7f134082
+Node: Algorithm\7f137743
+Node: Look-Ahead\7f140036
+Node: Shift/Reduce\7f142168
+Node: Precedence\7f145080
+Node: Why Precedence\7f145731
+Node: Using Precedence\7f147596
+Node: Precedence Examples\7f148564
+Node: How Precedence\7f149265
+Node: Contextual Precedence\7f150414
+Node: Parser States\7f152205
+Node: Reduce/Reduce\7f153448
+Node: Mystery Conflicts\7f157009
+Node: Stack Overflow\7f160395
+Node: Error Recovery\7f161768
+Node: Context Dependency\7f166904
+Node: Semantic Tokens\7f167752
+Node: Lexical Tie-ins\7f170769
+Node: Tie-in Recovery\7f172317
+Node: Debugging\7f174489
+Node: Invocation\7f177790
+Node: Bison Options\7f178520
+Node: Environment Variables\7f181893
+Node: Option Cross Key\7f182741
+Node: VMS Invocation\7f183631
+Node: Table of Symbols\7f184415
+Node: Glossary\7f191991
+Node: Index\7f198281
\1f
End Tag Table
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
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
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
to shift or reduce when the stack contains `1 - 2' and the look-ahead
token is `-': shifting makes right-associativity.
-\1f
-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.
-
-\1f
-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.)
-
included in translations approved by the Free Software Foundation
instead of in the original English.
+\1f
+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.
+
+\1f
+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.)
+
\1f
File: bison.info, Node: How Precedence, Prev: Precedence Examples, Up: Precedence
`-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::.
`-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'
`-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'
`-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'
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.
Separates alternate rules for the same result nonterminal. *Note
Syntax of Grammar Rules: Rules.
-\1f
-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.
-
included in translations approved by the Free Software Foundation
instead of in the original English.
+\1f
+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.
+
\1f
File: bison.info, Node: Index, Prev: Glossary, Up: Top
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
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
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
@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}.
@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
@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}
@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}
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}.
-@set UPDATED 15 January 2001
+@set UPDATED 18 January 2001
@set EDITION 1.28a
@set VERSION 1.28a
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);
{
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);
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}
};
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;
# 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
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;
case EXPECT:
parse_expect_decl ();
break;
+
case THONG:
parse_thong_decl ();
break;
parse_assoc_decl (non_assoc);
break;
- case SEMANTIC_PARSER:
- semantic_parser = 1;
- break;
-
- case PURE_PARSER:
- pure_parser = 1;
- break;
-
case NOOP:
break;
## 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])
+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_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])
-AT_CLEANUP
+# 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])