]>
git.saurik.com Git - bison.git/blob - src/derives.c
87b15f2d07b9bec7684e06b1bb68fc5e50588d7e
1 /* Match rules with nonterminals for bison,
2 Copyright 1984, 1989, 2000, 2001, 2002 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. */
30 /* Linked list of rule numbers. */
31 typedef struct rule_list_s
33 struct rule_list_s
*next
;
37 rule_number_t
**derives
= NULL
;
44 fputs ("DERIVES\n", stderr
);
46 for (i
= ntokens
; i
< nsyms
; i
++)
49 fprintf (stderr
, "\t%s derives\n", symbols
[i
]->tag
);
50 for (rp
= derives
[i
]; *rp
> 0; rp
++)
52 fprintf (stderr
, "\t\t%3d ", *rp
- 1);
53 rule_rhs_print (&rules
[*rp
], stderr
);
57 fputs ("\n\n", stderr
);
68 /* DSET[NTERM] -- A linked list of the numbers of the rules whose
70 rule_list_t
**dset
= XCALLOC (rule_list_t
*, nvars
) - ntokens
;
72 /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
73 Instead of performing NRULES allocations for each, have an array
74 indexed by rule numbers. */
75 rule_list_t
*delts
= XCALLOC (rule_list_t
, nrules
+ 1);
77 for (r
= nrules
; r
> 0; r
--)
79 symbol_number_t lhs
= rules
[r
].lhs
->number
;
80 rule_list_t
*p
= &delts
[r
];
81 /* A new LHS is found. */
87 /* DSET contains what we need under the form of a linked list. Make
90 derives
= XCALLOC (rule_number_t
*, nvars
) - ntokens
;
91 q
= XCALLOC (rule_number_t
, nvars
+ int_of_rule_number (nrules
));
93 for (i
= ntokens
; i
< nsyms
; i
++)
95 rule_list_t
*p
= dset
[i
];
108 free (dset
+ ntokens
);
116 XFREE (derives
[ntokens
]);
117 XFREE (derives
+ ntokens
);