]>
git.saurik.com Git - bison.git/blob - src/derives.c
1 /* Match rules with nonterminals for bison,
3 Copyright (C) 1984, 1989, 2000-2003, 2005, 2009-2013 Free Software
6 This file is part of Bison, the GNU Compiler Compiler.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 /* Linked list of rule numbers. */
32 typedef struct rule_list
34 struct rule_list
*next
;
45 fputs ("DERIVES\n", stderr
);
47 for (i
= ntokens
; i
< nsyms
; i
++)
50 fprintf (stderr
, "\t%s derives\n", symbols
[i
]->tag
);
51 for (rp
= derives
[i
- ntokens
]; *rp
; ++rp
)
53 fprintf (stderr
, "\t\t%3d ", (*rp
)->user_number
);
54 rule_rhs_print (*rp
, stderr
);
58 fputs ("\n\n", stderr
);
63 derives_compute (void)
69 /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules
70 whose LHS is NTERM. */
71 rule_list
**dset
= xcalloc (nvars
, sizeof *dset
);
73 /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
74 Instead of performing NRULES allocations for each, have an array
75 indexed by rule numbers. */
76 rule_list
*delts
= xnmalloc (nrules
, sizeof *delts
);
78 for (r
= nrules
- 1; r
>= 0; --r
)
80 symbol_number lhs
= rules
[r
].lhs
->number
;
81 rule_list
*p
= &delts
[r
];
82 /* A new LHS is found. */
83 p
->next
= dset
[lhs
- ntokens
];
85 dset
[lhs
- ntokens
] = p
;
88 /* DSET contains what we need under the form of a linked list. Make
91 derives
= xnmalloc (nvars
, sizeof *derives
);
92 q
= xnmalloc (nvars
+ nrules
, sizeof *q
);
94 for (i
= ntokens
; i
< nsyms
; i
++)
96 rule_list
*p
= dset
[i
- ntokens
];
97 derives
[i
- ntokens
] = q
;
106 if (trace_flag
& trace_sets
)