]> git.saurik.com Git - bison.git/blame - src/gram.h
* src/LR0.h: New file.
[bison.git] / src / gram.h
CommitLineData
f7d4d87a 1/* Data definitions for internal representation of bison's input,
9f690211 2 Copyright (C) 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
f7d4d87a
DM
3
4This file is part of Bison, the GNU Compiler Compiler.
5
6Bison is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11Bison is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Bison; see the file COPYING. If not, write to
c49a8e71
JT
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
f7d4d87a
DM
20
21
22/* representation of the grammar rules:
23
24ntokens is the number of tokens, and nvars is the number of variables
25(nonterminals). nsyms is the total number, ntokens + nvars.
26
9f690211
RS
27 (the true number of token values assigned is ntokens
28 reduced by one for each alias declaration)
29
f7d4d87a
DM
30Each symbol (either token or variable) receives a symbol number.
31Numbers 0 to ntokens-1 are for tokens, and ntokens to nsyms-1 are for
32variables. Symbol number zero is the end-of-input token. This token
33is counted in ntokens.
34
35The rules receive rule numbers 1 to nrules in the order they are written.
36Actions and guards are accessed via the rule number.
37
38The rules themselves are described by three arrays: rrhs, rlhs and
39ritem. rlhs[R] is the symbol number of the left hand side of rule R.
40The right hand side is stored as symbol numbers in a portion of
41ritem. rrhs[R] contains the index in ritem of the beginning of the
42portion for rule R.
43
44If rlhs[R] is -1, the rule has been thrown out by reduce.c
45and should be ignored.
46
47The length of the portion is one greater
48 than the number of symbols in the rule's right hand side.
49The last element in the portion contains minus R, which
50identifies it as the end of a portion and says which rule it is for.
51
52The portions of ritem come in order of increasing rule number and are
53followed by an element which is zero to mark the end. nitems is the
54total length of ritem, not counting the final zero. Each element of
55ritem is called an "item" and its index in ritem is an item number.
56
57Item numbers are used in the finite state machine to represent
58places that parsing can get to.
59
60Precedence levels are recorded in the vectors sprec and rprec.
61sprec records the precedence level of each symbol,
62rprec the precedence level of each rule.
63rprecsym is the symbol-number of the symbol in %prec for this rule (if any).
64
65Precedence levels are assigned in increasing order starting with 1 so
66that numerically higher precedence values mean tighter binding as they
67ought to. Zero as a symbol or rule's precedence means none is
68assigned.
69
70Associativities are recorded similarly in rassoc and sassoc. */
71
72
73#define ISTOKEN(s) ((s) < ntokens)
74#define ISVAR(s) ((s) >= ntokens)
75
76
77extern int nitems;
78extern int nrules;
79extern int nsyms;
80extern int ntokens;
81extern int nvars;
82
83extern short *ritem;
84extern short *rlhs;
85extern short *rrhs;
86extern short *rprec;
87extern short *rprecsym;
88extern short *sprec;
89extern short *rassoc;
90extern short *sassoc;
91extern short *rline; /* Source line number of each rule */
92
93extern int start_symbol;
94
95
96/* associativity values in elements of rassoc, sassoc. */
97
98#define RIGHT_ASSOC 1
99#define LEFT_ASSOC 2
100#define NON_ASSOC 3
101
102/* token translation table:
103indexed by a token number as returned by the user's yylex routine,
104it yields the internal token number used by the parser and throughout bison.
105If translations is zero, the translation table is not used because
9f690211
RS
106the two kinds of token numbers are the same.
107(It is noted in reader.c that "Nowadays translations is always set to 1...")
108*/
f7d4d87a
DM
109
110extern short *token_translations;
111extern int translations;
112extern int max_user_token_number;
113
114/* semantic_parser is nonzero if the input file says to use the hairy parser
115that provides for semantic error recovery. If it is zero, the yacc-compatible
116simplified parser is used. */
117
118extern int semantic_parser;
119
120/* pure_parser is nonzero if should generate a parser that is all pure and reentrant. */
121
122extern int pure_parser;
123
124/* error_token_number is the token number of the error token. */
125
126extern int error_token_number;