1 /**
2  * Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 /** \file
18  * \brief LR header files
19  *
20  *       This file declares all constants and varaiables global to all
21  *       LR (prstab) routines, also contains all the routine declarations.
22  *
23  */
24 
25 #ifndef PRSTAB_H
26 #define PRSTAB_H
27 
28 #define INT int
29 #define LOGICAL int
30 #define UINT unsigned int
31 #define FLOAT float
32 #define CHAR unsigned char
33 
34 #define VOID void
35 
36 #undef min
37 #undef max
38 #define min(a, b) ((a) <= (b) ? (a) : (b))
39 #define max(a, b) ((a) >= (b) ? (a) : (b))
40 
41 #if defined(__WIN64__) || defined(__WIN32__)
42 #define SNPRINTF _snprintf
43 #else
44 #define SNPRINTF snprintf
45 #endif
46 
47 #define MAXSHD 2000
48 #define MAXSHDP1 2001
49 #define MAXSHD2P1 4001
50 #define MAXSST 16000
51 #define MAXPRDC 10000
52 #define MAXPROD 4000
53 #define MAXLST 24000
54 #define MAXBAS 44000
55 #define MAXTRN 40000
56 #define MAXRED 10000
57 #define MAXSCR 6000
58 #define MAXHASH 2048
59 #define MAXLEN 1024
60 
61 /* Global Declarations */
62 
63 struct {
64   FILE *infile;
65   FILE *gramin;
66   FILE *tokin;
67   FILE *tokout;
68   FILE *lstfil;
69   FILE *datfil;
70   FILE *dbgfil;
71   FILE *semfil;
72 } files;
73 
74 INT *scrtch;
75 INT *hashpt;
76 CHAR *linech;
77 char *filnambuf;
78 
79 struct {
80   INT *item;
81   INT *nextt;
82 } s4;
83 
84 struct {
85   INT *sstore;
86   INT *sthead;
87 } s1_1;
88 
89 struct {
90   INT garbag;
91   INT lstptr;
92 } lstcom;
93 
94 struct {
95   INT qhead;
96   INT qtail;
97 } qcom;
98 
99 struct {
100   LOGICAL listsw;
101   LOGICAL runosw;
102   LOGICAL xrefsw;
103   LOGICAL toksw;
104   LOGICAL semsw;
105   LOGICAL datasw;
106   LOGICAL lrltsw;
107   LOGICAL dbgsw;
108   LOGICAL dbgasw;
109   LOGICAL dbgbsw;
110   LOGICAL dbgcsw;
111   LOGICAL dbgdsw;
112   LOGICAL dbgesw;
113 } switches;
114 
115 struct {
116   INT adequt;
117 } adqcom;
118 
119 struct {
120   INT *lftuse;
121   INT *rgtuse;
122   INT *frsprd;
123   INT *nprods;
124   INT *prodcn;
125   INT *prdind;
126   INT *vocab;
127   INT nvoc;
128   INT numprd;
129   INT goal;
130   INT nterms;
131 } g_1;
132 
133 struct {
134   INT nstate;
135   INT nxttrn;
136   INT nxtred;
137   INT ncsets;
138   INT listcs;
139   INT ifinal;
140   INT indbas;
141   INT lencsl;
142   INT lsets;
143   INT *thedpt;
144   INT *nullnt;
145   INT *basis;
146   INT *tran;
147   INT *red;
148 } s_1;
149 
150 struct {
151   INT sstptr;
152   INT shdptr;
153 } string_1;
154 
155 struct {
156   INT linbuf[81];
157   INT curchr;
158   INT lineno;
159   INT fstchr;
160 } readcm;
161 
162 struct {
163   INT pnum;
164   INT brkflg;
165   INT semnum;
166 } ptsem;
167 
168 /*
169  * a local array line is used to constuct a line of text to be written
170  * to a file.  Because the output routines are not yet "char *" - based,
171  * line is an INT array.  Use a macro to declare line so that it's
172  * trivial to change to a char array when the I/O is improved.
173  */
174 #define DECL_LINE(n) INT line[n]
175 
176 /* Functions Declaration */
177 
178 /* prstab1 */
179 INT enter(INT *buff, INT *len);
180 INT error(char *msg, INT msglen, INT ibad, INT sym, INT alias);
181 INT fndnul(void), bildhp(void), finish(void);
182 INT endbas(INT *iptr);
183 INT complt(INT *istate, INT *maxset);
184 INT enque(INT *iptr), deque(INT *iptr);
185 INT csun(INT *iptr1, INT *iptr2, INT *ich);
186 INT delcs(INT *iptr);
187 INT condec(INT number, INT *line, INT istart, INT iend);
188 INT additl(INT *iarg, INT *lptr, INT *ichnge);
189 INT addltl(INT *lptr1, INT *lptr2, INT *ichnge);
190 INT copyl(INT *lptr1, INT *lptr2);
191 INT chrcmp(INT *iptr1, INT *iptr2, INT *irslt);
192 INT addbas(INT iptr, INT npr, INT ndot, INT nset);
193 INT addtrn(INT *ibasis, INT *itran, INT *imax);
194 INT endtrn(INT *ibasis);
195 INT addred(INT *ibasis, INT *iprod, INT *icntxt, INT *maxr);
196 INT endred(INT *ibasis);
197 
198 /* prstab2 */
199 INT hashof(INT *i);
200 INT lenlst(INT *ihead);
201 INT length(INT *iptr);
202 INT log76(INT *iarg);
203 INT lcompr(INT *iptr1, INT *iptr2);
204 INT movstr(INT iptr, INT *line, INT *istart, INT iend);
205 INT output(FILE *unit, INT *line, INT nchars);
206 INT new (INT *iptr), newbas(INT *index), newcs(INT *is, INT *iptr);
207 INT genthd(void);
208 INT hepify(INT iptr, INT imax);
209 INT imtrcs(INT *ibasis, INT *iptr);
210 INT putsem(INT curlhs, INT *curprd);
211 INT hlddmp(INT *hold, INT *hldidx);
212 INT newtrn(INT *ibasis, INT *imax);
213 INT merge(INT *ibasis, INT *ires, INT *ichng);
214 INT newred(INT *ibasis, INT *imax);
215 INT less(INT *iptr1, INT *iptr2);
216 
217 /* prstab3 */
218 INT strcomp(INT *iptr1, INT *iptr2, INT *irslt);
219 INT sortcg(INT *nsets);
220 INT trnred(INT *ibasis, INT *jmax);
221 INT rel(INT *iptr);
222 INT scan(INT *token);
223 
224 INT init(void), xref(void), tablea(void), gentab(void), rdgram(void),
225     fndgol(void), tokmac(void), conect(void), chncsl(void), tableu(void),
226     finish(void), ground(void), analyz(void), prntgm(void), sortgm(void),
227     pntset(void), zprntk(void);
228 
229 void intArrayToCharArray(INT *intarr, CHAR *charr, INT count);
230 
231 #endif
232