/[bison]/bison/src/derives.c
ViewVC logotype

Diff of /bison/src/derives.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.37 by akim, Thu Aug 1 18:13:29 2002 UTC revision 1.38 by eggert, Wed Dec 11 06:26:06 2002 UTC
# Line 1  Line 1 
1  /* Match rules with nonterminals for bison,  /* Match rules with nonterminals for bison,
2     Copyright (C) 1984, 1989, 2000, 2001, 2002  Free Software Foundation, Inc.  
3       Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software
4       Foundation, Inc.
5    
6     This file is part of Bison, the GNU Compiler Compiler.     This file is part of Bison, the GNU Compiler Compiler.
7    
# Line 20  Line 22 
22    
23    
24  #include "system.h"  #include "system.h"
25    
26  #include "getargs.h"  #include "getargs.h"
27  #include "symtab.h"  
 #include "reader.h"  
 #include "gram.h"  
28  #include "derives.h"  #include "derives.h"
29    #include "gram.h"
30    #include "reader.h"
31    #include "symtab.h"
32    
33  /* Linked list of rule numbers.  */  /* Linked list of rule numbers.  */
34  typedef struct rule_list_s  typedef struct rule_list
35  {  {
36    struct rule_list_s *next;    struct rule_list *next;
37    rule_t *value;    rule *value;
38  } rule_list_t;  } rule_list;
39    
40  rule_t ***derives = NULL;  rule ***derives = NULL;
41    
42  static void  static void
43  print_derives (void)  print_derives (void)
# Line 44  print_derives (void) Line 48  print_derives (void)
48    
49    for (i = ntokens; i < nsyms; i++)    for (i = ntokens; i < nsyms; i++)
50      {      {
51        rule_t **rp;        rule **rp;
52        fprintf (stderr, "\t%s derives\n", symbols[i]->tag);        fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
53        for (rp = derives[i]; *rp; ++rp)        for (rp = derives[i]; *rp; ++rp)
54          {          {
# Line 60  print_derives (void) Line 64  print_derives (void)
64  void  void
65  derives_compute (void)  derives_compute (void)
66  {  {
67    symbol_number_t i;    symbol_number i;
68    int r;    int r;
69    rule_t **q;    rule **q;
70    
71    /* DSET[NTERM] -- A linked list of the numbers of the rules whose    /* DSET[NTERM] -- A linked list of the numbers of the rules whose
72       LHS is NTERM.  */       LHS is NTERM.  */
73    rule_list_t **dset = XCALLOC (rule_list_t *, nvars) - ntokens;    rule_list **dset = XCALLOC (rule_list *, nvars) - ntokens;
74    
75    /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.    /* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
76       Instead of performing NRULES allocations for each, have an array       Instead of performing NRULES allocations for each, have an array
77       indexed by rule numbers.  */       indexed by rule numbers.  */
78    rule_list_t *delts = XCALLOC (rule_list_t, nrules);    rule_list *delts = XCALLOC (rule_list, nrules);
79    
80    for (r = nrules - 1; r >= 0; --r)    for (r = nrules - 1; r >= 0; --r)
81      {      {
82        symbol_number_t lhs = rules[r].lhs->number;        symbol_number lhs = rules[r].lhs->number;
83        rule_list_t *p = &delts[r];        rule_list *p = &delts[r];
84        /* A new LHS is found.  */        /* A new LHS is found.  */
85        p->next = dset[lhs];        p->next = dset[lhs];
86        p->value = &rules[r];        p->value = &rules[r];
# Line 86  derives_compute (void) Line 90  derives_compute (void)
90    /* DSET contains what we need under the form of a linked list.  Make    /* DSET contains what we need under the form of a linked list.  Make
91       it a single array.  */       it a single array.  */
92    
93    derives = XCALLOC (rule_t **, nvars) - ntokens;    derives = XCALLOC (rule **, nvars) - ntokens;
94    q = XCALLOC (rule_t *, nvars + int_of_rule_number (nrules));    q = XCALLOC (rule *, nvars + int_of_rule_number (nrules));
95    
96    for (i = ntokens; i < nsyms; i++)    for (i = ntokens; i < nsyms; i++)
97      {      {
98        rule_list_t *p = dset[i];        rule_list *p = dset[i];
99        derives[i] = q;        derives[i] = q;
100        while (p)        while (p)
101          {          {

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.38

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26