]>
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-2015 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
, " %s derives\n", symbols
[i
]->tag
);
51 for (rp
= derives
[i
- ntokens
]; *rp
; ++rp
)
53 fprintf (stderr
, " %3d ", (*rp
)->user_number
);
54 rule_rhs_print (*rp
, stderr
);
55 fprintf (stderr
, "\n");
59 fputs ("\n\n", stderr
);
64 derives_compute (void)
70 /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules
71 whose LHS is NTERM. */
72 rule_list
**dset
= xcalloc (nvars
, sizeof *dset
);
74 /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
75 Instead of performing NRULES allocations for each, have an array
76 indexed by rule numbers. */
77 rule_list
*delts
= xnmalloc (nrules
, sizeof *delts
);
79 for (r
= nrules
- 1; r
>= 0; --r
)
81 symbol_number lhs
= rules
[r
].lhs
->number
;
82 rule_list
*p
= &delts
[r
];
83 /* A new LHS is found. */
84 p
->next
= dset
[lhs
- ntokens
];
86 dset
[lhs
- ntokens
] = p
;
89 /* DSET contains what we need under the form of a linked list. Make
92 derives
= xnmalloc (nvars
, sizeof *derives
);
93 q
= xnmalloc (nvars
+ nrules
, sizeof *q
);
95 for (i
= ntokens
; i
< nsyms
; i
++)
97 rule_list
*p
= dset
[i
- ntokens
];
98 derives
[i
- ntokens
] = q
;
107 if (trace_flag
& trace_sets
)