]>
git.saurik.com Git - bison.git/blob - src/derives.c
2e4ff31ba68c807908c76963ffd9d7a003f1bf9b
1 /* Match rules with nonterminals for bison,
3 Copyright (C) 1984, 1989, 2000, 2001, 2002, 2003, 2005 Free
4 Software Foundation, Inc.
6 This file is part of Bison, the GNU Compiler Compiler.
8 Bison 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 2, or (at your option)
13 Bison 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 Bison; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
33 /* Linked list of rule numbers. */
34 typedef struct rule_list
36 struct rule_list
*next
;
47 fputs ("DERIVES\n", stderr
);
49 for (i
= ntokens
; i
< nsyms
; i
++)
52 fprintf (stderr
, "\t%s derives\n", symbols
[i
]->tag
);
53 for (rp
= derives
[i
- ntokens
]; *rp
; ++rp
)
55 fprintf (stderr
, "\t\t%3d ", (*rp
)->user_number
);
56 rule_rhs_print (*rp
, stderr
);
60 fputs ("\n\n", stderr
);
65 derives_compute (void)
71 /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules
72 whose LHS is NTERM. */
73 rule_list
**dset
= xcalloc (nvars
, sizeof *dset
);
75 /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
76 Instead of performing NRULES allocations for each, have an array
77 indexed by rule numbers. */
78 rule_list
*delts
= xnmalloc (nrules
, sizeof *delts
);
80 for (r
= nrules
- 1; r
>= 0; --r
)
82 symbol_number lhs
= rules
[r
].lhs
->number
;
83 rule_list
*p
= &delts
[r
];
84 /* A new LHS is found. */
85 p
->next
= dset
[lhs
- ntokens
];
87 dset
[lhs
- ntokens
] = p
;
90 /* DSET contains what we need under the form of a linked list. Make
93 derives
= xnmalloc (nvars
, sizeof *derives
);
94 q
= xnmalloc (nvars
+ nrules
, sizeof *q
);
96 for (i
= ntokens
; i
< nsyms
; i
++)
98 rule_list
*p
= dset
[i
- ntokens
];
99 derives
[i
- ntokens
] = q
;
108 if (trace_flag
& trace_sets
)