]>
git.saurik.com Git - bison.git/blob - src/nullable.c
1 /* Part of the bison parser generator,
2 Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
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)
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.
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. */
22 /* Set up NULLABLE, a vector saying which nonterminals can expand into
23 the null string. NULLABLE[I - NTOKENS] is nonzero if symbol I can
33 char *nullable
= NULL
;
36 nullable_print (FILE *out
)
39 fputs ("NULLABLE\n", out
);
40 for (i
= ntokens
; i
< nsyms
; i
++)
41 fprintf (out
, "\t%s: %s\n", tags
[i
], nullable
[i
] ? "yes" : "no");
59 fprintf (stderr
, "Entering set_nullable\n");
61 nullable
= XCALLOC (char, nvars
) - ntokens
;
63 squeue
= XCALLOC (short, nvars
);
66 rcount
= XCALLOC (short, nrules
+ 1);
67 rsets
= XCALLOC (shorts
*, nvars
) - ntokens
;
68 /* This is said to be more elements than we actually use.
69 Supposedly nitems - nrules is enough.
70 But why take the risk? */
71 relts
= XCALLOC (shorts
, nitems
+ nvars
+ 1);
79 int symbol
= rule_table
[-(*r
++)].lhs
;
80 if (symbol
>= 0 && !nullable
[symbol
])
91 for (symbol
= *r
++; symbol
> 0; symbol
= *r
++)
99 for (symbol
= *r
++; symbol
> 0; symbol
= *r
++)
102 p
->next
= rsets
[symbol
];
116 int ruleno
= p
->value
;
118 if (--rcount
[ruleno
] == 0)
120 int symbol
= rule_table
[ruleno
].lhs
;
121 if (symbol
>= 0 && !nullable
[symbol
])
123 nullable
[symbol
] = 1;
132 XFREE (rsets
+ ntokens
);
136 nullable_print (stderr
);
143 XFREE (nullable
+ ntokens
);