]>
git.saurik.com Git - bison.git/blob - src/nullable.c
b85dec610d51a7bcf2b4e16fbd9b21a1cb7f736e
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* set up nullable, a vector saying which nonterminals can expand into the null string.
22 nullable[i - ntokens] is nonzero if symbol i can do so. */
52 fprintf(stderr
, "Entering set_nullable");
55 nullable
= NEW2(nvars
, char) - ntokens
;
57 squeue
= NEW2(nvars
, short);
60 rcount
= NEW2(nrules
+ 1, short);
61 rsets
= NEW2(nvars
, shorts
*) - ntokens
;
62 /* This is said to be more elements than we actually use.
63 Supposedly nitems - nrules is enough.
64 But why take the risk? */
65 relts
= NEW2(nitems
+ nvars
+ 1, shorts
);
73 symbol
= rlhs
[-(*r
++)];
74 if (symbol
>= 0 && !nullable
[symbol
])
84 for (symbol
= *r
++; symbol
> 0; symbol
= *r
++)
94 for (symbol
= *r
++; symbol
> 0; symbol
= *r
++)
97 p
->next
= rsets
[symbol
];
113 if (--rcount
[ruleno
] == 0)
115 symbol
= rlhs
[ruleno
];
116 if (symbol
>= 0 && !nullable
[symbol
])
118 nullable
[symbol
] = 1;
127 FREE(rsets
+ ntokens
);
135 FREE(nullable
+ ntokens
);