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