]>
git.saurik.com Git - bison.git/blob - src/nullable.c
1 /* Part of the bison parser generator,
2 Copyright (C) 1984, 1989 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
34 extern void free_nullable
PARAMS((void));
35 extern void set_nullable
PARAMS((void));
55 fprintf(stderr
, _("Entering set_nullable"));
58 nullable
= NEW2(nvars
, char) - ntokens
;
60 squeue
= NEW2(nvars
, short);
63 rcount
= NEW2(nrules
+ 1, short);
64 rsets
= NEW2(nvars
, shorts
*) - ntokens
;
65 /* This is said to be more elements than we actually use.
66 Supposedly nitems - nrules is enough.
67 But why take the risk? */
68 relts
= NEW2(nitems
+ nvars
+ 1, shorts
);
76 symbol
= rlhs
[-(*r
++)];
77 if (symbol
>= 0 && !nullable
[symbol
])
87 for (symbol
= *r
++; symbol
> 0; symbol
= *r
++)
97 for (symbol
= *r
++; symbol
> 0; symbol
= *r
++)
100 p
->next
= rsets
[symbol
];
116 if (--rcount
[ruleno
] == 0)
118 symbol
= rlhs
[ruleno
];
119 if (symbol
>= 0 && !nullable
[symbol
])
121 nullable
[symbol
] = 1;
130 FREE(rsets
+ ntokens
);
138 FREE(nullable
+ ntokens
);