BISON-2.INF 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  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: Infix Calc, Next: Simple Error Recovery, Prev: RPN Calc, Up: Examples
  23. Infix Notation Calculator: `calc'
  24. =================================
  25. We now modify rpcalc to handle infix operators instead of postfix.
  26. Infix notation involves the concept of operator precedence and the
  27. need for parentheses nested to arbitrary depth. Here is the Bison
  28. code for `calc.y', an infix desk-top calculator.
  29. /* Infix notation calculator--calc */
  30. %{
  31. #define YYSTYPE double
  32. #include <math.h>
  33. %}
  34. %token NUM
  35. %left '-' '+'
  36. %left '*' '/'
  37. %left NEG /* negation--unary minus */
  38. %right '^' /* exponentiation */
  39. /* Grammar follows */
  40. %%
  41. input: /* empty string */
  42. | input line
  43. ;
  44. line: '\n'
  45. | exp '\n' { printf("\t%.10g\n", $1); }
  46. ;
  47. exp: NUM { $$ = $1; }
  48. | exp '+' exp { $$ = $1 + $3; }
  49. | exp '-' exp { $$ = $1 - $3; }
  50. | exp '*' exp { $$ = $1 * $3; }
  51. | exp '/' exp { $$ = $1 / $3; }
  52. | '-' exp %prec NEG { $$ = -$2; }
  53. | exp '^' exp { $$ = pow ($1, $3); }
  54. | '(' exp ')' { $$ = $2; }
  55. ;
  56. %%
  57. The functions `yylex', `yyerror' and `main' can be the same as before.
  58. There are two important new features shown in this code.
  59. In the second section (Bison declarations), `%left' declares token
  60. types and says they are left-associative operators. The declarations
  61. `%left' and `%right' (right associativity) take the place of `%token'
  62. which is used to declare a token type name without associativity.
  63. (These tokens are single-character literals, which ordinarily don't
  64. need to be declared. We declare them here to specify the
  65. associativity.)
  66. Operator precedence is determined by the line ordering of the
  67. declarations; the lower the declaration, the higher the precedence.
  68. Hence, exponentiation has the highest precedence, unary minus (`NEG')
  69. is next, followed by `*' and `/', and so on. *Note Precedence::.
  70. The other important new feature is the `%prec' in the grammar section
  71. for the unary minus operator. The `%prec' simply instructs Bison
  72. that the rule `| '-' exp' has the same precedence as `NEG'--in this
  73. case the next-to-highest. *Note Contextual Precedence::.
  74. Here is a sample run of `calc.y':
  75. % calc
  76. 4 + 4.5 - (34/(8*3+-3))
  77. 6.880952381
  78. -56 + 2
  79. -54
  80. 3 ^ 2
  81. 9
  82. 
  83. File: bison.info, Node: Simple Error Recovery, Next: Multi-function Calc, Prev: Infix Calc, Up: Examples
  84. Simple Error Recovery
  85. =====================
  86. Up to this point, this manual has not addressed the issue of "error
  87. recovery"--how to continue parsing after the parser detects a syntax
  88. error. All we have handled is error reporting with `yyerror'.
  89. Recall that by default `yyparse' returns after calling `yyerror'.
  90. This means that an erroneous input line causes the calculator program
  91. to exit. Now we show how to rectify this deficiency.
  92. The Bison language itself includes the reserved word `error', which
  93. may be included in the grammar rules. In the example below it has
  94. been added to one of the alternatives for `line':
  95. line: '\n'
  96. | exp '\n' { printf("\t%.10g\n", $1); }
  97. | error '\n' { yyerrok; }
  98. ;
  99. This addition to the grammar allows for simple error recovery in the
  100. event of a parse error. If an expression that cannot be evaluated is
  101. read, the error will be recognized by the third rule for `line', and
  102. parsing will continue. (The `yyerror' function is still called upon
  103. to print its message as well.) The action executes the statement
  104. `yyerrok', a macro defined automatically by Bison; its meaning is
  105. that error recovery is complete (*note Error Recovery::.). Note the
  106. difference between `yyerrok' and `yyerror'; neither one is a misprint.
  107. This form of error recovery deals with syntax errors. There are
  108. other kinds of errors; for example, division by zero, which raises an
  109. exception signal that is normally fatal. A real calculator program
  110. must handle this signal and use `longjmp' to return to `main' and
  111. resume parsing input lines; it would also have to discard the rest of
  112. the current line of input. We won't discuss this issue further
  113. because it is not specific to Bison programs.
  114. 
  115. File: bison.info, Node: Multi-function Calc, Next: Exercises, Prev: Simple Error Recovery, Up: Examples
  116. Multi-Function Calculator: `mfcalc'
  117. ===================================
  118. Now that the basics of Bison have been discussed, it is time to move
  119. on to a more advanced problem. The above calculators provided only
  120. five functions, `+', `-', `*', `/' and `^'. It would be nice to have
  121. a calculator that provides other mathematical functions such as
  122. `sin', `cos', etc.
  123. It is easy to add new operators to the infix calculator as long as
  124. they are only single-character literals. The lexical analyzer
  125. `yylex' passes back all non-number characters as tokens, so new
  126. grammar rules suffice for adding a new operator. But we want
  127. something more flexible: built-in functions whose syntax has this form:
  128. FUNCTION_NAME (ARGUMENT)
  129. At the same time, we will add memory to the calculator, by allowing
  130. you to create named variables, store values in them, and use them
  131. later. Here is a sample session with the multi-function calculator:
  132. % acalc
  133. pi = 3.141592653589
  134. 3.1415926536
  135. sin(pi)
  136. 0.0000000000
  137. alpha = beta1 = 2.3
  138. 2.3000000000
  139. alpha
  140. 2.3000000000
  141. ln(alpha)
  142. 0.8329091229
  143. exp(ln(beta1))
  144. 2.3000000000
  145. %
  146. Note that multiple assignment and nested function calls are permitted.
  147. * Menu:
  148. * Decl: Mfcalc Decl. Bison declarations for multi-function calculator.
  149. * Rules: Mfcalc Rules. Grammar rules for the calculator.
  150. * Symtab: Mfcalc Symtab. Symbol table management subroutines.
  151. 
  152. File: bison.info, Node: Mfcalc Decl, Next: Mfcalc Rules, Prev: Multi-function Calc, Up: Multi-function Calc
  153. Declarations for `mfcalc'
  154. -------------------------
  155. Here are the C and Bison declarations for the multi-function
  156. calculator.
  157. %{
  158. #include <math.h> /* For math functions, cos(), sin(), etc */
  159. #include "calc.h" /* Contains definition of `symrec' */
  160. %}
  161. %union {
  162. double val; /* For returning numbers. */
  163. symrec *tptr; /* For returning symbol-table pointers */
  164. }
  165. %token <val> NUM /* Simple double precision number */
  166. %token <tptr> VAR FNCT /* Variable and Function */
  167. %type <val> exp
  168. %right '='
  169. %left '-' '+'
  170. %left '*' '/'
  171. %left NEG /* Negation--unary minus */
  172. %right '^' /* Exponentiation */
  173. /* Grammar follows */
  174. %%
  175. The above grammar introduces only two new features of the Bison
  176. language. These features allow semantic values to have various data
  177. types (*note Multiple Types::.).
  178. The `%union' declaration specifies the entire list of possible types;
  179. this is instead of defining `YYSTYPE'. The allowable types are now
  180. double-floats (for `exp' and `NUM') and pointers to entries in the
  181. symbol table. *Note Union Decl::.
  182. Since values can now have various types, it is necessary to associate
  183. a type with each grammar symbol whose semantic value is used. These
  184. symbols are `NUM', `VAR', `FNCT', and `exp'. Their declarations are
  185. augmented with information about their data type (placed between
  186. angle brackets).
  187. The Bison construct `%type' is used for declaring nonterminal
  188. symbols, just as `%token' is used for declaring token types. We have
  189. not used `%type' before because nonterminal symbols are normally
  190. declared implicitly by the rules that define them. But `exp' must be
  191. declared explicitly so we can specify its value type. *Note Type
  192. Decl::.
  193. 
  194. File: bison.info, Node: Mfcalc Rules, Next: Mfcalc Symtab, Prev: Mfcalc Decl, Up: Multi-function Calc
  195. Grammar Rules for `mfcalc'
  196. --------------------------
  197. Here are the grammar rules for the multi-function calculator. Most
  198. of them are copied directly from `calc'; three rules, those which
  199. mention `VAR' or `FNCT', are new.
  200. input: /* empty */
  201. | input line
  202. ;
  203. line:
  204. '\n'
  205. | exp '\n' { printf ("\t%.10g\n", $1); }
  206. | error '\n' { yyerrok; }
  207. ;
  208. exp: NUM { $$ = $1; }
  209. | VAR { $$ = $1->value.var; }
  210. | VAR '=' exp { $$ = $3; $1->value.var = $3; }
  211. | FNCT '(' exp ')' { $$ = (*($1->value.fnctptr))($3); }
  212. | exp '+' exp { $$ = $1 + $3; }
  213. | exp '-' exp { $$ = $1 - $3; }
  214. | exp '*' exp { $$ = $1 * $3; }
  215. | exp '/' exp { $$ = $1 / $3; }
  216. | '-' exp %prec NEG { $$ = -$2; }
  217. | exp '^' exp { $$ = pow ($1, $3); }
  218. | '(' exp ')' { $$ = $2; }
  219. ;
  220. /* End of grammar */
  221. %%
  222. 
  223. File: bison.info, Node: Mfcalc Symtab, Prev: Mfcalc Rules, Up: Multi-function Calc
  224. Managing the Symbol Table for `mfcalc'
  225. --------------------------------------
  226. The multi-function calculator requires a symbol table to keep track
  227. of the names and meanings of variables and functions. This doesn't
  228. affect the grammar rules (except for the actions) or the Bison
  229. declarations, but it requires some additional C functions for support.
  230. The symbol table itself consists of a linked list of records. Its
  231. definition, which is kept in the header `calc.h', is as follows. It
  232. provides for either functions or variables to be placed in the table.
  233. /* Data type for links in the chain of symbols. */
  234. struct symrec
  235. {
  236. char *name; /* name of symbol */
  237. int type; /* type of symbol: either VAR or FNCT */
  238. union {
  239. double var; /* value of a VAR */
  240. double (*fnctptr)(); /* value of a FNCT */
  241. } value;
  242. struct symrec *next; /* link field */
  243. };
  244. typedef struct symrec symrec;
  245. /* The symbol table: a chain of `struct symrec'. */
  246. extern symrec *sym_table;
  247. symrec *putsym ();
  248. symrec *getsym ();
  249. The new version of `main' includes a call to `init_table', a function
  250. that initializes the symbol table. Here it is, and `init_table' as
  251. well:
  252. #include <stdio.h>
  253. main()
  254. {
  255. init_table ();
  256. yyparse ();
  257. }
  258. yyerror (s) /* Called by yyparse on error */
  259. char *s;
  260. {
  261. printf ("%s\n", s);
  262. }
  263. struct init
  264. {
  265. char *fname;
  266. double (*fnct)();
  267. };
  268. struct init arith_fncts[]
  269. = {
  270. "sin", sin,
  271. "cos", cos,
  272. "atan", atan,
  273. "ln", log,
  274. "exp", exp,
  275. "sqrt", sqrt,
  276. 0, 0
  277. };
  278. /* The symbol table: a chain of `struct symrec'. */
  279. symrec *sym_table = (symrec *)0;
  280. init_table () /* puts arithmetic functions in table. */
  281. {
  282. int i;
  283. symrec *ptr;
  284. for (i = 0; arith_fncts[i].fname != 0; i++)
  285. {
  286. ptr = putsym (arith_fncts[i].fname, FNCT);
  287. ptr->value.fnctptr = arith_fncts[i].fnct;
  288. }
  289. }
  290. By simply editing the initialization list and adding the necessary
  291. include files, you can add additional functions to the calculator.
  292. Two important functions allow look-up and installation of symbols in
  293. the symbol table. The function `putsym' is passed a name and the
  294. type (`VAR' or `FNCT') of the object to be installed. The object is
  295. linked to the front of the list, and a pointer to the object is
  296. returned. The function `getsym' is passed the name of the symbol to
  297. look up. If found, a pointer to that symbol is returned; otherwise
  298. zero is returned.
  299. symrec *
  300. putsym (sym_name,sym_type)
  301. char *sym_name;
  302. int sym_type;
  303. {
  304. symrec *ptr;
  305. ptr = (symrec *) malloc (sizeof(symrec));
  306. ptr->name = (char *) malloc (strlen(sym_name)+1);
  307. strcpy (ptr->name,sym_name);
  308. ptr->type = sym_type;
  309. ptr->value.var = 0; /* set value to 0 even if fctn. */
  310. ptr->next = (struct symrec *)sym_table;
  311. sym_table = ptr;
  312. return ptr;
  313. }
  314. symrec *
  315. getsym (sym_name)
  316. char *sym_name;
  317. {
  318. symrec *ptr;
  319. for (ptr = sym_table; ptr != (symrec *) 0;
  320. ptr = (symrec *)ptr->next)
  321. if (strcmp (ptr->name,sym_name) == 0)
  322. return ptr;
  323. return 0;
  324. }
  325. The function `yylex' must now recognize variables, numeric values,
  326. and the single-character arithmetic operators. Strings of
  327. alphanumeric characters with a leading nondigit are recognized as
  328. either variables or functions depending on what the symbol table says
  329. about them.
  330. The string is passed to `getsym' for look up in the symbol table. If
  331. the name appears in the table, a pointer to its location and its type
  332. (`VAR' or `FNCT') is returned to `yyparse'. If it is not already in
  333. the table, then it is installed as a `VAR' using `putsym'. Again, a
  334. pointer and its type (which must be `VAR') is returned to `yyparse'.
  335. No change is needed in the handling of numeric values and arithmetic
  336. operators in `yylex'.
  337. #include <ctype.h>
  338. yylex()
  339. {
  340. int c;
  341. /* Ignore whitespace, get first nonwhite character. */
  342. while ((c = getchar ()) == ' ' || c == '\t');
  343. if (c == EOF)
  344. return 0;
  345. /* Char starts a number => parse the number. */
  346. if (c == '.' || isdigit (c))
  347. {
  348. ungetc (c, stdin);
  349. scanf ("%lf", &yylval.val);
  350. return NUM;
  351. }
  352. /* Char starts an identifier => read the name. */
  353. if (isalpha (c))
  354. {
  355. symrec *s;
  356. static char *symbuf = 0;
  357. static int length = 0;
  358. int i;
  359. /* Initially make the buffer long enough
  360. for a 40-character symbol name. */
  361. if (length == 0)
  362. length = 40, symbuf = (char *)malloc (length + 1);
  363. i = 0;
  364. do
  365. {
  366. /* If buffer is full, make it bigger. */
  367. if (i == length)
  368. {
  369. length *= 2;
  370. symbuf = (char *)realloc (symbuf, length + 1);
  371. }
  372. /* Add this character to the buffer. */
  373. symbuf[i++] = c;
  374. /* Get another character. */
  375. c = getchar ();
  376. }
  377. while (c != EOF && isalnum (c));
  378. ungetc (c, stdin);
  379. symbuf[i] = '\0';
  380. s = getsym (symbuf);
  381. if (s == 0)
  382. s = putsym (symbuf, VAR);
  383. yylval.tptr = s;
  384. return s->type;
  385. }
  386. /* Any other character is a token by itself. */
  387. return c;
  388. }
  389. This program is both powerful and flexible. You may easily add new
  390. functions, and it is a simple job to modify this code to install
  391. predefined variables such as `pi' or `e' as well.
  392. 
  393. File: bison.info, Node: Exercises, Prev: Multi-function calc, Up: Examples
  394. Exercises
  395. =========
  396. 1. Add some new functions from `math.h' to the initialization list.
  397. 2. Add another array that contains constants and their values.
  398. Then modify `init_table' to add these constants to the symbol
  399. table. It will be easiest to give the constants type `VAR'.
  400. 3. Make the program report an error if the user refers to an
  401. uninitialized variable in any way except to store a value in it.
  402. 
  403. File: bison.info, Node: Grammar File, Next: Interface, Prev: Examples, Up: Top
  404. Bison Grammar Files
  405. *******************
  406. Bison takes as input a context-free grammar specification and
  407. produces a C-language function that recognizes correct instances of
  408. the grammar.
  409. The Bison grammar input file conventionally has a name ending in `.y'.
  410. * Menu:
  411. * Grammar Outline:: Overall layout of the grammar file.
  412. * Symbols:: Terminal and nonterminal symbols.
  413. * Rules:: How to write grammar rules.
  414. * Recursion:: Writing recursive rules.
  415. * Semantics:: Semantic values and actions.
  416. * Declarations:: All kinds of Bison declarations are described here.
  417. * Multiple Parsers:: Putting more than one Bison parser in one program.
  418. 
  419. File: bison.info, Node: Grammar Outline, Next: Symbols, Prev: Grammar File, Up: Grammar File
  420. Outline of a Bison Grammar
  421. ==========================
  422. A Bison grammar file has four main sections, shown here with the
  423. appropriate delimiters:
  424. %{
  425. C DECLARATIONS
  426. %}
  427. BISON DECLARATIONS
  428. %%
  429. GRAMMAR RULES
  430. %%
  431. ADDITIONAL C CODE
  432. Comments enclosed in `/* ... */' may appear in any of the sections.
  433. * Menu:
  434. * C Declarations:: Syntax and usage of the C declarations section.
  435. * Bison Declarations:: Syntax and usage of the Bison declarations section.
  436. * Grammar Rules:: Syntax and usage of the grammar rules section.
  437. * C Code:: Syntax and usage of the additional C code section.
  438. 
  439. File: bison.info, Node: C Declarations, Next: Bison Declarations, Prev: Grammar Outline, Up: Grammar Outline
  440. The C Declarations Section
  441. --------------------------
  442. The C DECLARATIONS section contains macro definitions and
  443. declarations of functions and variables that are used in the actions
  444. in the grammar rules. These are copied to the beginning of the
  445. parser file so that they precede the definition of `yylex'. You can
  446. use `#include' to get the declarations from a header file. If you
  447. don't need any C declarations, you may omit the `%{' and `%}'
  448. delimiters that bracket this section.
  449. 
  450. File: bison.info, Node: Bison Declarations, Next: Grammar Rules, Prev: C Declarations, Up: Grammar Outline
  451. The Bison Declarations Section
  452. ------------------------------
  453. The BISON DECLARATIONS section contains declarations that define
  454. terminal and nonterminal symbols, specify precedence, and so on. In
  455. some simple grammars you may not need any declarations. *Note
  456. Declarations::.
  457. 
  458. File: bison.info, Node: Grammar Rules, Next: C Code, Prev: Bison Declarations, Up: Grammar Outline
  459. The Grammar Rules Section
  460. -------------------------
  461. The "grammar rules" section contains one or more Bison grammar rules,
  462. and nothing else. *Note Rules::.
  463. There must always be at least one grammar rule, and the first `%%'
  464. (which precedes the grammar rules) may never be omitted even if it is
  465. the first thing in the file.
  466. 
  467. File: bison.info, Node: C Code, Prev: Grammar Rules, Up: Grammar Outline
  468. The Additional C Code Section
  469. -----------------------------
  470. The ADDITIONAL C CODE section is copied verbatim to the end of the
  471. parser file, just as the C DECLARATIONS section is copied to the
  472. beginning. This is the most convenient place to put anything that
  473. you want to have in the parser file but which need not come before
  474. the definition of `yylex'. For example, the definitions of `yylex'
  475. and `yyerror' often go here. *Note Interface::.
  476. If the last section is empty, you may omit the `%%' that separates it
  477. from the grammar rules.
  478. The Bison parser itself contains many static variables whose names
  479. start with `yy' and many macros whose names start with `YY'. It is a
  480. good idea to avoid using any such names (except those documented in
  481. this manual) in the additional C code section of the grammar file.
  482. 
  483. File: bison.info, Node: Symbols, Next: Rules, Prev: Grammar Outline, Up: Grammar File
  484. Symbols, Terminal and Nonterminal
  485. =================================
  486. "Symbols" in Bison grammars represent the grammatical classifications
  487. of the language.
  488. A "terminal symbol" (also known as a "token type") represents a class
  489. of syntactically equivalent tokens. You use the symbol in grammar
  490. rules to mean that a token in that class is allowed. The symbol is
  491. represented in the Bison parser by a numeric code, and the `yylex'
  492. function returns a token type code to indicate what kind of token has
  493. been read. You don't need to know what the code value is; you can
  494. use the symbol to stand for it.
  495. A "nonterminal symbol" stands for a class of syntactically equivalent
  496. groupings. The symbol name is used in writing grammar rules. By
  497. convention, it should be all lower case.
  498. Symbol names can contain letters, digits (not at the beginning),
  499. underscores and periods. Periods make sense only in nonterminals.
  500. There are two ways of writing terminal symbols in the grammar:
  501. * A "named token type" is written with an identifier, like an
  502. identifier in C. By convention, it should be all upper case.
  503. Each such name must be defined with a Bison declaration such as
  504. `%token'. *Note Token Decl::.
  505. * A "character token type" (or "literal token") is written in the
  506. grammar using the same syntax used in C for character constants;
  507. for example, `'+'' is a character token type. A character token
  508. type doesn't need to be declared unless you need to specify its
  509. semantic value data type (*note Value Type::.), associativity,
  510. or precedence (*note Precedence::.).
  511. By convention, a character token type is used only to represent
  512. a token that consists of that particular character. Thus, the
  513. token type `'+'' is used to represent the character `+' as a
  514. token. Nothing enforces this convention, but if you depart from
  515. it, your program will confuse other readers.
  516. All the usual escape sequences used in character literals in C
  517. can be used in Bison as well, but you must not use the null
  518. character as a character literal because its ASCII code, zero,
  519. is the code `yylex' returns for end-of-input (*note Calling
  520. Convention::.).
  521. How you choose to write a terminal symbol has no effect on its
  522. grammatical meaning. That depends only on where it appears in rules
  523. and on when the parser function returns that symbol.
  524. The value returned by `yylex' is always one of the terminal symbols
  525. (or 0 for end-of-input). Whichever way you write the token type in
  526. the grammar rules, you write it the same way in the definition of
  527. `yylex'. The numeric code for a character token type is simply the
  528. ASCII code for the character, so `yylex' can use the identical
  529. character constant to generate the requisite code. Each named token
  530. type becomes a C macro in the parser file, so `yylex' can use the
  531. name to stand for the code. (This is why periods don't make sense in
  532. terminal symbols.) *Note Calling Convention::.
  533. If `yylex' is defined in a separate file, you need to arrange for the
  534. token-type macro definitions to be available there. Use the `-d'
  535. option when you run Bison, so that it will write these macro
  536. definitions into a separate header file `NAME.tab.h' which you can
  537. include in the other source files that need it. *Note Invocation::.
  538. The symbol `error' is a terminal symbol reserved for error recovery
  539. (*note Error Recovery::.); you shouldn't use it for any other purpose.
  540. In particular, `yylex' should never return this value.
  541. 
  542. File: bison.info, Node: Rules, Next: Recursion, Prev: Symbols, Up: Grammar File
  543. Syntax of Grammar Rules
  544. =======================
  545. A Bison grammar rule has the following general form:
  546. RESULT: COMPONENTS...
  547. ;
  548. where RESULT is the nonterminal symbol that this rule describes and
  549. COMPONENTS are various terminal and nonterminal symbols that are put
  550. together by this rule (*note Symbols::.). For example,
  551. exp: exp '+' exp
  552. ;
  553. says that two groupings of type `exp', with a `+' token in between,
  554. can be combined into a larger grouping of type `exp'.
  555. Whitespace in rules is significant only to separate symbols. You can
  556. add extra whitespace as you wish.
  557. Scattered among the components can be ACTIONS that determine the
  558. semantics of the rule. An action looks like this:
  559. {C STATEMENTS}
  560. Usually there is only one action and it follows the components.
  561. *Note Actions::.
  562. Multiple rules for the same RESULT can be written separately or can
  563. be joined with the vertical-bar character `|' as follows:
  564. RESULT: RULE1-COMPONENTS...
  565. | RULE2-COMPONENTS...
  566. ...
  567. ;
  568. They are still considered distinct rules even when joined in this way.
  569. If COMPONENTS in a rule is empty, it means that RESULT can match the
  570. empty string. For example, here is how to define a comma-separated
  571. sequence of zero or more `exp' groupings:
  572. expseq: /* empty */
  573. | expseq1
  574. ;
  575. expseq1: exp
  576. | expseq1 ',' exp
  577. ;
  578. It is customary to write a comment `/* empty */' in each rule with no
  579. components.
  580. 
  581. File: bison.info, Node: Recursion, Next: Semantics, Prev: Rules, Up: Grammar File
  582. Recursive Rules
  583. ===============
  584. A rule is called "recursive" when its RESULT nonterminal appears also
  585. on its right hand side. Nearly all Bison grammars need to use
  586. recursion, because that is the only way to define a sequence of any
  587. number of somethings. Consider this recursive definition of a
  588. comma-separated sequence of one or more expressions:
  589. expseq1: exp
  590. | expseq1 ',' exp
  591. ;
  592. Since the recursive use of `expseq1' is the leftmost symbol in the
  593. right hand side, we call this "left recursion". By contrast, here
  594. the same construct is defined using "right recursion":
  595. expseq1: exp
  596. | exp ',' expseq1
  597. ;
  598. Any kind of sequence can be defined using either left recursion or
  599. right recursion, but you should always use left recursion, because it
  600. can parse a sequence of any number of elements with bounded stack
  601. space. Right recursion uses up space on the Bison stack in
  602. proportion to the number of elements in the sequence, because all the
  603. elements must be shifted onto the stack before the rule can be
  604. applied even once. *Note Algorithm::, for further explanation of this.
  605. "Indirect" or "mutual" recursion occurs when the result of the rule
  606. does not appear directly on its right hand side, but does appear in
  607. rules for other nonterminals which do appear on its right hand side.
  608. For example:
  609. expr: primary
  610. | primary '+' primary
  611. ;
  612. primary: constant
  613. | '(' expr ')'
  614. ;
  615. defines two mutually-recursive nonterminals, since each refers to the
  616. other.
  617. 
  618. File: bison.info, Node: Semantics, Next: Declarations, Prev: Recursion, Up: Grammar File
  619. The Semantics of the Language
  620. =============================
  621. The grammar rules for a language determine only the syntax. The
  622. semantics are determined by the semantic values associated with
  623. various tokens and groupings, and by the actions taken when various
  624. groupings are recognized.
  625. For example, the calculator calculates properly because the value
  626. associated with each expression is the proper number; it adds
  627. properly because the action for the grouping `X + Y' is to add the
  628. numbers associated with X and Y.
  629. * Menu:
  630. * Value Type:: Specifying one data type for all semantic values.
  631. * Multiple Types:: Specifying several alternative data types.
  632. * Actions:: An action is the semantic definition of a grammar rule.
  633. * Action Types:: Specifying data types for actions to operate on.
  634. * Mid-Rule Actions:: Most actions go at the end of a rule.
  635. This says when, why and how to use the exceptional
  636. action in the middle of a rule.
  637. 
  638. File: bison.info, Node: Value Type, Next: Multiple Types, Prev: Semantics, Up: Semantics
  639. The Data Types of Semantic Values
  640. ---------------------------------
  641. In a simple program it may be sufficient to use the same data type
  642. for the semantic values of all language constructs. This was true in
  643. the RPN and infix calculator examples (*note RPN Calc::.).
  644. Bison's default is to use type `int' for all semantic values. To
  645. specify some other type, define `YYSTYPE' as a macro, like this:
  646. #define YYSTYPE double
  647. This macro definition must go in the C declarations section of the
  648. grammar file (*note Grammar Outline::.).
  649. 
  650. File: bison.info, Node: Multiple Types, Next: Actions, Prev: Value Type, Up: Semantics
  651. More Than One Type for Semantic Values
  652. --------------------------------------
  653. In most programs, you will need different data types for different
  654. kinds of tokens and groupings. For example, a numeric constant may
  655. need type `int' or `long', while a string constant needs type `char
  656. *', and an identifier might need a pointer to an entry in the symbol
  657. table.
  658. To use more than one data type for semantic values in one parser,
  659. Bison requires you to do two things:
  660. * Specify the entire collection of possible data types, with the
  661. `%union' Bison declaration (*note Union Decl::.).
  662. * Choose one of those types for each symbol (terminal or
  663. nonterminal) for which semantic values are used. This is done
  664. for tokens with the `%token' Bison declaration (*note Token
  665. Decl::.) and for groupings with the `%type' Bison declaration
  666. (*note Type Decl::.).
  667. 
  668. File: bison.info, Node: Actions, Next: Action Types, Prev: Multiple Types, Up: Semantics
  669. Actions
  670. -------
  671. An action accompanies a syntactic rule and contains C code to be
  672. executed each time an instance of that rule is recognized. The task
  673. of most actions is to compute a semantic value for the grouping built
  674. by the rule from the semantic values associated with tokens or
  675. smaller groupings.
  676. An action consists of C statements surrounded by braces, much like a
  677. compound statement in C. It can be placed at any position in the
  678. rule; it is executed at that position. Most rules have just one
  679. action at the end of the rule, following all the components. Actions
  680. in the middle of a rule are tricky and used only for special purposes
  681. (*note Mid-Rule Actions::.).
  682. The C code in an action can refer to the semantic values of the
  683. components matched by the rule with the construct `$N', which stands
  684. for the value of the Nth component. The semantic value for the
  685. grouping being constructed is `$$'. (Bison translates both of these
  686. constructs into array element references when it copies the actions
  687. into the parser file.)
  688. Here is a typical example:
  689. exp: ...
  690. | exp '+' exp
  691. { $$ = $1 + $3; }
  692. This rule constructs an `exp' from two smaller `exp' groupings
  693. connected by a plus-sign token. In the action, `$1' and `$3' refer
  694. to the semantic values of the two component `exp' groupings, which
  695. are the first and third symbols on the right hand side of the rule.
  696. The sum is stored into `$$' so that it becomes the semantic value of
  697. the addition-expression just recognized by the rule. If there were a
  698. useful semantic value associated with the `+' token, it could be
  699. referred to as `$2'.
  700. `$N' with N zero or negative is allowed for reference to tokens and
  701. groupings on the stack *before* those that match the current rule.
  702. This is a very risky practice, and to use it reliably you must be
  703. certain of the context in which the rule is applied. Here is a case
  704. in which you can use this reliably:
  705. foo: expr bar '+' expr { ... }
  706. | expr bar '-' expr { ... }
  707. ;
  708. bar: /* empty */
  709. { previous_expr = $0; }
  710. ;
  711. As long as `bar' is used only in the fashion shown here, `$0' always
  712. refers to the `expr' which precedes `bar' in the definition of `foo'.
  713. 
  714. File: bison.info, Node: Action Types, Next: Mid-Rule Actions, Prev: Actions, Up: Semantics
  715. Data Types of Values in Actions
  716. -------------------------------
  717. If you have chosen a single data type for semantic values, the `$$'
  718. and `$N' constructs always have that data type.
  719. If you have used `%union' to specify a variety of data types, then
  720. you must declare a choice among these types for each terminal or
  721. nonterminal symbol that can have a semantic value. Then each time
  722. you use `$$' or `$N', its data type is determined by which symbol it
  723. refers to in the rule. In this example,
  724. exp: ...
  725. | exp '+' exp
  726. { $$ = $1 + $3; }
  727. `$3' and `$$' refer to instances of `exp', so they all have the data
  728. type declared for the nonterminal symbol `exp'. If `$2' were used,
  729. it would have the data type declared for the terminal symbol `'+'',
  730. whatever that might be.
  731. Alternatively, you can specify the data type when you refer to the
  732. value, by inserting `<TYPE>' after the `$' at the beginning of the
  733. reference. For example, if you have defined types as shown here:
  734. %union {
  735. int itype;
  736. double dtype;
  737. }
  738. then you can write `$<itype>1' to refer to the first subunit of the
  739. rule as an integer, or `$<dtype>1' to refer to it as a double.
  740. 
  741. File: bison.info, Node: Mid-Rule Actions, Prev: Action Types, Up: Semantics
  742. Actions in Mid-Rule
  743. -------------------
  744. Occasionally it is useful to put an action in the middle of a rule.
  745. These actions are written just like usual end-of-rule actions, but
  746. they are executed before the parser even recognizes the following
  747. components.
  748. A mid-rule action may refer to the components preceding it using
  749. `$N', but it may not refer to subsequent components because it is run
  750. before they are parsed.
  751. The mid-rule action itself counts as one of the components of the rule.
  752. This makes a difference when there is another action later in the
  753. same rule (and usually there is another at the end): you have to
  754. count the actions along with the symbols when working out which
  755. number N to use in `$N'.
  756. The mid-rule action can also have a semantic value. This can be set
  757. within that action by an assignment to `$$', and can referred to by
  758. later actions using `$N'. Since there is no symbol to name the
  759. action, there is no way to declare a data type for the value in
  760. advance, so you must use the `$<...>' construct to specify a data
  761. type each time you refer to this value.
  762. Here is an example from a hypothetical compiler, handling a `let'
  763. statement that looks like `let (VARIABLE) STATEMENT' and serves to
  764. create a variable named VARIABLE temporarily for the duration of
  765. STATEMENT. To parse this construct, we must put VARIABLE into the
  766. symbol table while STATEMENT is parsed, then remove it afterward.
  767. Here is how it is done:
  768. stmt: LET '(' var ')'
  769. { $<context>$ = push_context ();
  770. declare_variable ($3); }
  771. stmt { $$ = $6;
  772. pop_context ($<context>5); }
  773. As soon as `let (VARIABLE)' has been recognized, the first action is
  774. run. It saves a copy of the current semantic context (the list of
  775. accessible variables) as its semantic value, using alternative
  776. `context' in the data-type union. Then it calls `declare_variable'
  777. to add the new variable to that list. Once the first action is
  778. finished, the embedded statement `stmt' can be parsed. Note that the
  779. mid-rule action is component number 5, so the `stmt' is component
  780. number 6.
  781. After the embedded statement is parsed, its semantic value becomes
  782. the value of the entire `let'-statement. Then the semantic value
  783. from the earlier action is used to restore the prior list of
  784. variables. This removes the temporary `let'-variable from the list
  785. so that it won't appear to exist while the rest of the program is
  786. parsed.
  787. Taking action before a rule is completely recognized often leads to
  788. conflicts since the parser must commit to a parse in order to execute
  789. the action. For example, the following two rules, without mid-rule
  790. actions, can coexist in a working parser because the parser can shift
  791. the open-brace token and look at what follows before deciding whether
  792. there is a declaration or not:
  793. compound: '{' declarations statements '}'
  794. | '{' statements '}'
  795. ;
  796. But when we add a mid-rule action as follows, the rules become
  797. nonfunctional:
  798. compound: { prepare_for_local_variables (); }
  799. '{' declarations statements '}'
  800. | '{' statements '}'
  801. ;
  802. Now the parser is forced to decide whether to run the mid-rule action
  803. when it has read no farther than the open-brace. In other words, it
  804. must commit to using one rule or the other, without sufficient
  805. information to do it correctly. (The open-brace token is what is
  806. called the "look-ahead" token at this time, since the parser is still
  807. deciding what to do about it. *Note Look-Ahead::.)
  808. You might think that you could correct the problem by putting
  809. identical actions into the two rules, like this:
  810. compound: { prepare_for_local_variables (); }
  811. '{' declarations statements '}'
  812. | { prepare_for_local_variables (); }
  813. '{' statements '}'
  814. ;
  815. But this does not help, because Bison does not realize that the two
  816. actions are identical. (Bison never tries to understand the C code
  817. in an action.)
  818. If the grammar is such that a declaration can be distinguished from a
  819. statement by the first token (which is true in C), then one solution
  820. which does work is to put the action after the open-brace, like this:
  821. compound: '{' { prepare_for_local_variables (); }
  822. declarations statements '}'
  823. | '{' statements '}'
  824. ;
  825. Now the first token of the following declaration or statement, which
  826. would in any case tell Bison which rule to use, can still do so.
  827. Another solution is to bury the action inside a nonterminal symbol
  828. which serves as a subroutine:
  829. subroutine: /* empty */
  830. { prepare_for_local_variables (); }
  831. ;
  832. compound: subroutine
  833. '{' declarations statements '}'
  834. | subroutine
  835. '{' statements '}'
  836. ;
  837. Now Bison can execute the action in the rule for `subroutine' without
  838. deciding which rule for `compound' it will eventually use. Note that
  839. the action is now at the end of its rule. Any mid-rule action can be
  840. converted to an end-of-rule action in this way, and this is what
  841. Bison actually does to implement mid-rule actions.
  842. 
  843. File: bison.info, Node: Declarations, Next: Multiple Parsers, Prev: Semantics, Up: Grammar File
  844. Bison Declarations
  845. ==================
  846. The "Bison declarations" section of a Bison grammar defines the
  847. symbols used in formulating the grammar and the data types of
  848. semantic values. *Note Symbols::.
  849. All token type names (but not single-character literal tokens such as
  850. `'+'' and `'*'') must be declared. Nonterminal symbols must be
  851. declared if you need to specify which data type to use for the
  852. semantic value (*note Multiple Types::.).
  853. The first rule in the file also specifies the start symbol, by default.
  854. If you want some other symbol to be the start symbol, you must
  855. declare it explicitly (*note Language and Grammar::.).
  856. * Menu:
  857. * Token Decl:: Declaring terminal symbols.
  858. * Precedence Decl:: Declaring terminals with precedence and associativity.
  859. * Union Decl:: Declaring the set of all semantic value types.
  860. * Type Decl:: Declaring the choice of type for a nonterminal symbol.
  861. * Expect Decl:: Suppressing warnings about shift/reduce conflicts.
  862. * Start Decl:: Specifying the start symbol.
  863. * Pure Decl:: Requesting a reentrant parser.
  864. * Decl Summary:: Table of all Bison declarations.
  865. 
  866. File: bison.info, Node: Token Decl, Next: Precedence Decl, Prev: Declarations, Up: Declarations
  867. Declaring Token Type Names
  868. --------------------------
  869. The basic way to declare a token type name (terminal symbol) is as
  870. follows:
  871. %token NAME
  872. Bison will convert this into a `#define' directive in the parser, so
  873. that the function `yylex' (if it is in this file) can use the name
  874. NAME to stand for this token type's code.
  875. Alternatively you can use `%left', `%right', or `%nonassoc' instead
  876. of `%token', if you wish to specify precedence. *Note Precedence
  877. Decl::.
  878. You can explicitly specify the numeric code for a token type by
  879. appending an integer value in the field immediately following the
  880. token name:
  881. %token NUM 300
  882. It is generally best, however, to let Bison choose the numeric codes
  883. for all token types. Bison will automatically select codes that
  884. don't conflict with each other or with ASCII characters.
  885. In the event that the stack type is a union, you must augment the
  886. `%token' or other token declaration to include the data type
  887. alternative delimited by angle-brackets (*note Multiple Types::.).
  888. For example:
  889. %union { /* define stack type */
  890. double val;
  891. symrec *tptr;
  892. }
  893. %token <val> NUM /* define token NUM and its type */
  894. 
  895. File: bison.info, Node: Precedence Decl, Next: Union Decl, Prev: Token Decl, Up: Declarations
  896. Declaring Operator Precedence
  897. -----------------------------
  898. Use the `%left', `%right' or `%nonassoc' declaration to declare a
  899. token and specify its precedence and associativity, all at once.
  900. These are called "precedence declarations". *Note Precedence::, for
  901. general information on operator precedence.
  902. The syntax of a precedence declaration is the same as that of
  903. `%token': either
  904. %left SYMBOLS...
  905. or
  906. %left <TYPE> SYMBOLS...
  907. And indeed any of these declarations serves the purposes of `%token'.
  908. But in addition, they specify the associativity and relative
  909. precedence for all the SYMBOLS:
  910. * The associativity of an operator OP determines how repeated uses
  911. of the operator nest: whether `X OP Y OP Z' is parsed by
  912. grouping X with Y first or by grouping Y with Z first. `%left'
  913. specifies left-associativity (grouping X with Y first) and
  914. `%right' specifies right-associativity (grouping Y with Z
  915. first). `%nonassoc' specifies no associativity, which means
  916. that `X OP Y OP Z' is considered a syntax error.
  917. * The precedence of an operator determines how it nests with other
  918. operators. All the tokens declared in a single precedence
  919. declaration have equal precedence and nest together according to
  920. their associativity. When two tokens declared in different
  921. precedence declarations associate, the one declared later has
  922. the higher precedence and is grouped first.
  923. 
  924. File: bison.info, Node: Union Decl, Next: Type Decl, Prev: Precedence Decl, Up: Declarations
  925. Declaring the Collection of Value Types
  926. ---------------------------------------
  927. The `%union' declaration specifies the entire collection of possible
  928. data types for semantic values. The keyword `%union' is followed by
  929. a pair of braces containing the same thing that goes inside a `union'
  930. in C. For example:
  931. %union {
  932. double val;
  933. symrec *tptr;
  934. }
  935. This says that the two alternative types are `double' and `symrec *'.
  936. They are given names `val' and `tptr'; these names are used in the
  937. `%token' and `%type' declarations to pick one of the types for a
  938. terminal or nonterminal symbol (*note Type Decl::.).
  939. Note that, unlike making a `union' declaration in C, you do not write
  940. a semicolon after the closing brace.
  941. 
  942. File: bison.info, Node: Type Decl, Next: Expect Decl, Prev: Union Decl, Up: Declarations
  943. Declaring Value Types of Nonterminal Symbols
  944. --------------------------------------------
  945. When you use `%union' to specify multiple value types, you must
  946. declare the value type of each nonterminal symbol for which values
  947. are used. This is done with a `%type' declaration, like this:
  948. %type <TYPE> NONTERMINAL...
  949. Here NONTERMINAL is the name of a nonterminal symbol, and TYPE is the
  950. name given in the `%union' to the alternative that you want (*note
  951. Union Decl::.). You can give any number of nonterminal symbols in
  952. the same `%type' declaration, if they have the same value type. Use
  953. spaces to separate the symbol names.
  954. 
  955. File: bison.info, Node: Expect Decl, Next: Start Decl, Prev: Type Decl, Up: Declarations
  956. Preventing Warnings about Conflicts
  957. -----------------------------------
  958. Bison normally warns if there are any conflicts in the grammar (*note
  959. Shift/Reduce::.), but most real grammars have harmless shift/reduce
  960. conflicts which are resolved in a predictable way and would be
  961. difficult to eliminate. It is desirable to suppress the warning
  962. about these conflicts unless the number of conflicts changes. You
  963. can do this with the `%expect' declaration.
  964. The declaration looks like this:
  965. %expect N
  966. Here N is a decimal integer. The declaration says there should be no
  967. warning if there are N shift/reduce conflicts and no reduce/reduce
  968. conflicts. The usual warning is given if there are either more or
  969. fewer conflicts, or if there are any reduce/reduce conflicts.
  970. In general, using `%expect' involves these steps:
  971. * Compile your grammar without `%expect'. Use the `-v' option to
  972. get a verbose list of where the conflicts occur. Bison will
  973. also print the number of conflicts.
  974. * Check each of the conflicts to make sure that Bison's default
  975. resolution is what you really want. If not, rewrite the grammar
  976. and go back to the beginning.
  977. * Add an `%expect' declaration, copying the number N from the
  978. number which Bison printed.
  979. Now Bison will stop annoying you about the conflicts you have
  980. checked, but it will warn you again if changes in the grammer result
  981. in additional conflicts.
  982. 
  983. File: bison.info, Node: Start Decl, Next: Pure Decl, Prev: Expect Decl, Up: Declarations
  984. Declaring the Start-Symbol
  985. --------------------------
  986. Bison assumes by default that the start symbol for the grammar is the
  987. first nonterminal specified in the grammar specification section.
  988. The programmer may override this restriction with the `%start'
  989. declaration as follows:
  990. %start SYMBOL
  991. 
  992. File: bison.info, Node: Pure Decl, Next: Decl Summary, Prev: Start Decl, Up: Declarations
  993. Requesting a Pure (Reentrant) Parser
  994. ------------------------------------
  995. A "reentrant" program is one which does not alter in the course of
  996. execution; in other words, it consists entirely of "pure" (read-only)
  997. code. Reentrancy is important whenever asynchronous execution is
  998. possible; for example, a nonreentrant program may not be safe to call
  999. from a signal handler. In systems with multiple threads of control,
  1000. a nonreentrant program must be called only within interlocks.
  1001. The Bison parser is not normally a reentrant program, because it uses
  1002. statically allocated variables for communication with `yylex'. These
  1003. variables include `yylval' and `yylloc'.
  1004. The Bison declaration `%pure_parser' says that you want the parser to
  1005. be reentrant. It looks like this:
  1006. %pure_parser
  1007. The effect is that the the two communication variables become local
  1008. variables in `yyparse', and a different calling convention is used
  1009. for the lexical analyzer function `yylex'. *Note Pure Calling::, for
  1010. the details of this. The variable `yynerrs' also becomes local in
  1011. `yyparse' (*note Error Reporting::.). The convention for calling
  1012. `yyparse' itself is unchanged.
  1013. 
  1014. File: bison.info, Node: Decl Summary, Prev: Pure Decl, Up: Declarations
  1015. Bison Declaration Summary
  1016. -------------------------
  1017. Here is a summary of all Bison declarations:
  1018. `%union'
  1019. Declare the collection of data types that semantic values may
  1020. have (*note Union Decl::.).
  1021. `%token'
  1022. Declare a terminal symbol (token type name) with no precedence
  1023. or associativity specified (*note Token Decl::.).
  1024. `%right'
  1025. Declare a terminal symbol (token type name) that is
  1026. right-associative (*note Precedence Decl::.).
  1027. `%left'
  1028. Declare a terminal symbol (token type name) that is
  1029. left-associative (*note Precedence Decl::.).
  1030. `%nonassoc'
  1031. Declare a terminal symbol (token type name) that is
  1032. nonassociative (using it in a way that would be associative is a
  1033. syntax error) (*note Precedence Decl::.).
  1034. `%type'
  1035. Declare the type of semantic values for a nonterminal symbol
  1036. (*note Type Decl::.).
  1037. `%start'
  1038. Specify the grammar's start symbol (*note Start Decl::.).
  1039. `%expect'
  1040. Declare the expected number of shift-reduce conflicts (*note
  1041. Expect Decl::.).
  1042. `%pure_parser'
  1043. Request a pure (reentrant) parser program (*note Pure Decl::.).