]>
git.saurik.com Git - bison.git/blob - src/derives.c
   1 /* Match rules with nonterminals for bison, 
   2    Copyright (C) 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.  */ 
  29 /* Linked list of rule numbers.  */ 
  30 typedef struct rule_list_s
 
  32   struct rule_list_s 
*next
; 
  36 rule_t 
***derives 
= NULL
; 
  43   fputs ("DERIVES\n", stderr
); 
  45   for (i 
= ntokens
; i 
< nsyms
; i
++) 
  48       fprintf (stderr
, "\t%s derives\n", symbols
[i
]->tag
); 
  49       for (rp 
= derives
[i
]; *rp
; ++rp
) 
  51           fprintf (stderr
, "\t\t%3d ", (*rp
)->user_number
); 
  52           rule_rhs_print (*rp
, stderr
); 
  56   fputs ("\n\n", stderr
); 
  61 derives_compute (void) 
  67   /* DSET[NTERM] -- A linked list of the numbers of the rules whose 
  69   rule_list_t 
**dset 
= XCALLOC (rule_list_t 
*, nvars
) - ntokens
; 
  71   /* DELTS[RULE] -- There are NRULES rule number to attach to nterms. 
  72      Instead of performing NRULES allocations for each, have an array 
  73      indexed by rule numbers.  */ 
  74   rule_list_t 
*delts 
= XCALLOC (rule_list_t
, nrules
); 
  76   for (r 
= nrules 
- 1; r 
>= 0; --r
) 
  78       symbol_number_t lhs 
= rules
[r
].lhs
->number
; 
  79       rule_list_t 
*p 
= &delts
[r
]; 
  80       /* A new LHS is found.  */ 
  86   /* DSET contains what we need under the form of a linked list.  Make 
  89   derives 
= XCALLOC (rule_t 
**, nvars
) - ntokens
; 
  90   q 
= XCALLOC (rule_t 
*, nvars 
+ int_of_rule_number (nrules
)); 
  92   for (i 
= ntokens
; i 
< nsyms
; i
++) 
  94       rule_list_t 
*p 
= dset
[i
]; 
 104   if (trace_flag 
& trace_sets
) 
 107   free (dset 
+ ntokens
); 
 115   XFREE (derives
[ntokens
]); 
 116   XFREE (derives 
+ ntokens
);