]> git.saurik.com Git - bison.git/blob - src/gram.h
66031cc38e67220f55ad241d7c82088208170e02
[bison.git] / src / gram.h
1 /* Data definitions for internal representation of bison's input,
2 Copyright 1984, 1986, 1989, 1992, 2001 Free Software Foundation, Inc.
3
4 This file is part of Bison, the GNU Compiler Compiler.
5
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.
10
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.
15
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. */
20
21 #ifndef GRAM_H_
22 # define GRAM_H_
23
24 /* representation of the grammar rules:
25
26 ntokens is the number of tokens, and nvars is the number of
27 variables (nonterminals). nsyms is the total number, ntokens +
28 nvars.
29
30 (the true number of token values assigned is ntokens reduced by one
31 for each alias declaration)
32
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.
37
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.
40
41 The rules themselves are described by several arrays: amongst which
42 RITEM, and RULE_TABLE.
43
44 RULE_TABLE is an array of struct rule_s, which members are:
45
46 RULE_TABLE[R].lhs -- the symbol number of the left hand side of
47 rule R. If -1, the rule has been thrown out by reduce.c and should
48 be ignored.
49
50 RULE_TABLE[R].rhs -- the index in RITEM of the beginning of the
51 portion for rule R.
52
53 The right hand side is stored as symbol numbers in a portion of
54 RITEM.
55
56 The length of the portion is one greater than the number of symbols
57 in the rule's right hand side. The last element in the portion
58 contains minus R, which identifies it as the end of a portion and
59 says which rule it is for.
60
61 The portions of RITEM come in order of increasing rule number and
62 are followed by an element which is zero to mark the end. nitems
63 is the total length of ritem, not counting the final zero. Each
64 element of ritem is called an "item" and its index in ritem is an
65 item number.
66
67 Item numbers are used in the finite state machine to represent
68 places that parsing can get to.
69
70 Precedence levels are recorded in the vectors sprec and rprec.
71 sprec records the precedence level of each symbol, rprec the
72 precedence level of each rule. rprecsym is the symbol-number of
73 the symbol in %prec for this rule (if any).
74
75 Precedence levels are assigned in increasing order starting with 1
76 so that numerically higher precedence values mean tighter binding
77 as they ought to. Zero as a symbol or rule's precedence means none
78 is assigned.
79
80 Associativities are recorded similarly in rassoc and sassoc. */
81
82
83 #define ISTOKEN(s) ((s) < ntokens)
84 #define ISVAR(s) ((s) >= ntokens)
85
86 extern int nitems;
87 extern int nrules;
88 extern int nsyms;
89 extern int ntokens;
90 extern int nvars;
91
92 extern short *ritem;
93
94 extern short *rprec;
95 extern short *rprecsym;
96 extern short *sprec;
97 extern short *rassoc;
98 extern short *sassoc;
99 extern short *rline; /* Source line number of each rule */
100
101 extern int start_symbol;
102
103 typedef struct rule_s
104 {
105 short lhs;
106 short rhs;
107 } rule_t;
108
109 extern struct rule_s *rule_table;
110
111 /* associativity values in elements of rassoc, sassoc. */
112 typedef enum
113 {
114 right_assoc,
115 left_assoc,
116 non_assoc
117 } associativity;
118
119
120 /* token translation table: indexed by a token number as returned by
121 the user's yylex routine, it yields the internal token number used
122 by the parser and throughout bison. */
123
124 extern short *token_translations;
125 extern int max_user_token_number;
126
127 /* SEMANTIC_PARSER is nonzero if the input file says to use the hairy
128 parser that provides for semantic error recovery. If it is zero,
129 the yacc-compatible simplified parser is used. */
130
131 extern int semantic_parser;
132
133 /* PURE_PARSER is nonzero if should generate a parser that is all pure
134 and reentrant. */
135
136 extern int pure_parser;
137
138 /* ERROR_TOKEN_NUMBER is the token number of the error token. */
139
140 extern int error_token_number;
141 #endif /* !GRAM_H_ */