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