]>
Commit | Line | Data |
---|---|---|
f7d4d87a | 1 | /* Allocate input grammar variables for bison, |
8b3df748 | 2 | Copyright (C) 1984, 1986, 1989, 2001, 2002 Free Software Foundation, Inc. |
f7d4d87a | 3 | |
076ab033 | 4 | This file is part of Bison, the GNU Compiler Compiler. |
f7d4d87a | 5 | |
076ab033 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 | |
076ab033 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 | |
076ab033 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 DM |
20 | |
21 | ||
4a120d45 | 22 | #include "system.h" |
8b3df748 | 23 | #include "quotearg.h" |
b2ed6e58 | 24 | #include "gram.h" |
0e78e603 | 25 | #include "symtab.h" |
3067fbef | 26 | #include "reader.h" |
4a120d45 | 27 | |
f7d4d87a DM |
28 | /* comments for these variables are in gram.h */ |
29 | ||
62a3e4f0 | 30 | item_number_t *ritem = NULL; |
280a38c3 | 31 | int nritems = 0; |
75142d45 | 32 | |
1a2b5d37 | 33 | rule_t *rules = NULL; |
5123689b | 34 | int nrules = 0; |
0e78e603 | 35 | |
db8837cb | 36 | symbol_t **symbols = NULL; |
5123689b AD |
37 | int nsyms = 0; |
38 | int ntokens = 1; | |
39 | int nvars = 0; | |
40 | ||
680e8701 | 41 | token_number_t *token_translations = NULL; |
f7d4d87a | 42 | |
280a38c3 | 43 | int start_symbol = 0; |
f7d4d87a | 44 | |
280a38c3 | 45 | int max_user_token_number = 256; |
f7d4d87a | 46 | |
280a38c3 | 47 | int semantic_parser = 0; |
f7d4d87a | 48 | |
280a38c3 | 49 | int pure_parser = 0; |
f7d4d87a | 50 | |
c2713865 | 51 | |
c3b407f4 AD |
52 | /*--------------------------------------. |
53 | | Return the number of symbols in RHS. | | |
54 | `--------------------------------------*/ | |
55 | ||
56 | int | |
57 | rule_rhs_length (rule_t *rule) | |
58 | { | |
59 | int res = 0; | |
62a3e4f0 | 60 | item_number_t *rhsp; |
c3b407f4 AD |
61 | for (rhsp = rule->rhs; *rhsp >= 0; ++rhsp) |
62 | ++res; | |
63 | return res; | |
64 | } | |
65 | ||
66 | ||
c2713865 AD |
67 | /*------------------------. |
68 | | Dump RITEM for traces. | | |
69 | `------------------------*/ | |
70 | ||
cbbe7505 | 71 | void |
3067fbef | 72 | ritem_print (FILE *out) |
f7d4d87a | 73 | { |
3067fbef AD |
74 | int i; |
75 | fputs ("RITEM\n", out); | |
75142d45 AD |
76 | for (i = 0; i < nritems; ++i) |
77 | if (ritem[i] >= 0) | |
8b3df748 AD |
78 | fprintf (out, " %s", quotearg_style (escape_quoting_style, |
79 | symbols[ritem[i]]->tag)); | |
3067fbef | 80 | else |
29d29c8f | 81 | fprintf (out, " (rule %d)\n", -ritem[i] - 1); |
3067fbef | 82 | fputs ("\n\n", out); |
f7d4d87a | 83 | } |
c2713865 AD |
84 | |
85 | ||
86 | /*------------------------------------------. | |
87 | | Return the size of the longest rule RHS. | | |
88 | `------------------------------------------*/ | |
89 | ||
90 | size_t | |
91 | ritem_longest_rhs (void) | |
92 | { | |
c3b407f4 | 93 | int max = 0; |
9e7f6bbd | 94 | int i; |
c2713865 | 95 | |
c3b407f4 AD |
96 | for (i = 1; i < nrules + 1; ++i) |
97 | { | |
98 | int length = rule_rhs_length (&rules[i]); | |
99 | if (length > max) | |
100 | max = length; | |
101 | } | |
c2713865 AD |
102 | |
103 | return max; | |
104 | } |