BISON-3.INF 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. Info file bison.info, produced by Makeinfo, -*- Text -*- from input
  2. file bison.texinfo.
  3. This file documents the Bison parser generator.
  4. Copyright (C) 1988, 1989 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
  11. ``Conditions for Using Bison'' are included exactly as in the
  12. original, and provided that the entire resulting derived work is
  13. distributed under the terms of a permission notice identical to this
  14. one.
  15. Permission is granted to copy and distribute translations of this
  16. manual into another language, under the above conditions for modified
  17. versions, except that the sections entitled ``GNU General Public
  18. License'', ``Conditions for Using Bison'' and this permission notice
  19. may be included in translations approved by the Free Software
  20. Foundation instead of in the original English.
  21. 
  22. File: bison.info, Node: Multiple Parsers, Prev: Declarations, Up: Grammar File
  23. Multiple Parsers in the Same Program
  24. ====================================
  25. Most programs that use Bison parse only one language and therefore
  26. contain only one Bison parser. But what if you want to parse more
  27. than one language with the same program? Here is what you must do:
  28. * Make each parser a pure parser (*note Pure Decl::.). This gets
  29. rid of global variables such as `yylval' which would otherwise
  30. conflict between the various parsers, but it requires an
  31. alternate calling convention for `yylex' (*note Pure Calling::.).
  32. * In each grammar file, define `yyparse' as a macro, expanding
  33. into the name you want for that parser. Put this definition in
  34. the C declarations section (*note C Declarations::.). For
  35. example:
  36. %{
  37. #define yyparse parse_algol
  38. %}
  39. Then use the expanded name `parse_algol' in other source files
  40. to call this parser.
  41. * If you want different lexical analyzers for each grammar, you
  42. can define `yylex' as a macro, just like `yyparse'. Use the
  43. expanded name when you define `yylex' in another source file.
  44. If you define `yylex' in the grammar file itself, simply make it
  45. static, like this:
  46. %{
  47. static int yylex ();
  48. %}
  49. %%
  50. ... GRAMMAR RULES ...
  51. %%
  52. static int
  53. yylex (yylvalp, yyllocp)
  54. YYSTYPE *yylvalp;
  55. YYLTYPE *yyllocp;
  56. { ... }
  57. * If you want a different `yyerror' function for each grammar, you
  58. can use the same methods that work for `yylex'.
  59. 
  60. File: bison.info, Node: Interface, Next: Algorithm, Prev: Grammar File, Up: Top
  61. Parser C-Language Interface
  62. ***************************
  63. The Bison parser is actually a C function named `yyparse'. Here we
  64. describe the interface conventions of `yyparse' and the other
  65. functions that it needs to use.
  66. Keep in mind that the parser uses many C identifiers starting with
  67. `yy' and `YY' for internal purposes. If you use such an identifier
  68. (aside from those in this manual) in an action or in additional C
  69. code in the grammar file, you are likely to run into trouble.
  70. * Menu:
  71. * Parser Function:: How to call `yyparse' and what it returns.
  72. * Lexical:: You must supply a function `yylex' which reads tokens.
  73. * Error Reporting:: You must supply a function `yyerror'.
  74. * Action Features:: Special features for use in actions.
  75. 
  76. File: bison.info, Node: Parser Function, Next: Lexical, Prev: Interface, Up: Interface
  77. The Parser Function `yyparse'
  78. =============================
  79. You call the function `yyparse' to cause parsing to occur. This
  80. function reads tokens, executes actions, and ultimately returns when
  81. it encounters end-of-input or an unrecoverable syntax error. You can
  82. also write an action which directs `yyparse' to return immediately
  83. without reading further.
  84. The value returned by `yyparse' is 0 if parsing was successful
  85. (return is due to end-of-input).
  86. The value is 1 if parsing failed (return is due to a syntax error).
  87. In an action, you can cause immediate return from `yyparse' by using
  88. these macros:
  89. `YYACCEPT'
  90. Return immediately with value 0 (to report success).
  91. `YYABORT'
  92. Return immediately with value 1 (to report failure).
  93. 
  94. File: bison.info, Node: Lexical, Next: Error Reporting, Prev: Parser Function, Up: Interface
  95. The Lexical Analyzer Function `yylex'
  96. =====================================
  97. The "lexical analyzer" function, `yylex', recognizes tokens from the
  98. input stream and returns them to the parser. Bison does not create
  99. this function automatically; you must write it so that `yyparse' can
  100. call it. The function is sometimes referred to as a lexical scanner.
  101. In simple programs, `yylex' is often defined at the end of the Bison
  102. grammar file. If `yylex' is defined in a separate source file, you
  103. need to arrange for the token-type macro definitions to be available
  104. there. To do this, use the `-d' option when you run Bison, so that
  105. it will write these macro definitions into a separate header file
  106. `NAME.tab.h' which you can include in the other source files that
  107. need it. *Note Invocation::.
  108. * Menu:
  109. * Calling Convention:: How `yyparse' calls `yylex'.
  110. * Token Values:: How `yylex' must return the semantic value
  111. of the token it has read.
  112. * Token Positions:: How `yylex' must return the text position
  113. (line number, etc.) of the token, if the
  114. actions want that.
  115. * Pure Calling:: How the calling convention differs
  116. in a pure parser (*note Pure Decl::.).
  117. 
  118. File: bison.info, Node: Calling Convention, Next: Token Values, Prev: Lexical, Up: Lexical
  119. Calling Convention for `yylex'
  120. ------------------------------
  121. The value that `yylex' returns must be the numeric code for the type
  122. of token it has just found, or 0 for end-of-input.
  123. When a token is referred to in the grammar rules by a name, that name
  124. in the parser file becomes a C macro whose definition is the proper
  125. numeric code for that token type. So `yylex' can use the name to
  126. indicate that type. *Note Symbols::.
  127. When a token is referred to in the grammar rules by a character
  128. literal, the numeric code for that character is also the code for the
  129. token type. So `yylex' can simply return that character code. The
  130. null character must not be used this way, because its code is zero
  131. and that is what signifies end-of-input.
  132. Here is an example showing these things:
  133. yylex()
  134. {
  135. ...
  136. if (c == EOF) /* Detect end of file. */
  137. return 0;
  138. ...
  139. if (c == '+' || c == '-')
  140. return c; /* Assume token type for `+' is '+'. */
  141. ...
  142. return INT; /* Return the type of the token. */
  143. ...
  144. }
  145. This interface has been designed so that the output from the `lex'
  146. utility can be used without change as the definition of `yylex'.
  147. 
  148. File: bison.info, Node: Token Values, Next: Token Positions, Prev: Calling Convention, Up: Lexical
  149. Returning Semantic Values of Tokens
  150. -----------------------------------
  151. In an ordinary (nonreentrant) parser, the semantic value of the token
  152. must be stored into the global variable `yylval'. When you are using
  153. just one data type for semantic values, `yylval' has that type.
  154. Thus, if the type is `int' (the default), you might write this in
  155. `yylex':
  156. ...
  157. yylval = value; /* Put value onto Bison stack. */
  158. return INT; /* Return the type of the token. */
  159. ...
  160. When you are using multiple data types, `yylval''s type is a union
  161. made from the `%union' declaration (*note Union Decl::.). So when
  162. you store a token's value, you must use the proper member of the union.
  163. If the `%union' declaration looks like this:
  164. %union {
  165. int intval;
  166. double val;
  167. symrec *tptr;
  168. }
  169. then the code in `yylex' might look like this:
  170. ...
  171. yylval.intval = value; /* Put value onto Bison stack. */
  172. return INT; /* Return the type of the token. */
  173. ...
  174. 
  175. File: bison.info, Node: Token Positions, Next: Pure Calling, Prev: Token Values, Up: Lexical
  176. Reporting Textual Positions of Tokens
  177. -------------------------------------
  178. If you are using the `@N'-feature (*note Action Features::.) in
  179. actions to keep track of the textual locations of tokens and
  180. groupings, then you must provide this information in `yylex'. The
  181. function `yyparse' expects to find the textual location of a token
  182. just parsed in the global variable `yylloc'. So `yylex' must store
  183. the proper data in that variable. The value of `yylloc' is a
  184. structure and you need only initialize the members that are going to
  185. be used by the actions. The four members are called `first_line',
  186. `first_column', `last_line' and `last_column'. Note that the use of
  187. this feature makes the parser noticeably slower.
  188. The data type of `yylloc' has the name `YYLTYPE'.
  189. 
  190. File: bison.info, Node: Pure Calling, Prev: Token Positions, Up: Lexical
  191. Calling Convention for Pure Parsers
  192. -----------------------------------
  193. When you use the Bison declaration `%pure_parser' to request a pure,
  194. reentrant parser, the global communication variables `yylval' and
  195. `yylloc' cannot be used. (*Note Pure Decl::.) In such parsers the
  196. two global variables are replaced by pointers passed as arguments to
  197. `yylex'. You must declare them as shown here, and pass the
  198. information back by storing it through those pointers.
  199. yylex (lvalp, llocp)
  200. YYSTYPE *lvalp;
  201. YYLTYPE *llocp;
  202. {
  203. ...
  204. *lvalp = value; /* Put value onto Bison stack. */
  205. return INT; /* Return the type of the token. */
  206. ...
  207. }
  208. 
  209. File: bison.info, Node: Error Reporting, Next: Action Features, Prev: Lexical, Up: Interface
  210. The Error Reporting Function `yyerror'
  211. ======================================
  212. The Bison parser detects a "parse error" or "syntax error" whenever
  213. it reads a token which cannot satisfy any syntax rule. A action in
  214. the grammar can also explicitly proclaim an error, using the macro
  215. `YYERROR' (*note Action Features::.).
  216. The Bison parser expects to report the error by calling an error
  217. reporting function named `yyerror', which you must supply. It is
  218. called by `yyparse' whenever a syntax error is found, and it receives
  219. one argument. For a parse error, the string is always `"parse error"'.
  220. The parser can detect one other kind of error: stack overflow. This
  221. happens when the input contains constructions that are very deeply
  222. nested. It isn't likely you will encounter this, since the Bison
  223. parser extends its stack automatically up to a very large limit. But
  224. if overflow happens, `yyparse' calls `yyerror' in the usual fashion,
  225. except that the argument string is `"parser stack overflow"'.
  226. The following definition suffices in simple programs:
  227. yyerror (s)
  228. char *s;
  229. {
  230. fprintf (stderr, "%s\n", s);
  231. }
  232. After `yyerror' returns to `yyparse', the latter will attempt error
  233. recovery if you have written suitable error recovery grammar rules
  234. (*note Error Recovery::.). If recovery is impossible, `yyparse' will
  235. immediately return 1.
  236. The variable `yynerrs' contains the number of syntax errors
  237. encountered so far. Normally this variable is global; but if you
  238. request a pure parser (*note Pure Decl::.) then it is a local
  239. variable which only the actions can access.
  240. 
  241. File: bison.info, Node: Action Features, Prev: Error Reporting, Up: Interface
  242. Special Features for Use in Actions
  243. ===================================
  244. Here is a table of Bison constructs, variables and macros that are
  245. useful in actions.
  246. `$$'
  247. Acts like a variable that contains the semantic value for the
  248. grouping made by the current rule. *Note Actions::.
  249. `$N'
  250. Acts like a variable that contains the semantic value for the
  251. Nth component of the current rule. *Note Actions::.
  252. `$<TYPEALT>$'
  253. Like `$$' but specifies alternative TYPEALT in the union
  254. specified by the `%union' declaration. *Note Action Types::.
  255. `$<TYPEALT>N'
  256. Like `$N' but specifies alternative TYPEALT in the union
  257. specified by the `%union' declaration. *Note Action Types::.
  258. `YYABORT;'
  259. Return immediately from `yyparse', indicating failure. *Note
  260. Parser Function::.
  261. `YYACCEPT;'
  262. Return immediately from `yyparse', indicating success. *Note
  263. Parser Function::.
  264. `YYEMPTY'
  265. Value stored in `yychar' when there is no look-ahead token.
  266. `YYERROR;'
  267. Cause an immediate syntax error. This causes `yyerror' to be
  268. called, and then error recovery begins. *Note Error Recovery::.
  269. `yychar'
  270. Variable containing the current look-ahead token. (In a pure
  271. parser, this is actually a local variable within `yyparse'.)
  272. When there is no look-ahead token, the value `YYERROR' is stored
  273. here. *Note Look-Ahead::.
  274. `yyclearin;'
  275. Discard the current look-ahead token. This is useful primarily
  276. in error rules. *Note Error Recovery::.
  277. `yyerrok;'
  278. Resume generating error messages immediately for subsequent
  279. syntax errors. This is useful primarily in error rules. *Note
  280. Error Recovery::.
  281. `@N'
  282. Acts like a structure variable containing information on the
  283. line numbers and column numbers of the Nth component of the
  284. current rule. The structure has four members, like this:
  285. struct {
  286. int first_line, last_line;
  287. int first_column, last_column;
  288. };
  289. Thus, to get the starting line number of the third component,
  290. use `@3.first_line'.
  291. In order for the members of this structure to contain valid
  292. information, you must make `yylex' supply this information about
  293. each token. If you need only certain members, then `yylex' need
  294. only fill in those members.
  295. The use of this feature makes the parser noticeably slower.
  296. 
  297. File: bison.info, Node: Algorithm, Next: Error Recovery, Prev: Interface, Up: Top
  298. The Algorithm of the Bison Parser
  299. *********************************
  300. As Bison reads tokens, it pushes them onto a stack along with their
  301. semantic values. The stack is called the "parser stack". Pushing a
  302. token is traditionally called "shifting".
  303. For example, suppose the infix calculator has read `1 + 5 *', with a
  304. `3' to come. The stack will have four elements, one for each token
  305. that was shifted.
  306. But the stack does not always have an element for each token read.
  307. When the last N tokens and groupings shifted match the components of
  308. a grammar rule, they can be combined according to that rule. This is
  309. called "reduction". Those tokens and groupings are replaced on the
  310. stack by a single grouping whose symbol is the result (left hand
  311. side) of that rule. Running the rule's action is part of the process
  312. of reduction, because this is what computes the semantic value of the
  313. resulting grouping.
  314. For example, if the infix calculator's parser stack contains this:
  315. 1 + 5 * 3
  316. and the next input token is a newline character, then the last three
  317. elements can be reduced to 15 via the rule:
  318. expr: expr '*' expr;
  319. Then the stack contains just these three elements:
  320. 1 + 15
  321. At this point, another reduction can be made, resulting in the single
  322. value 16. Then the newline token can be shifted.
  323. The parser tries, by shifts and reductions, to reduce the entire
  324. input down to a single grouping whose symbol is the grammar's
  325. start-symbol (*note Language and Grammar::.).
  326. This kind of parser is known in the literature as a bottom-up parser.
  327. * Menu:
  328. * Look-Ahead:: Parser looks one token ahead when deciding what to do.
  329. * Shift/Reduce:: Conflicts: when either shifting or reduction is valid.
  330. * Precedence:: Operator precedence works by resolving conflicts.
  331. * Contextual Precedence:: When an operator's precedence depends on context.
  332. * Parser States:: The parser is a finite-state-machine with stack.
  333. * Reduce/Reduce:: When two rules are applicable in the same situation.
  334. 
  335. File: bison.info, Node: Look-Ahead, Next: Shift/Reduce, Prev: Algorithm, Up: Algorithm
  336. Look-Ahead Tokens
  337. =================
  338. The Bison parser does *not* always reduce immediately as soon as the
  339. last N tokens and groupings match a rule. This is because such a
  340. simple strategy is inadequate to handle most languages. Instead,
  341. when a reduction is possible, the parser sometimes ``looks ahead'' at
  342. the next token in order to decide what to do.
  343. When a token is read, it is not immediately shifted; first it becomes
  344. the "look-ahead token", which is not on the stack. Now the parser
  345. can perform one or more reductions of tokens and groupings on the
  346. stack, while the look-ahead token remains off to the side. When no
  347. more reductions should take place, the look-ahead token is shifted
  348. onto the stack. This does not mean that all possible reductions have
  349. been done; depending on the token type of the look-ahead token, some
  350. rules may choose to delay their application.
  351. Here is a simple case where look-ahead is needed. These three rules
  352. define expressions which contain binary addition operators and
  353. postfix unary factorial operators (`!'), and allow parentheses for
  354. grouping.
  355. expr: term '+' expr
  356. | term
  357. ;
  358. term: '(' expr ')'
  359. | term '!'
  360. | NUMBER
  361. ;
  362. Suppose that the tokens `1 + 2' have been read and shifted; what
  363. should be done? If the following token is `)', then the first three
  364. tokens must be reduced to form an `expr'. This is the only valid
  365. course, because shifting the `)' would produce a sequence of symbols
  366. `term ')'', and no rule allows this.
  367. If the following token is `!', then it must be shifted immediately so
  368. that `2 !' can be reduced to make a `term'. If instead the parser
  369. were to reduce before shifting, `1 + 2' would become an `expr'. It
  370. would then be impossible to shift the `!' because doing so would
  371. produce on the stack the sequence of symbols `expr '!''. No rule
  372. allows that sequence.
  373. The current look-ahead token is stored in the variable `yychar'.
  374. *Note Action Features::.
  375. 
  376. File: bison.info, Node: Shift/Reduce, Next: Precedence, Prev: Look-Ahead, Up: Algorithm
  377. Shift/Reduce Conflicts
  378. ======================
  379. Suppose we are parsing a language which has if-then and if-then-else
  380. statements, with a pair of rules like this:
  381. if_stmt:
  382. IF expr THEN stmt
  383. | IF expr THEN stmt ELSE stmt
  384. ;
  385. (Here we assume that `IF', `THEN' and `ELSE' are terminal symbols for
  386. specific keyword tokens.)
  387. When the `ELSE' token is read and becomes the look-ahead token, the
  388. contents of the stack (assuming the input is valid) are just right
  389. for reduction by the first rule. But it is also legitimate to shift
  390. the `ELSE', because that would lead to eventual reduction by the
  391. second rule.
  392. This situation, where either a shift or a reduction would be valid,
  393. is called a "shift/reduce conflict". Bison is designed to resolve
  394. these conflicts by choosing to shift, unless otherwise directed by
  395. operator precedence declarations. To see the reason for this, let's
  396. contrast it with the other alternative.
  397. Since the parser prefers to shift the `ELSE', the result is to attach
  398. the else-clause to the innermost if-statement, making these two
  399. inputs equivalent:
  400. if x then if y then win(); else lose;
  401. if x then do; if y then win(); else lose; end;
  402. But if the parser chose to reduce when possible rather than shift,
  403. the result would be to attach the else-clause to the outermost
  404. if-statement, making these two inputs equivalent:
  405. if x then if y then win(); else lose;
  406. if x then do; if y then win(); end; else lose;
  407. The conflict exists because the grammar as written is ambiguous:
  408. either parsing of the simple nested if-statement is legitimate. The
  409. established convention is that these ambiguities are resolved by
  410. attaching the else-clause to the innermost if-statement; this is what
  411. Bison accomplishes by choosing to shift rather than reduce. (It
  412. would ideally be cleaner to write an unambiguous grammar, but that is
  413. very hard to do in this case.) This particular ambiguity was first
  414. encountered in the specifications of Algol 60 and is called the
  415. ``dangling `else''' ambiguity.
  416. To avoid warnings from Bison about predictable, legitimate
  417. shift/reduce conflicts, use the `%expect N' declaration. There will
  418. be no warning as long as the number of shift/reduce conflicts is
  419. exactly N. *Note Expect Decl::.
  420. 
  421. File: bison.info, Node: Precedence, Next: Contextual Precedence, Prev: Shift/Reduce, Up: Algorithm
  422. Operator Precedence
  423. ===================
  424. Another situation where shift/reduce conflicts appear is in
  425. arithmetic expressions. Here shifting is not always the preferred
  426. resolution; the Bison declarations for operator precedence allow you
  427. to specify when to shift and when to reduce.
  428. * Menu:
  429. * Why Precedence:: An example showing why precedence is needed.
  430. * Using Precedence:: How to specify precedence in Bison grammars.
  431. * Precedence Examples:: How these features are used in the previous example.
  432. * How Precedence:: How they work.
  433. 
  434. File: bison.info, Node: Why Precedence, Next: Using Precedence, Prev: Precedence, Up: Precedence
  435. When Precedence is Needed
  436. -------------------------
  437. Consider the following ambiguous grammar fragment (ambiguous because
  438. the input `1 - 2 * 3' can be parsed in two different ways):
  439. expr: expr '-' expr
  440. | expr '*' expr
  441. | expr '<' expr
  442. | '(' expr ')'
  443. ...
  444. ;
  445. Suppose the parser has seen the tokens `1', `-' and `2'; should it
  446. reduce them via the rule for the addition operator? It depends on
  447. the next token. Of course, if the next token is `)', we must reduce;
  448. shifting is invalid because no single rule can reduce the token
  449. sequence `- 2 )' or anything starting with that. But if the next
  450. token is `*' or `<', we have a choice: either shifting or reduction
  451. would allow the parse to complete, but with different results.
  452. To decide which one Bison should do, we must consider the results.
  453. If the next operator token OP is shifted, then it must be reduced
  454. first in order to permit another opportunity to reduce the sum. The
  455. result is (in effect) `1 - (2 OP 3)'. On the other hand, if the
  456. subtraction is reduced before shifting OP, the result is
  457. `(1 - 2) OP 3'. Clearly, then, the choice of shift or reduce
  458. should depend on the relative precedence of the operators `-' and OP:
  459. `*' should be shifted first, but not `<'.
  460. What about input like `1 - 2 - 5'; should this be `(1 - 2) - 5' or
  461. `1 - (2 - 5)'? For most operators we prefer the former, which is
  462. called "left association". The latter alternative, "right
  463. association", is desirable for assignment operators. The choice of
  464. left or right association is a matter of whether the parser chooses
  465. to shift or reduce when the stack contains `1 - 2' and the look-ahead
  466. token is `-': shifting makes right-associativity.
  467. 
  468. File: bison.info, Node: Using Precedence, Next: Precedence Examples, Prev: Why Precedence, Up: Precedence
  469. How to Specify Operator Precedence
  470. ----------------------------------
  471. Bison allows you to specify these choices with the operator
  472. precedence declarations `%left' and `%right'. Each such declaration
  473. contains a list of tokens, which are operators whose precedence and
  474. associativity is being declared. The `%left' declaration makes all
  475. those operators left-associative and the `%right' declaration makes
  476. them right-associative. A third alternative is `%nonassoc', which
  477. declares that it is a syntax error to find the same operator twice
  478. ``in a row''.
  479. The relative precedence of different operators is controlled by the
  480. order in which they are declared. The first `%left' or `%right'
  481. declaration declares the operators whose precedence is lowest, the
  482. next such declaration declares the operators whose precedence is a
  483. little higher, and so on.
  484. 
  485. File: bison.info, Node: Precedence Examples, Next: How Precedence, Prev: Using Precedence, Up: Precedence
  486. Precedence Examples
  487. -------------------
  488. In our example, we would want the following declarations:
  489. %left '<'
  490. %left '-'
  491. %left '*'
  492. In a more complete example, which supports other operators as well,
  493. we would declare them in groups of equal precedence. For example,
  494. `'+'' is declared with `'-'':
  495. %left '<' '>' '=' NE LE GE
  496. %left '+' '-'
  497. %left '*' '/'
  498. (Here `NE' and so on stand for the operators for ``not equal'' and so
  499. on. We assume that these tokens are more than one character long and
  500. therefore are represented by names, not character literals.)
  501. 
  502. File: bison.info, Node: How Precedence, Prev: Precedence Examples, Up: Precedence
  503. How Precedence Works
  504. --------------------
  505. The first effect of the precedence declarations is to assign
  506. precedence levels to the terminal symbols declared. The second
  507. effect is to assign precedence levels to certain rules: each rule
  508. gets its precedence from the last terminal symbol mentioned in the
  509. components. (You can also specify explicitly the precedence of a
  510. rule. *Note Contextual Precedence::.)
  511. Finally, the resolution of conflicts works by comparing the
  512. precedence of the rule being considered with that of the look-ahead
  513. token. If the token's precedence is higher, the choice is to shift.
  514. If the rule's precedence is higher, the choice is to reduce. If they
  515. have equal precedence, the choice is made based on the associativity
  516. of that precedence level. The verbose output file made by `-v'
  517. (*note Invocation::.) says how each conflict was resolved.
  518. Not all rules and not all tokens have precedence. If either the rule
  519. or the look-ahead token has no precedence, then the default is to
  520. shift.
  521. 
  522. File: bison.info, Node: Contextual Precedence, Next: Parser States, Prev: Precedence, Up: Algorithm
  523. Operators with Context-Dependent Precedence
  524. ===========================================
  525. Often the precedence of an operator depends on the context. This
  526. sounds outlandish at first, but it is really very common. For
  527. example, a minus sign typically has a very high precedence as a unary
  528. operator, and a somewhat lower precedence (lower than multiplication)
  529. as a binary operator.
  530. The Bison precedence declarations, `%left', `%right' and `%nonassoc',
  531. can only be used once for a given token; so a token has only one
  532. precedence declared in this way. For context-dependent precedence,
  533. you need to use an additional mechanism: the `%prec' modifier for
  534. rules.
  535. The `%prec' modifier declares the precedence of a particular rule by
  536. specifying a terminal symbol whose predecence should be used for that
  537. rule. It's not necessary for that symbol to appear otherwise in the
  538. rule. The modifier's syntax is:
  539. %prec TERMINAL-SYMBOL
  540. and it is written after the components of the rule. Its effect is to
  541. assign the rule the precedence of TERMINAL-SYMBOL, overriding the
  542. precedence that would be deduced for it in the ordinary way. The
  543. altered rule precedence then affects how conflicts involving that
  544. rule are resolved (*note Precedence::.).
  545. Here is how `%prec' solves the problem of unary minus. First,
  546. declare a precedence for a fictitious terminal symbol named `UMINUS'.
  547. There are no tokens of this type, but the symbol serves to stand for
  548. its precedence:
  549. ...
  550. %left '+' '-'
  551. %left '*'
  552. %left UMINUS
  553. Now the precedence of `UMINUS' can be used in specific rules:
  554. exp: ...
  555. | exp '-' exp
  556. ...
  557. | '-' exp %prec UMINUS
  558. 
  559. File: bison.info, Node: Parser States, Next: Reduce/Reduce, Prev: Contextual Precedence, Up: Algorithm
  560. Parser States
  561. =============
  562. The function `yyparse' is implemented using a finite-state machine.
  563. The values pushed on the parser stack are not simply token type
  564. codes; they represent the entire sequence of terminal and nonterminal
  565. symbols at or near the top of the stack. The current state collects
  566. all the information about previous input which is relevant to
  567. deciding what to do next.
  568. Each time a look-ahead token is read, the current parser state
  569. together with the type of look-ahead token are looked up in a table.
  570. This table entry can say, ``Shift the look-ahead token.'' In this
  571. case, it also specifies the new parser state, which is pushed onto
  572. the top of the parser stack. Or it can say, ``Reduce using rule
  573. number N.'' This means that a certain of tokens or groupings are
  574. taken off the top of the stack, and replaced by one grouping. In
  575. other words, that number of states are popped from the stack, and one
  576. new state is pushed.
  577. There is one other alternative: the table can say that the look-ahead
  578. token is erroneous in the current state. This causes error
  579. processing to begin (*note Error Recovery::.).
  580. 
  581. File: bison.info, Node: Reduce/Reduce, Prev: Parser States, Up: Algorithm
  582. Reduce/Reduce conflicts
  583. =======================
  584. A reduce/reduce conflict occurs if there are two or more rules that
  585. apply to the same sequence of input. This usually indicates a
  586. serious error in the grammar.
  587. For example, here is an erroneous attempt to define a sequence of
  588. zero or more `word' groupings.
  589. sequence: /* empty */
  590. { printf ("empty sequence\n"); }
  591. | word
  592. { printf ("single word %s\n", $1); }
  593. | sequence word
  594. { printf ("added word %s\n", $2); }
  595. ;
  596. The error is an ambiguity: there is more than one way to parse a
  597. single `word' into a `sequence'. It could be reduced directly via
  598. the second rule. Alternatively, nothing-at-all could be reduced into
  599. a `sequence' via the first rule, and this could be combined with the
  600. `word' using the third rule.
  601. You might think that this is a distinction without a difference,
  602. because it does not change whether any particular input is valid or
  603. not. But it does affect which actions are run. One parsing order
  604. runs the second rule's action; the other runs the first rule's action
  605. and the third rule's action. In this example, the output of the
  606. program changes.
  607. Bison resolves a reduce/reduce conflict by choosing to use the rule
  608. that appears first in the grammar, but it is very risky to rely on
  609. this. Every reduce/reduce conflict must be studied and usually
  610. eliminated. Here is the proper way to define `sequence':
  611. sequence: /* empty */
  612. { printf ("empty sequence\n"); }
  613. | sequence word
  614. { printf ("added word %s\n", $2); }
  615. ;
  616. Here is another common error that yields a reduce/reduce conflict:
  617. sequence: /* empty */
  618. | sequence words
  619. | sequence redirects
  620. ;
  621. words: /* empty */
  622. | words word
  623. ;
  624. redirects:/* empty */
  625. | redirects redirect
  626. ;
  627. The intention here is to define a sequence which can contain either
  628. `word' or `redirect' groupings. The individual definitions of
  629. `sequence', `words' and `redirects' are error-free, but the three
  630. together make a subtle ambiguity: even an empty input can be parsed
  631. in infinitely many ways!
  632. Consider: nothing-at-all could be a `words'. Or it could be two
  633. `words' in a row, or three, or any number. It could equally well be
  634. a `redirects', or two, or any number. Or it could be a `words'
  635. followed by three `redirects' and another `words'. And so on.
  636. Here are two ways to correct these rules. First, to make it a single
  637. level of sequence:
  638. sequence: /* empty */
  639. | sequence word
  640. | sequence redirect
  641. ;
  642. Second, to prevent either a `words' or a `redirects' from being empty:
  643. sequence: /* empty */
  644. | sequence words
  645. | sequence redirects
  646. ;
  647. words: word
  648. | words word
  649. ;
  650. redirects:redirect
  651. | redirects redirect
  652. ;
  653. 
  654. File: bison.info, Node: Error Recovery, Next: Context Dependency, Prev: Algorithm, Up: Top
  655. Error Recovery
  656. **************
  657. It is not usually acceptable to have the program terminate on a parse
  658. error. For example, a compiler should recover sufficiently to parse
  659. the rest of the input file and check it for errors; a calculator
  660. should accept another expression.
  661. In a simple interactive command parser where each input is one line,
  662. it may be sufficient to allow `yyparse' to return 1 on error and have
  663. the caller ignore the rest of the input line when that happens (and
  664. then call `yyparse' again). But this is inadequate for a compiler,
  665. because it forgets all the syntactic context leading up to the error.
  666. A syntax error deep within a function in the compiler input should
  667. not cause the compiler to treat the following line like the beginning
  668. of a source file.
  669. You can define how to recover from a syntax error by writing rules to
  670. recognize the special token `error'. This is a terminal symbol that
  671. is always defined (you need not declare it) and reserved for error
  672. handling. The Bison parser generates an `error' token whenever a
  673. syntax error happens; if you have provided a rule to recognize this
  674. token in the current context, the parse can continue. For example:
  675. stmnts: /* empty string */
  676. | stmnts '\n'
  677. | stmnts exp '\n'
  678. | stmnts error '\n'
  679. The fourth rule in this example says that an error followed by a
  680. newline makes a valid addition to any `stmnts'.
  681. What happens if a syntax error occurs in the middle of an `exp'? The
  682. error recovery rule, interpreted strictly, applies to the precise
  683. sequence of a `stmnts', an `error' and a newline. If an error occurs
  684. in the middle of an `exp', there will probably be some additional
  685. tokens and subexpressions on the stack after the last `stmnts', and
  686. there will be tokens to read before the next newline. So the rule is
  687. not applicable in the ordinary way.
  688. But Bison can force the situation to fit the rule, by discarding part
  689. of the semantic context and part of the input. First it discards
  690. states and objects from the stack until it gets back to a state in
  691. which the `error' token is acceptable. (This means that the
  692. subexpressions already parsed are discarded, back to the last
  693. complete `stmnts'.) At this point the `error' token can be shifted.
  694. Then, if the old look-ahead token is not acceptable to be shifted
  695. next, the parser reads tokens and discards them until it finds a
  696. token which is acceptable. In this example, Bison reads and discards
  697. input until the next newline so that the fourth rule can apply.
  698. The choice of error rules in the grammar is a choice of strategies
  699. for error recovery. A simple and useful strategy is simply to skip
  700. the rest of the current input line or current statement if an error
  701. is detected:
  702. stmnt: error ';' /* on error, skip until ';' is read */
  703. It is also useful to recover to the matching close-delimiter of an
  704. opening-delimiter that has already been parsed. Otherwise the
  705. close-delimiter will probably appear to be unmatched, and generate
  706. another, spurious error message:
  707. primary: '(' expr ')'
  708. | '(' error ')'
  709. ...
  710. ;
  711. Error recovery strategies are necessarily guesses. When they guess
  712. wrong, one syntax error often leads to another. In the above
  713. example, the error recovery rule guesses that an error is due to bad
  714. input within one `stmnt'. Suppose that instead a spurious semicolon
  715. is inserted in the middle of a valid `stmnt'. After the error
  716. recovery rule recovers from the first error, another syntax error
  717. will be found straightaway, since the text following the spurious
  718. semicolon is also an invalid `stmnt'.
  719. To prevent an outpouring of error messages, the parser will output no
  720. error message for another syntax error that happens shortly after the
  721. first; only after three consecutive input tokens have been
  722. successfully shifted will error messages resume.
  723. Note that rules which accept the `error' token may have actions, just
  724. as any other rules can.
  725. You can make error messages resume immediately by using the macro
  726. `yyerrok' in an action. If you do this in the error rule's action,
  727. no error messages will be suppressed. This macro requires no
  728. arguments; `yyerrok;' is a valid C statement.
  729. The previous look-ahead token is reanalyzed immediately after an
  730. error. If this is unacceptable, then the macro `yyclearin' may be
  731. used to clear this token. Write the statement `yyclearin;' in the
  732. error rule's action.
  733. For example, suppose that on a parse error, an error handling routine
  734. is called that advances the input stream to some point where parsing
  735. should once again commence. The next symbol returned by the lexical
  736. scanner is probably correct. The previous look-ahead token ought to
  737. be discarded with `yyclearin;'.
  738. 
  739. File: bison.info, Node: Context Dependency, Next: Debugging, Prev: Error Recovery, Up: Top
  740. Handling Context Dependencies
  741. *****************************
  742. The Bison paradigm is to parse tokens first, then group them into
  743. larger syntactic units. In many languages, the meaning of a token is
  744. affected by its context. Although this violates the Bison paradigm,
  745. certain techniques (known as "kludges") may enable you to write Bison
  746. parsers for such languages.
  747. * Menu:
  748. * Semantic Tokens:: Token parsing can depend on the semantic context.
  749. * Lexical Tie-ins:: Token parsing can depend on the syntactic context.
  750. * Tie-in Recovery:: Lexical tie-ins have implications for how
  751. error recovery rules must be written.
  752. (Actually, ``kludge'' means any technique that gets its job done but
  753. is neither clean nor robust.)
  754. 
  755. File: bison.info, Node: Semantic Tokens, Next: Lexical Tie-ins, Prev: Context Dependency, Up: Context Dependency
  756. Semantic Info in Token Types
  757. ============================
  758. The C language has a context dependency: the way an identifier is
  759. used depends on what its current meaning is. For example, consider
  760. this:
  761. foo (x);
  762. This looks like a function call statement, but if `foo' is a typedef
  763. name, then this is actually a declaration of `x'. How can a Bison
  764. parser for C decide how to parse this input?
  765. The method used in GNU C is to have two different token types,
  766. `IDENTIFIER' and `TYPENAME'. When `yylex' finds an identifier, it
  767. looks up the current declaration of the identifier in order to decide
  768. which token type to return: `TYPENAME' if the identifier is declared
  769. as a typedef, `IDENTIFIER' otherwise.
  770. The grammar rules can then express the context dependency by the
  771. choice of token type to recognize. `IDENTIFIER' is accepted as an
  772. expression, but `TYPENAME' is not. `TYPENAME' can start a
  773. declaration, but `IDENTIFIER' cannot. In contexts where the meaning
  774. of the identifier is *not* significant, such as in declarations that
  775. can shadow a typedef name, either `TYPENAME' or `IDENTIFIER' is
  776. accepted--there is one rule for each of the two token types.
  777. This technique is simple to use if the decision of which kinds of
  778. identifiers to allow is made at a place close to where the identifier
  779. is parsed. But in C this is not always so: C allows a declaration to
  780. redeclare a typedef name provided an explicit type has been specified
  781. earlier:
  782. typedef int foo, bar, lose;
  783. static foo (bar); /* redeclare `bar' as static variable */
  784. static int foo (lose); /* redeclare `foo' as function */
  785. Unfortunately, the name being declared is separated from the
  786. declaration construct itself by a complicated syntactic
  787. structure--the ``declarator''.
  788. As a result, the part of Bison parser for C needs to be duplicated,
  789. with all the nonterminal names changed: once for parsing a
  790. declaration in which a typedef name can be redefined, and once for
  791. parsing a declaration in which that can't be done. Here is a part of
  792. the duplication, with actions omitted for brevity:
  793. initdcl:
  794. declarator maybeasm '='
  795. init
  796. | declarator maybeasm
  797. ;
  798. notype_initdcl:
  799. notype_declarator maybeasm '='
  800. init
  801. | notype_declarator maybeasm
  802. ;
  803. Here `initdcl' can redeclare a typedef name, but `notype_initdcl'
  804. cannot. The distinction between `declarator' and `notype_declarator'
  805. is the same sort of thing.
  806. There is some similarity between this technique and a lexical tie-in
  807. (described next), in that information which alters the lexical
  808. analysis is changed during parsing by other parts of the program.
  809. The difference is here the information is global, and is used for
  810. other purposes in the program. A true lexical tie-in has a
  811. special-purpose flag controlled by the syntactic context.
  812. 
  813. File: bison.info, Node: Lexical Tie-ins, Next: Tie-in Recovery, Prev: Semantic Tokens, Up: Context Dependency
  814. Lexical Tie-ins
  815. ===============
  816. One way to handle context-dependency is the "lexical tie-in": a flag
  817. which is set by Bison actions, whose purpose is to alter the way
  818. tokens are parsed.
  819. For example, suppose we have a language vaguely like C, but with a
  820. special construct `hex (HEX-EXPR)'. After the keyword `hex' comes an
  821. expression in parentheses in which all integers are hexadecimal. In
  822. particular, the token `a1b' must be treated as an integer rather than
  823. as an identifier if it appears in that context. Here is how you can
  824. do it:
  825. %{
  826. int hexflag;
  827. %}
  828. %%
  829. ...
  830. expr: IDENTIFIER
  831. | constant
  832. | HEX '('
  833. { hexflag = 1; }
  834. expr ')'
  835. { hexflag = 0;
  836. $$ = $4; }
  837. | expr '+' expr
  838. { $$ = make_sum ($1, $3); }
  839. ...
  840. ;
  841. constant:
  842. INTEGER
  843. | STRING
  844. ;
  845. Here we assume that `yylex' looks at the value of `hexflag'; when it
  846. is nonzero, all integers are parsed in hexadecimal, and tokens
  847. starting with letters are parsed as integers if possible.
  848. The declaration of `hexflag' shown in the C declarations section of
  849. the parser file is needed to make it accessible to the actions (*note
  850. C Declarations::.). You must also write the code in `yylex' to obey
  851. the flag.
  852. 
  853. File: bison.info, Node: Tie-in Recovery, Prev: Lexical Tie-ins, Up: Context Dependency
  854. Lexical Tie-ins and Error Recovery
  855. ==================================
  856. Lexical tie-ins make strict demands on any error recovery rules you
  857. have. *Note Error Recovery::.
  858. The reason for this is that the purpose of an error recovery rule is
  859. to abort the parsing of one construct and resume in some larger
  860. construct. For example, in C-like languages, a typical error
  861. recovery rule is to skip tokens until the next semicolon, and then
  862. start a new statement, like this:
  863. stmt: expr ';'
  864. | IF '(' expr ')' stmt { ... }
  865. ...
  866. error ';'
  867. { hexflag = 0; }
  868. ;
  869. If there is a syntax error in the middle of a `hex (EXPR)' construct,
  870. this error rule will apply, and then the action for the completed
  871. `hex (EXPR)' will never run. So `hexflag' would remain set for the
  872. entire rest of the input, or until the next `hex' keyword, causing
  873. identifiers to be misinterpreted as integers.
  874. To avoid this problem the error recovery rule itself clears `hexflag'.
  875. There may also be an error recovery rule that works within expressions.
  876. For example, there could be a rule which applies within parentheses
  877. and skips to the close-parenthesis:
  878. expr: ...
  879. | '(' expr ')'
  880. { $$ = $2; }
  881. | '(' error ')'
  882. ...
  883. If this rule acts within the `hex' construct, it is not going to
  884. abort that construct (since it applies to an inner level of
  885. parentheses within the construct). Therefore, it should not clear
  886. the flag: the rest of the `hex' construct should be parsed with the
  887. flag still in effect.
  888. What if there is an error recovery rule which might abort out of the
  889. `hex' construct or might not, depending on circumstances? There is
  890. no way you can write the action to determine whether a `hex'
  891. construct is being aborted or not. So if you are using a lexical
  892. tie-in, you had better make sure your error recovery rules are not of
  893. this kind. Each rule must be such that you can be sure that it
  894. always will, or always won't, have to clear the flag.
  895. 
  896. File: bison.info, Node: Debugging, Next: Invocation, Prev: Context Dependency, Up: Top
  897. Debugging Your Parser
  898. *********************
  899. If a Bison grammar compiles properly but doesn't do what you want
  900. when it runs, the `yydebug' parser-trace feature can help you figure
  901. out why.
  902. To enable compilation of trace facilities, you must define the macro
  903. `YYDEBUG' when you compile the parser. You could use `-DYYDEBUG' as
  904. a compiler option or you could put `#define YYDEBUG' in the C
  905. declarations section of the grammar file (*note C Declarations::.).
  906. Alternatively, use the `-t' option when you run Bison (*note
  907. Invocation::.). I always define `YYDEBUG' so that debugging is
  908. always possible.
  909. The trace facility uses `stderr', so you must add
  910. `#include <stdio.h>' to the C declarations section unless it is
  911. already there.
  912. Once you have compiled the program with trace facilities, the way to
  913. request a trace is to store a nonzero value in the variable `yydebug'.
  914. You can do this by making the C code do it (in `main', perhaps), or
  915. you can alter the value with a C debugger.
  916. Each step taken by the parser when `yydebug' is nonzero produces a
  917. line or two of trace information, written on `stderr'. The trace
  918. messages tell you these things:
  919. * Each time the parser calls `yylex', what kind of token was read.
  920. * Each time a token is shifted, the depth and complete contents of
  921. the state stack (*note Parser States::.).
  922. * Each time a rule is reduced, which rule it is, and the complete
  923. contents of the state stack afterward.
  924. To make sense of this information, it helps to refer to the listing
  925. file produced by the Bison `-v' option (*note Invocation::.). This
  926. file shows the meaning of each state in terms of positions in various
  927. rules, and also what each state will do with each possible input
  928. token. As you read the successive trace messages, you can see that
  929. the parser is functioning according to its specification in the
  930. listing file. Eventually you will arrive at the place where
  931. something undesirable happens, and you will see which parts of the
  932. grammar are to blame.
  933. The parser file is a C program and you can use C debuggers on it, but
  934. it's not easy to interpret what it is doing. The parser function is
  935. a finite-state machine interpreter, and aside from the actions it
  936. executes the same code over and over. Only the values of variables
  937. show where in the grammar it is working.
  938. 
  939. File: bison.info, Node: Invocation, Next: Table of Symbols, Prev: Debugging, Up: Top
  940. Invocation of Bison; Command Options
  941. ************************************
  942. The usual way to invoke Bison is as follows:
  943. bison INFILE
  944. Here INFILE is the grammar file name, which usually ends in `.y'.
  945. The parser file's name is made by replacing the `.y' with `.tab.c'.
  946. Thus, `bison foo.y' outputs `foo.tab.c', and `bison hack/foo.y'
  947. outputs `hack/foo.tab.c'.
  948. These options can be used with Bison:
  949. `-d'
  950. Write an extra output file containing macro definitions for the
  951. token type names defined in the grammar and the semantic value
  952. type `YYSTYPE', as well as a few `extern' variable declarations.
  953. If the parser output file is named `NAME.c' then this file is
  954. named `NAME.h'.
  955. This output file is essential if you wish to put the definition
  956. of `yylex' in a separate source file, because `yylex' needs to
  957. be able to refer to token type codes and the variable `yylval'.
  958. *Note Token Values::.
  959. `-l'
  960. Don't put any `#line' preprocessor commands in the parser file.
  961. Ordinarily Bison puts them in the parser file so that the C
  962. compiler and debuggers will associate errors with your source
  963. file, the grammar file. This option causes them to associate
  964. errors with the parser file, treating it an independent source
  965. file in its own right.
  966. `-o OUTFILE'
  967. Specify the name OUTFILE for the parser file.
  968. The other output files' names are constructed from OUTFILE as
  969. described under the `-v' and `-d' switches.
  970. `-t'
  971. Output a definition of the macro `YYDEBUG' into the parser file,
  972. so that the debugging facilities are compiled. *Note Debugging::.
  973. `-v'
  974. Write an extra output file containing verbose descriptions of
  975. the parser states and what is done for each type of look-ahead
  976. token in that state.
  977. This file also describes all the conflicts, both those resolved
  978. by operator precedence and the unresolved ones.
  979. The file's name is made by removing `.tab.c' or `.c' from the
  980. parser output file name, and adding `.output' instead.
  981. Therefore, if the input file is `foo.y', then the parser file is
  982. called `foo.tab.c' by default. As a consequence, the verbose
  983. output file is called `foo.output'.
  984. `-y'
  985. Equivalent to `-o y.tab.c'; the parser output file is called
  986. `y.tab.c', and the other outputs are called `y.output' and
  987. `y.tab.h'. The purpose of this switch is to imitate Yacc's
  988. output file name conventions.