]> git.saurik.com Git - bison.git/blame_incremental - src/gram.h
[_MSC_VER]: Include stdlib.h and process.h.
[bison.git] / src / gram.h
... / ...
CommitLineData
1/* Data definitions for internal representation of bison's input,
2 Copyright (C) 1984, 1986, 1989, 1992 Free Software Foundation, Inc.
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
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21/* representation of the grammar rules:
22
23ntokens is the number of tokens, and nvars is the number of variables
24(nonterminals). nsyms is the total number, ntokens + nvars.
25
26 (the true number of token values assigned is ntokens
27 reduced by one for each alias declaration)
28
29Each symbol (either token or variable) receives a symbol number.
30Numbers 0 to ntokens-1 are for tokens, and ntokens to nsyms-1 are for
31variables. Symbol number zero is the end-of-input token. This token
32is counted in ntokens.
33
34The rules receive rule numbers 1 to nrules in the order they are written.
35Actions and guards are accessed via the rule number.
36
37The rules themselves are described by three arrays: rrhs, rlhs and
38ritem. rlhs[R] is the symbol number of the left hand side of rule R.
39The right hand side is stored as symbol numbers in a portion of
40ritem. rrhs[R] contains the index in ritem of the beginning of the
41portion for rule R.
42
43If rlhs[R] is -1, the rule has been thrown out by reduce.c
44and should be ignored.
45
46The length of the portion is one greater
47 than the number of symbols in the rule's right hand side.
48The last element in the portion contains minus R, which
49identifies it as the end of a portion and says which rule it is for.
50
51The portions of ritem come in order of increasing rule number and are
52followed by an element which is zero to mark the end. nitems is the
53total length of ritem, not counting the final zero. Each element of
54ritem is called an "item" and its index in ritem is an item number.
55
56Item numbers are used in the finite state machine to represent
57places that parsing can get to.
58
59Precedence levels are recorded in the vectors sprec and rprec.
60sprec records the precedence level of each symbol,
61rprec the precedence level of each rule.
62rprecsym is the symbol-number of the symbol in %prec for this rule (if any).
63
64Precedence levels are assigned in increasing order starting with 1 so
65that numerically higher precedence values mean tighter binding as they
66ought to. Zero as a symbol or rule's precedence means none is
67assigned.
68
69Associativities are recorded similarly in rassoc and sassoc. */
70
71
72#define ISTOKEN(s) ((s) < ntokens)
73#define ISVAR(s) ((s) >= ntokens)
74
75
76extern int nitems;
77extern int nrules;
78extern int nsyms;
79extern int ntokens;
80extern int nvars;
81
82extern short *ritem;
83extern short *rlhs;
84extern short *rrhs;
85extern short *rprec;
86extern short *rprecsym;
87extern short *sprec;
88extern short *rassoc;
89extern short *sassoc;
90extern short *rline; /* Source line number of each rule */
91
92extern int start_symbol;
93
94
95/* associativity values in elements of rassoc, sassoc. */
96
97#define RIGHT_ASSOC 1
98#define LEFT_ASSOC 2
99#define NON_ASSOC 3
100
101/* token translation table:
102indexed by a token number as returned by the user's yylex routine,
103it yields the internal token number used by the parser and throughout bison.
104If translations is zero, the translation table is not used because
105the two kinds of token numbers are the same.
106(It is noted in reader.c that "Nowadays translations is always set to 1...")
107*/
108
109extern short *token_translations;
110extern int translations;
111extern int max_user_token_number;
112
113/* semantic_parser is nonzero if the input file says to use the hairy parser
114that provides for semantic error recovery. If it is zero, the yacc-compatible
115simplified parser is used. */
116
117extern int semantic_parser;
118
119/* pure_parser is nonzero if should generate a parser that is all pure and reentrant. */
120
121extern int pure_parser;
122
123/* error_token_number is the token number of the error token. */
124
125extern int error_token_number;