1 /*
2  * fcache.c
3  *
4  * SOFTWARE RIGHTS
5  *
6  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
7  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
8  * company may do whatever they wish with source code distributed with
9  * PCCTS or the code generated by PCCTS, including the incorporation of
10  * PCCTS, or its output, into commerical software.
11  *
12  * We encourage users to develop software with PCCTS.  However, we do ask
13  * that credit is given to us for developing PCCTS.  By "credit",
14  * we mean that if you incorporate our source code into one of your
15  * programs (commercial product, research project, or otherwise) that you
16  * acknowledge this fact somewhere in the documentation, research report,
17  * etc...  If you like PCCTS and have developed a nice tool with the
18  * output, please mention that you developed it using PCCTS.  In
19  * addition, we ask that this header remain intact in our source code.
20  * As long as these guidelines are kept, we expect to continue enhancing
21  * this system and expect to make other tools available as they are
22  * completed.
23  *
24  * ANTLR 1.33MR10
25  *
26  */
27 
28 #include <stdio.h>
29 #include <ctype.h>
30 
31 #include "pcctscfg.h"
32 
33 #include "set.h"
34 #include "syn.h"
35 #include "hash.h"
36 #include "generic.h"
37 
38 #ifdef __USE_PROTOS
dumpFcache1(char * prev)39 CacheEntry *dumpFcache1(char *prev)
40 #else
41 CacheEntry *dumpFcache1(prev)
42   char  *prev;
43 #endif
44 {
45     Entry   **table=Fcache;
46 
47     int     low=0;
48     int     hi=0;
49 
50     CacheEntry  *least=NULL;
51 
52 	Entry   **p;
53 
54 	for (p=table; p<&(table[HashTableSize]); p++) {
55 
56 		CacheEntry *q =(CacheEntry *) *p;
57 
58 		if ( q != NULL && low==0 ) low = p-table;
59 		while ( q != NULL ) {
60             if (strcmp(q->str,prev) > 0) {
61               if (least == NULL) {
62                 least=q;
63               } else {
64                 if (strcmp(q->str,least->str) < 0) {
65                   least=q;
66                 };
67               };
68             };
69 			q = q->next;
70 		};
71 
72 		if ( *p != NULL ) hi = p-table;
73 	}
74     return least;
75 }
76 
77 #ifdef __USE_PROTOS
reportFcache(CacheEntry * q)78 void reportFcache(CacheEntry *q)
79 #else
80 void reportFcache(q)
81   CacheEntry    *q;
82 #endif
83 {
84     char        *qstr;
85 
86     fprintf(stdout,"\nrule ");
87     for (qstr=q->str; *qstr != '*' ; qstr++) {
88       fprintf(stdout,"%c",*qstr);
89     };
90 
91     qstr++;
92     if (*qstr == 'i') fprintf(stdout," First[");
93     if (*qstr == 'o') fprintf(stdout," Follow[");
94     qstr++;
95     fprintf(stdout,"%s]",qstr);
96     if (q->incomplete) fprintf(stdout," *** incomplete ***");
97     fprintf(stdout,"\n");
98     MR_dumpTokenSet(stdout,1,q->fset);
99 }
100 
101 void
102 #ifdef __USE_PROTOS
DumpFcache(void)103 DumpFcache(void)
104 #else
105 DumpFcache()
106 #endif
107 {
108 
109     char        *prev="";
110     int          n=0;
111     CacheEntry  *next;
112 
113     fprintf(stdout,"\n\nDump of First/Follow Cache\n");
114 
115     for(;;) {
116       next=dumpFcache1(prev);
117       if (next == NULL) break;
118       reportFcache(next);
119       ++n;
120       prev=next->str;
121     };
122     fprintf(stdout,"\nEnd dump of First/Follow Cache\n");
123 }
124