]> git.saurik.com Git - bison.git/blame - src/derives.c
* src/LR0.h (first_shift, first_reduction): Remove.
[bison.git] / src / derives.c
CommitLineData
122c0aac 1/* Match rules with nonterminals for bison,
2c5f66ed 2 Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
122c0aac 3
cc84fd5d 4 This file is part of Bison, the GNU Compiler Compiler.
122c0aac 5
cc84fd5d
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.
122c0aac 10
cc84fd5d
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.
122c0aac 15
cc84fd5d
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. */
122c0aac
RS
20
21
122c0aac 22#include "system.h"
9bfe901c 23#include "getargs.h"
122c0aac 24#include "types.h"
2c5f66ed 25#include "reader.h"
122c0aac 26#include "gram.h"
cc84fd5d 27#include "derives.h"
4a120d45 28
80a69750 29short **derives = NULL;
cc84fd5d
AD
30
31static void
32print_derives (void)
33{
d7913476 34 int i;
cc84fd5d 35
c87d4863 36 fputs ("DERIVES\n", stderr);
cc84fd5d
AD
37
38 for (i = ntokens; i < nsyms; i++)
39 {
720e5c1b 40 short *sp;
c87d4863 41 fprintf (stderr, "\t%s derives\n", tags[i]);
cc84fd5d 42 for (sp = derives[i]; *sp > 0; sp++)
720e5c1b
AD
43 {
44 short *rhsp;
45 fprintf (stderr, "\t\t%d:", *sp);
46 for (rhsp = ritem + rule_table[*sp].rhs; *rhsp > 0; ++rhsp)
47 fprintf (stderr, " %s", tags[*rhsp]);
80a69750 48 fprintf (stderr, " (rule %d)\n", -*rhsp);
720e5c1b 49 }
cc84fd5d
AD
50 }
51
c87d4863 52 fputs ("\n\n", stderr);
cc84fd5d
AD
53}
54
122c0aac 55
122c0aac 56void
d2729d44 57set_derives (void)
122c0aac 58{
d7913476 59 int i;
d7913476
AD
60 shorts *p;
61 short *q;
62 shorts **dset;
63 shorts *delts;
122c0aac 64
d7913476
AD
65 dset = XCALLOC (shorts *, nvars) - ntokens;
66 delts = XCALLOC (shorts, nrules + 1);
122c0aac
RS
67
68 p = delts;
69 for (i = nrules; i > 0; i--)
68f1e3ed
AD
70 if (rule_table[i].useful)
71 {
72 int lhs = rule_table[i].lhs;
73 p->next = dset[lhs];
74 p->value = i;
75 dset[lhs] = p;
76 p++;
77 }
122c0aac 78
d7913476
AD
79 derives = XCALLOC (short *, nvars) - ntokens;
80 q = XCALLOC (short, nvars + nrules);
122c0aac
RS
81
82 for (i = ntokens; i < nsyms; i++)
83 {
84 derives[i] = q;
85 p = dset[i];
86 while (p)
87 {
88 *q++ = p->value;
89 p = p->next;
90 }
91 *q++ = -1;
92 }
93
9bfe901c
AD
94 if (trace_flag)
95 print_derives ();
122c0aac 96
d7913476
AD
97 XFREE (dset + ntokens);
98 XFREE (delts);
122c0aac
RS
99}
100
101void
d2729d44 102free_derives (void)
122c0aac 103{
d7913476
AD
104 XFREE (derives[ntokens]);
105 XFREE (derives + ntokens);
122c0aac 106}