bison.info-4 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. This is Info file bison.info, produced by Makeinfo version 1.67 from
  2. the input file ./bison.texinfo.
  3. This file documents the Bison parser generator.
  4. Copyright (C) 1988, 1989, 1990 Free Software Foundation, Inc.
  5. Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8. Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the sections entitled "GNU General Public License" and "Conditions
  11. for Using Bison" are included exactly as in the original, and provided
  12. that the entire resulting derived work is distributed under the terms
  13. of a permission notice identical to this one.
  14. Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the sections entitled "GNU General Public
  17. License", "Conditions for Using Bison" and this permission notice may be
  18. included in translations approved by the Free Software Foundation
  19. instead of in the original English.
  20. 
  21. File: bison.info, Node: Semantic Tokens, Next: Lexical Tie-ins, Prev: Context Dependency, Up: Context Dependency
  22. Semantic Info in Token Types
  23. ============================
  24. The C language has a context dependency: the way an identifier is
  25. used depends on what its current meaning is. For example, consider
  26. this:
  27. foo (x);
  28. This looks like a function call statement, but if `foo' is a typedef
  29. name, then this is actually a declaration of `x'. How can a Bison
  30. parser for C decide how to parse this input?
  31. The method used in GNU C is to have two different token types,
  32. `IDENTIFIER' and `TYPENAME'. When `yylex' finds an identifier, it
  33. looks up the current declaration of the identifier in order to decide
  34. which token type to return: `TYPENAME' if the identifier is declared as
  35. a typedef, `IDENTIFIER' otherwise.
  36. The grammar rules can then express the context dependency by the
  37. choice of token type to recognize. `IDENTIFIER' is accepted as an
  38. expression, but `TYPENAME' is not. `TYPENAME' can start a declaration,
  39. but `IDENTIFIER' cannot. In contexts where the meaning of the
  40. identifier is *not* significant, such as in declarations that can
  41. shadow a typedef name, either `TYPENAME' or `IDENTIFIER' is
  42. accepted--there is one rule for each of the two token types.
  43. This technique is simple to use if the decision of which kinds of
  44. identifiers to allow is made at a place close to where the identifier is
  45. parsed. But in C this is not always so: C allows a declaration to
  46. redeclare a typedef name provided an explicit type has been specified
  47. earlier:
  48. typedef int foo, bar, lose;
  49. static foo (bar); /* redeclare `bar' as static variable */
  50. static int foo (lose); /* redeclare `foo' as function */
  51. Unfortunately, the name being declared is separated from the
  52. declaration construct itself by a complicated syntactic structure--the
  53. "declarator".
  54. As a result, the part of Bison parser for C needs to be duplicated,
  55. with all the nonterminal names changed: once for parsing a declaration
  56. in which a typedef name can be redefined, and once for parsing a
  57. declaration in which that can't be done. Here is a part of the
  58. duplication, with actions omitted for brevity:
  59. initdcl:
  60. declarator maybeasm '='
  61. init
  62. | declarator maybeasm
  63. ;
  64. notype_initdcl:
  65. notype_declarator maybeasm '='
  66. init
  67. | notype_declarator maybeasm
  68. ;
  69. Here `initdcl' can redeclare a typedef name, but `notype_initdcl'
  70. cannot. The distinction between `declarator' and `notype_declarator'
  71. is the same sort of thing.
  72. There is some similarity between this technique and a lexical tie-in
  73. (described next), in that information which alters the lexical analysis
  74. is changed during parsing by other parts of the program. The
  75. difference is here the information is global, and is used for other
  76. purposes in the program. A true lexical tie-in has a special-purpose
  77. flag controlled by the syntactic context.
  78. 
  79. File: bison.info, Node: Lexical Tie-ins, Next: Tie-in Recovery, Prev: Semantic Tokens, Up: Context Dependency
  80. Lexical Tie-ins
  81. ===============
  82. One way to handle context-dependency is the "lexical tie-in": a flag
  83. which is set by Bison actions, whose purpose is to alter the way tokens
  84. are parsed.
  85. For example, suppose we have a language vaguely like C, but with a
  86. special construct `hex (HEX-EXPR)'. After the keyword `hex' comes an
  87. expression in parentheses in which all integers are hexadecimal. In
  88. particular, the token `a1b' must be treated as an integer rather than
  89. as an identifier if it appears in that context. Here is how you can do
  90. it:
  91. %{
  92. int hexflag;
  93. %}
  94. %%
  95. ...
  96. expr: IDENTIFIER
  97. | constant
  98. | HEX '('
  99. { hexflag = 1; }
  100. expr ')'
  101. { hexflag = 0;
  102. $$ = $4; }
  103. | expr '+' expr
  104. { $$ = make_sum ($1, $3); }
  105. ...
  106. ;
  107. constant:
  108. INTEGER
  109. | STRING
  110. ;
  111. Here we assume that `yylex' looks at the value of `hexflag'; when it is
  112. nonzero, all integers are parsed in hexadecimal, and tokens starting
  113. with letters are parsed as integers if possible.
  114. The declaration of `hexflag' shown in the C declarations section of
  115. the parser file is needed to make it accessible to the actions (*note C
  116. Declarations::.). You must also write the code in `yylex' to obey the
  117. flag.
  118. 
  119. File: bison.info, Node: Tie-in Recovery, Prev: Lexical Tie-ins, Up: Context Dependency
  120. Lexical Tie-ins and Error Recovery
  121. ==================================
  122. Lexical tie-ins make strict demands on any error recovery rules you
  123. have. *Note Error Recovery::.
  124. The reason for this is that the purpose of an error recovery rule is
  125. to abort the parsing of one construct and resume in some larger
  126. construct. For example, in C-like languages, a typical error recovery
  127. rule is to skip tokens until the next semicolon, and then start a new
  128. statement, like this:
  129. stmt: expr ';'
  130. | IF '(' expr ')' stmt { ... }
  131. ...
  132. error ';'
  133. { hexflag = 0; }
  134. ;
  135. If there is a syntax error in the middle of a `hex (EXPR)'
  136. construct, this error rule will apply, and then the action for the
  137. completed `hex (EXPR)' will never run. So `hexflag' would remain set
  138. for the entire rest of the input, or until the next `hex' keyword,
  139. causing identifiers to be misinterpreted as integers.
  140. To avoid this problem the error recovery rule itself clears
  141. `hexflag'.
  142. There may also be an error recovery rule that works within
  143. expressions. For example, there could be a rule which applies within
  144. parentheses and skips to the close-parenthesis:
  145. expr: ...
  146. | '(' expr ')'
  147. { $$ = $2; }
  148. | '(' error ')'
  149. ...
  150. If this rule acts within the `hex' construct, it is not going to
  151. abort that construct (since it applies to an inner level of parentheses
  152. within the construct). Therefore, it should not clear the flag: the
  153. rest of the `hex' construct should be parsed with the flag still in
  154. effect.
  155. What if there is an error recovery rule which might abort out of the
  156. `hex' construct or might not, depending on circumstances? There is no
  157. way you can write the action to determine whether a `hex' construct is
  158. being aborted or not. So if you are using a lexical tie-in, you had
  159. better make sure your error recovery rules are not of this kind. Each
  160. rule must be such that you can be sure that it always will, or always
  161. won't, have to clear the flag.
  162. 
  163. File: bison.info, Node: Debugging, Next: Invocation, Prev: Context Dependency, Up: Top
  164. Debugging Your Parser
  165. *********************
  166. If a Bison grammar compiles properly but doesn't do what you want
  167. when it runs, the `yydebug' parser-trace feature can help you figure
  168. out why.
  169. To enable compilation of trace facilities, you must define the macro
  170. `YYDEBUG' when you compile the parser. You could use `-DYYDEBUG=1' as
  171. a compiler option or you could put `#define YYDEBUG 1' in the C
  172. declarations section of the grammar file (*note C Declarations::.).
  173. Alternatively, use the `-t' option when you run Bison (*note
  174. Invocation::.). We always define `YYDEBUG' so that debugging is always
  175. possible.
  176. The trace facility uses `stderr', so you must add
  177. `#include <stdio.h>' to the C declarations section unless it is already
  178. there.
  179. Once you have compiled the program with trace facilities, the way to
  180. request a trace is to store a nonzero value in the variable `yydebug'.
  181. You can do this by making the C code do it (in `main', perhaps), or you
  182. can alter the value with a C debugger.
  183. Each step taken by the parser when `yydebug' is nonzero produces a
  184. line or two of trace information, written on `stderr'. The trace
  185. messages tell you these things:
  186. * Each time the parser calls `yylex', what kind of token was read.
  187. * Each time a token is shifted, the depth and complete contents of
  188. the state stack (*note Parser States::.).
  189. * Each time a rule is reduced, which rule it is, and the complete
  190. contents of the state stack afterward.
  191. To make sense of this information, it helps to refer to the listing
  192. file produced by the Bison `-v' option (*note Invocation::.). This file
  193. shows the meaning of each state in terms of positions in various rules,
  194. and also what each state will do with each possible input token. As
  195. you read the successive trace messages, you can see that the parser is
  196. functioning according to its specification in the listing file.
  197. Eventually you will arrive at the place where something undesirable
  198. happens, and you will see which parts of the grammar are to blame.
  199. The parser file is a C program and you can use C debuggers on it,
  200. but it's not easy to interpret what it is doing. The parser function
  201. is a finite-state machine interpreter, and aside from the actions it
  202. executes the same code over and over. Only the values of variables
  203. show where in the grammar it is working.
  204. The debugging information normally gives the token type of each token
  205. read, but not its semantic value. You can optionally define a macro
  206. named `YYPRINT' to provide a way to print the value. If you define
  207. `YYPRINT', it should take three arguments. The parser will pass a
  208. standard I/O stream, the numeric code for the token type, and the token
  209. value (from `yylval').
  210. Here is an example of `YYPRINT' suitable for the multi-function
  211. calculator (*note Mfcalc Decl::.):
  212. #define YYPRINT(file, type, value) yyprint (file, type, value)
  213. static void
  214. yyprint (file, type, value)
  215. FILE *file;
  216. int type;
  217. YYSTYPE value;
  218. {
  219. if (type == VAR)
  220. fprintf (file, " %s", value.tptr->name);
  221. else if (type == NUM)
  222. fprintf (file, " %d", value.val);
  223. }
  224. 
  225. File: bison.info, Node: Invocation, Next: Table of Symbols, Prev: Debugging, Up: Top
  226. Invoking Bison
  227. **************
  228. The usual way to invoke Bison is as follows:
  229. bison INFILE
  230. Here INFILE is the grammar file name, which usually ends in `.y'.
  231. The parser file's name is made by replacing the `.y' with `.tab.c'.
  232. Thus, the `bison foo.y' filename yields `foo.tab.c', and the `bison
  233. hack/foo.y' filename yields `hack/foo.tab.c'.
  234. * Menu:
  235. * Bison Options:: All the options described in detail,
  236. in alphabetical order by short options.
  237. * Option Cross Key:: Alphabetical list of long options.
  238. * VMS Invocation:: Bison command syntax on VMS.
  239. 
  240. File: bison.info, Node: Bison Options, Next: Option Cross Key, Up: Invocation
  241. Bison Options
  242. =============
  243. Bison supports both traditional single-letter options and mnemonic
  244. long option names. Long option names are indicated with `--' instead of
  245. `-'. Abbreviations for option names are allowed as long as they are
  246. unique. When a long option takes an argument, like `--file-prefix',
  247. connect the option name and the argument with `='.
  248. Here is a list of options that can be used with Bison, alphabetized
  249. by short option. It is followed by a cross key alphabetized by long
  250. option.
  251. `-b FILE-PREFIX'
  252. `--file-prefix=PREFIX'
  253. Specify a prefix to use for all Bison output file names. The
  254. names are chosen as if the input file were named `PREFIX.c'.
  255. `-d'
  256. `--defines'
  257. Write an extra output file containing macro definitions for the
  258. token type names defined in the grammar and the semantic value type
  259. `YYSTYPE', as well as a few `extern' variable declarations.
  260. If the parser output file is named `NAME.c' then this file is
  261. named `NAME.h'.
  262. This output file is essential if you wish to put the definition of
  263. `yylex' in a separate source file, because `yylex' needs to be
  264. able to refer to token type codes and the variable `yylval'.
  265. *Note Token Values::.
  266. `-l'
  267. `--no-lines'
  268. Don't put any `#line' preprocessor commands in the parser file.
  269. Ordinarily Bison puts them in the parser file so that the C
  270. compiler and debuggers will associate errors with your source
  271. file, the grammar file. This option causes them to associate
  272. errors with the parser file, treating it an independent source
  273. file in its own right.
  274. `-o OUTFILE'
  275. `--output-file=OUTFILE'
  276. Specify the name OUTFILE for the parser file.
  277. The other output files' names are constructed from OUTFILE as
  278. described under the `-v' and `-d' switches.
  279. `-p PREFIX'
  280. `--name-prefix=PREFIX'
  281. Rename the external symbols used in the parser so that they start
  282. with PREFIX instead of `yy'. The precise list of symbols renamed
  283. is `yyparse', `yylex', `yyerror', `yylval', `yychar' and `yydebug'.
  284. For example, if you use `-p c', the names become `cparse', `clex',
  285. and so on.
  286. *Note Multiple Parsers::.
  287. `-t'
  288. `--debug'
  289. Output a definition of the macro `YYDEBUG' into the parser file,
  290. so that the debugging facilities are compiled. *Note Debugging::.
  291. `-v'
  292. `--verbose'
  293. Write an extra output file containing verbose descriptions of the
  294. parser states and what is done for each type of look-ahead token in
  295. that state.
  296. This file also describes all the conflicts, both those resolved by
  297. operator precedence and the unresolved ones.
  298. The file's name is made by removing `.tab.c' or `.c' from the
  299. parser output file name, and adding `.output' instead.
  300. Therefore, if the input file is `foo.y', then the parser file is
  301. called `foo.tab.c' by default. As a consequence, the verbose
  302. output file is called `foo.output'.
  303. `-V'
  304. `--version'
  305. Print the version number of Bison.
  306. `-y'
  307. `--yacc'
  308. `--fixed-output-files'
  309. Equivalent to `-o y.tab.c'; the parser output file is called
  310. `y.tab.c', and the other outputs are called `y.output' and
  311. `y.tab.h'. The purpose of this switch is to imitate Yacc's output
  312. file name conventions. Thus, the following shell script can
  313. substitute for Yacc:
  314. bison -y $*
  315. 
  316. File: bison.info, Node: Option Cross Key, Next: VMS Invocation, Prev: Bison Options, Up: Invocation
  317. Option Cross Key
  318. ================
  319. Here is a list of options, alphabetized by long option, to help you
  320. find the corresponding short option.
  321. --debug -t
  322. --defines -d
  323. --file-prefix=PREFIX -b FILE-PREFIX
  324. --fixed-output-files --yacc -y
  325. --name-prefix -p
  326. --no-lines -l
  327. --output-file=OUTFILE -o OUTFILE
  328. --verbose -v
  329. --version -V
  330. 
  331. File: bison.info, Node: VMS Invocation, Prev: Option Cross Key, Up: Invocation
  332. Invoking Bison under VMS
  333. ========================
  334. The command line syntax for Bison on VMS is a variant of the usual
  335. Bison command syntax--adapted to fit VMS conventions.
  336. To find the VMS equivalent for any Bison option, start with the long
  337. option, and substitute a `/' for the leading `--', and substitute a `_'
  338. for each `-' in the name of the long option. For example, the
  339. following invocation under VMS:
  340. bison /debug/name_prefix=bar foo.y
  341. is equivalent to the following command under POSIX.
  342. bison --debug --name-prefix=bar foo.y
  343. The VMS filesystem does not permit filenames such as `foo.tab.c'.
  344. In the above example, the output file would instead be named
  345. `foo_tab.c'.
  346. 
  347. File: bison.info, Node: Table of Symbols, Next: Glossary, Prev: Invocation, Up: Top
  348. Bison Symbols
  349. *************
  350. `error'
  351. A token name reserved for error recovery. This token may be used
  352. in grammar rules so as to allow the Bison parser to recognize an
  353. error in the grammar without halting the process. In effect, a
  354. sentence containing an error may be recognized as valid. On a
  355. parse error, the token `error' becomes the current look-ahead
  356. token. Actions corresponding to `error' are then executed, and
  357. the look-ahead token is reset to the token that originally caused
  358. the violation. *Note Error Recovery::.
  359. `YYABORT'
  360. Macro to pretend that an unrecoverable syntax error has occurred,
  361. by making `yyparse' return 1 immediately. The error reporting
  362. function `yyerror' is not called. *Note Parser Function::.
  363. `YYACCEPT'
  364. Macro to pretend that a complete utterance of the language has been
  365. read, by making `yyparse' return 0 immediately. *Note Parser
  366. Function::.
  367. `YYBACKUP'
  368. Macro to discard a value from the parser stack and fake a
  369. look-ahead token. *Note Action Features::.
  370. `YYERROR'
  371. Macro to pretend that a syntax error has just been detected: call
  372. `yyerror' and then perform normal error recovery if possible
  373. (*note Error Recovery::.), or (if recovery is impossible) make
  374. `yyparse' return 1. *Note Error Recovery::.
  375. `YYINITDEPTH'
  376. Macro for specifying the initial size of the parser stack. *Note
  377. Stack Overflow::.
  378. `YYLTYPE'
  379. Macro for the data type of `yylloc'; a structure with four
  380. members. *Note Token Positions::.
  381. `YYMAXDEPTH'
  382. Macro for specifying the maximum size of the parser stack. *Note
  383. Stack Overflow::.
  384. `YYRECOVERING'
  385. Macro whose value indicates whether the parser is recovering from a
  386. syntax error. *Note Action Features::.
  387. `YYSTYPE'
  388. Macro for the data type of semantic values; `int' by default.
  389. *Note Value Type::.
  390. `yychar'
  391. External integer variable that contains the integer value of the
  392. current look-ahead token. (In a pure parser, it is a local
  393. variable within `yyparse'.) Error-recovery rule actions may
  394. examine this variable. *Note Action Features::.
  395. `yyclearin'
  396. Macro used in error-recovery rule actions. It clears the previous
  397. look-ahead token. *Note Error Recovery::.
  398. `yydebug'
  399. External integer variable set to zero by default. If `yydebug' is
  400. given a nonzero value, the parser will output information on input
  401. symbols and parser action. *Note Debugging::.
  402. `yyerrok'
  403. Macro to cause parser to recover immediately to its normal mode
  404. after a parse error. *Note Error Recovery::.
  405. `yyerror'
  406. User-supplied function to be called by `yyparse' on error. The
  407. function receives one argument, a pointer to a character string
  408. containing an error message. *Note Error Reporting::.
  409. `yylex'
  410. User-supplied lexical analyzer function, called with no arguments
  411. to get the next token. *Note Lexical::.
  412. `yylval'
  413. External variable in which `yylex' should place the semantic value
  414. associated with a token. (In a pure parser, it is a local
  415. variable within `yyparse', and its address is passed to `yylex'.)
  416. *Note Token Values::.
  417. `yylloc'
  418. External variable in which `yylex' should place the line and
  419. column numbers associated with a token. (In a pure parser, it is a
  420. local variable within `yyparse', and its address is passed to
  421. `yylex'.) You can ignore this variable if you don't use the `@'
  422. feature in the grammar actions. *Note Token Positions::.
  423. `yynerrs'
  424. Global variable which Bison increments each time there is a parse
  425. error. (In a pure parser, it is a local variable within
  426. `yyparse'.) *Note Error Reporting::.
  427. `yyparse'
  428. The parser function produced by Bison; call this function to start
  429. parsing. *Note Parser Function::.
  430. `%left'
  431. Bison declaration to assign left associativity to token(s). *Note
  432. Precedence Decl::.
  433. `%nonassoc'
  434. Bison declaration to assign nonassociativity to token(s). *Note
  435. Precedence Decl::.
  436. `%prec'
  437. Bison declaration to assign a precedence to a specific rule.
  438. *Note Contextual Precedence::.
  439. `%pure_parser'
  440. Bison declaration to request a pure (reentrant) parser. *Note
  441. Pure Decl::.
  442. `%right'
  443. Bison declaration to assign right associativity to token(s).
  444. *Note Precedence Decl::.
  445. `%start'
  446. Bison declaration to specify the start symbol. *Note Start Decl::.
  447. `%token'
  448. Bison declaration to declare token(s) without specifying
  449. precedence. *Note Token Decl::.
  450. `%type'
  451. Bison declaration to declare nonterminals. *Note Type Decl::.
  452. `%union'
  453. Bison declaration to specify several possible data types for
  454. semantic values. *Note Union Decl::.
  455. These are the punctuation and delimiters used in Bison input:
  456. `%%'
  457. Delimiter used to separate the grammar rule section from the Bison
  458. declarations section or the additional C code section. *Note
  459. Grammar Layout::.
  460. `%{ %}'
  461. All code listed between `%{' and `%}' is copied directly to the
  462. output file uninterpreted. Such code forms the "C declarations"
  463. section of the input file. *Note Grammar Outline::.
  464. `/*...*/'
  465. Comment delimiters, as in C.
  466. `:'
  467. Separates a rule's result from its components. *Note Rules::.
  468. `;'
  469. Terminates a rule. *Note Rules::.
  470. `|'
  471. Separates alternate rules for the same result nonterminal. *Note
  472. Rules::.
  473. 
  474. File: bison.info, Node: Glossary, Next: Index, Prev: Table of Symbols, Up: Top
  475. Glossary
  476. ********
  477. Backus-Naur Form (BNF)
  478. Formal method of specifying context-free grammars. BNF was first
  479. used in the `ALGOL-60' report, 1963. *Note Language and Grammar::.
  480. Context-free grammars
  481. Grammars specified as rules that can be applied regardless of
  482. context. Thus, if there is a rule which says that an integer can
  483. be used as an expression, integers are allowed *anywhere* an
  484. expression is permitted. *Note Language and Grammar::.
  485. Dynamic allocation
  486. Allocation of memory that occurs during execution, rather than at
  487. compile time or on entry to a function.
  488. Empty string
  489. Analogous to the empty set in set theory, the empty string is a
  490. character string of length zero.
  491. Finite-state stack machine
  492. A "machine" that has discrete states in which it is said to exist
  493. at each instant in time. As input to the machine is processed, the
  494. machine moves from state to state as specified by the logic of the
  495. machine. In the case of the parser, the input is the language
  496. being parsed, and the states correspond to various stages in the
  497. grammar rules. *Note Algorithm::.
  498. Grouping
  499. A language construct that is (in general) grammatically divisible;
  500. for example, `expression' or `declaration' in C. *Note Language
  501. and Grammar::.
  502. Infix operator
  503. An arithmetic operator that is placed between the operands on
  504. which it performs some operation.
  505. Input stream
  506. A continuous flow of data between devices or programs.
  507. Language construct
  508. One of the typical usage schemas of the language. For example,
  509. one of the constructs of the C language is the `if' statement.
  510. *Note Language and Grammar::.
  511. Left associativity
  512. Operators having left associativity are analyzed from left to
  513. right: `a+b+c' first computes `a+b' and then combines with `c'.
  514. *Note Precedence::.
  515. Left recursion
  516. A rule whose result symbol is also its first component symbol; for
  517. example, `expseq1 : expseq1 ',' exp;'. *Note Recursion::.
  518. Left-to-right parsing
  519. Parsing a sentence of a language by analyzing it token by token
  520. from left to right. *Note Algorithm::.
  521. Lexical analyzer (scanner)
  522. A function that reads an input stream and returns tokens one by
  523. one. *Note Lexical::.
  524. Lexical tie-in
  525. A flag, set by actions in the grammar rules, which alters the way
  526. tokens are parsed. *Note Lexical Tie-ins::.
  527. Look-ahead token
  528. A token already read but not yet shifted. *Note Look-Ahead::.
  529. LALR(1)
  530. The class of context-free grammars that Bison (like most other
  531. parser generators) can handle; a subset of LR(1). *Note
  532. Mysterious Reduce/Reduce Conflicts: Mystery Conflicts.
  533. LR(1)
  534. The class of context-free grammars in which at most one token of
  535. look-ahead is needed to disambiguate the parsing of any piece of
  536. input.
  537. Nonterminal symbol
  538. A grammar symbol standing for a grammatical construct that can be
  539. expressed through rules in terms of smaller constructs; in other
  540. words, a construct that is not a token. *Note Symbols::.
  541. Parse error
  542. An error encountered during parsing of an input stream due to
  543. invalid syntax. *Note Error Recovery::.
  544. Parser
  545. A function that recognizes valid sentences of a language by
  546. analyzing the syntax structure of a set of tokens passed to it
  547. from a lexical analyzer.
  548. Postfix operator
  549. An arithmetic operator that is placed after the operands upon
  550. which it performs some operation.
  551. Reduction
  552. Replacing a string of nonterminals and/or terminals with a single
  553. nonterminal, according to a grammar rule. *Note Algorithm::.
  554. Reentrant
  555. A reentrant subprogram is a subprogram which can be in invoked any
  556. number of times in parallel, without interference between the
  557. various invocations. *Note Pure Decl::.
  558. Reverse polish notation
  559. A language in which all operators are postfix operators.
  560. Right recursion
  561. A rule whose result symbol is also its last component symbol; for
  562. example, `expseq1: exp ',' expseq1;'. *Note Recursion::.
  563. Semantics
  564. In computer languages, the semantics are specified by the actions
  565. taken for each instance of the language, i.e., the meaning of each
  566. statement. *Note Semantics::.
  567. Shift
  568. A parser is said to shift when it makes the choice of analyzing
  569. further input from the stream rather than reducing immediately some
  570. already-recognized rule. *Note Algorithm::.
  571. Single-character literal
  572. A single character that is recognized and interpreted as is.
  573. *Note Grammar in Bison::.
  574. Start symbol
  575. The nonterminal symbol that stands for a complete valid utterance
  576. in the language being parsed. The start symbol is usually listed
  577. as the first nonterminal symbol in a language specification.
  578. *Note Start Decl::.
  579. Symbol table
  580. A data structure where symbol names and associated data are stored
  581. during parsing to allow for recognition and use of existing
  582. information in repeated uses of a symbol. *Note Multi-function
  583. Calc::.
  584. Token
  585. A basic, grammatically indivisible unit of a language. The symbol
  586. that describes a token in the grammar is a terminal symbol. The
  587. input of the Bison parser is a stream of tokens which comes from
  588. the lexical analyzer. *Note Symbols::.
  589. Terminal symbol
  590. A grammar symbol that has no rules in the grammar and therefore is
  591. grammatically indivisible. The piece of text it represents is a
  592. token. *Note Language and Grammar::.
  593. 
  594. File: bison.info, Node: Index, Prev: Glossary, Up: Top
  595. Index
  596. *****
  597. * Menu:
  598. * $$: Actions.
  599. * $N: Actions.
  600. * %expect: Expect Decl.
  601. * %left: Using Precedence.
  602. * %nonassoc: Using Precedence.
  603. * %prec: Contextual Precedence.
  604. * %pure_parser: Pure Decl.
  605. * %right: Using Precedence.
  606. * %start: Start Decl.
  607. * %token: Token Decl.
  608. * %type: Type Decl.
  609. * %union: Union Decl.
  610. * @N: Action Features.
  611. * action: Actions.
  612. * action data types: Action Types.
  613. * action features summary: Action Features.
  614. * actions in mid-rule: Mid-Rule Actions.
  615. * actions, semantic: Semantic Actions.
  616. * additional C code section: C Code.
  617. * algorithm of parser: Algorithm.
  618. * associativity: Why Precedence.
  619. * Backus-Naur form: Language and Grammar.
  620. * Bison declaration summary: Decl Summary.
  621. * Bison declarations: Declarations.
  622. * Bison declarations (introduction): Bison Declarations.
  623. * Bison grammar: Grammar in Bison.
  624. * Bison invocation: Invocation.
  625. * Bison parser: Bison Parser.
  626. * Bison parser algorithm: Algorithm.
  627. * Bison symbols, table of: Table of Symbols.
  628. * Bison utility: Bison Parser.
  629. * BNF: Language and Grammar.
  630. * C code, section for additional: C Code.
  631. * C declarations section: C Declarations.
  632. * C-language interface: Interface.
  633. * calc: Infix Calc.
  634. * calculator, infix notation: Infix Calc.
  635. * calculator, multi-function: Multi-function Calc.
  636. * calculator, simple: RPN Calc.
  637. * character token: Symbols.
  638. * compiling the parser: Rpcalc Compile.
  639. * conflicts: Shift/Reduce.
  640. * conflicts, reduce/reduce: Reduce/Reduce.
  641. * conflicts, suppressing warnings of: Expect Decl.
  642. * context-dependent precedence: Contextual Precedence.
  643. * context-free grammar: Language and Grammar.
  644. * controlling function: Rpcalc Main.
  645. * dangling else: Shift/Reduce.
  646. * data types in actions: Action Types.
  647. * data types of semantic values: Value Type.
  648. * debugging: Debugging.
  649. * declaration summary: Decl Summary.
  650. * declarations, Bison: Declarations.
  651. * declarations, Bison (introduction): Bison Declarations.
  652. * declarations, C: C Declarations.
  653. * declaring operator precedence: Precedence Decl.
  654. * declaring the start symbol: Start Decl.
  655. * declaring token type names: Token Decl.
  656. * declaring value types: Union Decl.
  657. * declaring value types, nonterminals: Type Decl.
  658. * defining language semantics: Semantics.
  659. * else, dangling: Shift/Reduce.
  660. * error: Error Recovery.
  661. * error recovery: Error Recovery.
  662. * error recovery, simple: Simple Error Recovery.
  663. * error reporting function: Error Reporting.
  664. * error reporting routine: Rpcalc Error.
  665. * examples, simple: Examples.
  666. * exercises: Exercises.
  667. * file format: Grammar Layout.
  668. * finite-state machine: Parser States.
  669. * formal grammar: Grammar in Bison.
  670. * format of grammar file: Grammar Layout.
  671. * glossary: Glossary.
  672. * grammar file: Grammar Layout.
  673. * grammar rule syntax: Rules.
  674. * grammar rules section: Grammar Rules.
  675. * grammar, Bison: Grammar in Bison.
  676. * grammar, context-free: Language and Grammar.
  677. * grouping, syntactic: Language and Grammar.
  678. * infix notation calculator: Infix Calc.
  679. * interface: Interface.
  680. * introduction: Introduction.
  681. * invoking Bison: Invocation.
  682. * invoking Bison under VMS: VMS Invocation.
  683. * LALR(1): Mystery Conflicts.
  684. * language semantics, defining: Semantics.
  685. * layout of Bison grammar: Grammar Layout.
  686. * left recursion: Recursion.
  687. * lexical analyzer: Lexical.
  688. * lexical analyzer, purpose: Bison Parser.
  689. * lexical analyzer, writing: Rpcalc Lexer.
  690. * lexical tie-in: Lexical Tie-ins.
  691. * literal token: Symbols.
  692. * look-ahead token: Look-Ahead.
  693. * LR(1): Mystery Conflicts.
  694. * main function in simple example: Rpcalc Main.
  695. * mfcalc: Multi-function Calc.
  696. * mid-rule actions: Mid-Rule Actions.
  697. * multi-function calculator: Multi-function Calc.
  698. * mutual recursion: Recursion.
  699. * nonterminal symbol: Symbols.
  700. * operator precedence: Precedence.
  701. * operator precedence, declaring: Precedence Decl.
  702. * options for invoking Bison: Invocation.
  703. * overflow of parser stack: Stack Overflow.
  704. * parse error: Error Reporting.
  705. * parser: Bison Parser.
  706. * parser stack: Algorithm.
  707. * parser stack overflow: Stack Overflow.
  708. * parser state: Parser States.
  709. * polish notation calculator: RPN Calc.
  710. * precedence declarations: Precedence Decl.
  711. * precedence of operators: Precedence.
  712. * precedence, context-dependent: Contextual Precedence.
  713. * precedence, unary operator: Contextual Precedence.
  714. * preventing warnings about conflicts: Expect Decl.
  715. * pure parser: Pure Decl.
  716. * recovery from errors: Error Recovery.
  717. * recursive rule: Recursion.
  718. * reduce/reduce conflict: Reduce/Reduce.
  719. * reduction: Algorithm.
  720. * reentrant parser: Pure Decl.
  721. * reverse polish notation: RPN Calc.
  722. * right recursion: Recursion.
  723. * rpcalc: RPN Calc.
  724. * rule syntax: Rules.
  725. * rules section for grammar: Grammar Rules.
  726. * running Bison (introduction): Rpcalc Gen.
  727. * semantic actions: Semantic Actions.
  728. * semantic value: Semantic Values.
  729. * semantic value type: Value Type.
  730. * shift/reduce conflicts: Shift/Reduce.
  731. * shifting: Algorithm.
  732. * simple examples: Examples.
  733. * single-character literal: Symbols.
  734. * stack overflow: Stack Overflow.
  735. * stack, parser: Algorithm.
  736. * stages in using Bison: Stages.
  737. * start symbol: Language and Grammar.
  738. * start symbol, declaring: Start Decl.
  739. * state (of parser): Parser States.
  740. * summary, action features: Action Features.
  741. * summary, Bison declaration: Decl Summary.
  742. * suppressing conflict warnings: Expect Decl.
  743. * symbol: Symbols.
  744. * symbol table example: Mfcalc Symtab.
  745. * symbols (abstract): Language and Grammar.
  746. * symbols in Bison, table of: Table of Symbols.
  747. * syntactic grouping: Language and Grammar.
  748. * syntax error: Error Reporting.
  749. * syntax of grammar rules: Rules.
  750. * terminal symbol: Symbols.
  751. * token: Language and Grammar.
  752. * token type: Symbols.
  753. * token type names, declaring: Token Decl.
  754. * tracing the parser: Debugging.
  755. * unary operator precedence: Contextual Precedence.
  756. * using Bison: Stages.
  757. * value type, semantic: Value Type.
  758. * value types, declaring: Union Decl.
  759. * value types, nonterminals, declaring: Type Decl.
  760. * value, semantic: Semantic Values.
  761. * VMS: VMS Invocation.
  762. * warnings, preventing: Expect Decl.
  763. * writing a lexical analyzer: Rpcalc Lexer.
  764. * YYABORT: Parser Function.
  765. * YYACCEPT: Parser Function.
  766. * YYBACKUP: Action Features.
  767. * yychar: Look-Ahead.
  768. * yyclearin: Error Recovery.
  769. * YYDEBUG: Debugging.
  770. * yydebug: Debugging.
  771. * YYEMPTY: Action Features.
  772. * yyerrok: Error Recovery.
  773. * YYERROR: Action Features.
  774. * yyerror: Error Reporting.
  775. * YYINITDEPTH: Stack Overflow.
  776. * yylex: Lexical.
  777. * yylloc: Token Positions.
  778. * YYLTYPE: Token Positions.
  779. * yylval: Token Values.
  780. * YYMAXDEPTH: Stack Overflow.
  781. * yynerrs: Error Reporting.
  782. * yyparse: Parser Function.
  783. * YYPRINT: Debugging.
  784. * YYRECOVERING: Error Recovery.
  785. * |: Rules.