]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/h/dlgauto.h
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Other / Maintained / Tools / Pccts / h / dlgauto.h
CommitLineData
3eb9473e 1/* dlgauto.h automaton\r
2 *\r
3 * SOFTWARE RIGHTS\r
4 *\r
5 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
6 * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
7 * company may do whatever they wish with source code distributed with\r
8 * PCCTS or the code generated by PCCTS, including the incorporation of\r
9 * PCCTS, or its output, into commerical software.\r
10 *\r
11 * We encourage users to develop software with PCCTS. However, we do ask\r
12 * that credit is given to us for developing PCCTS. By "credit",\r
13 * we mean that if you incorporate our source code into one of your\r
14 * programs (commercial product, research project, or otherwise) that you\r
15 * acknowledge this fact somewhere in the documentation, research report,\r
16 * etc... If you like PCCTS and have developed a nice tool with the\r
17 * output, please mention that you developed it using PCCTS. In\r
18 * addition, we ask that this header remain intact in our source code.\r
19 * As long as these guidelines are kept, we expect to continue enhancing\r
20 * this system and expect to make other tools available as they are\r
21 * completed.\r
22 *\r
23 * ANTLR 1.33\r
24 * Will Cohen and Terence Parr\r
25 * Parr Research Corporation\r
26 * with Purdue University and AHPCRC, University of Minnesota\r
27 * 1989-1998\r
28 */\r
29\r
30#ifndef ZZDEFAUTO_H\r
31#define ZZDEFAUTO_H\r
32\r
33/* 10-Apr-97 133MR1 Uses __USE_PROTOS show should #include pcctscfg.h */\r
34\r
35#include "pcctscfg.h"\r
36\r
37zzchar_t *zzlextext; /* text of most recently matched token */\r
38zzchar_t *zzbegexpr; /* beginning of last reg expr recogn. */\r
39zzchar_t *zzendexpr; /* beginning of last reg expr recogn. */\r
40int zzbufsize = 0; /* number of characters in zzlextext */ /* MR7 */\r
41int zzbegcol = 0; /* column that first character of token is in*/\r
42int zzendcol = 0; /* column that last character of token is in */\r
43int zzline = 1; /* line current token is on */\r
44int zzreal_line=1; /* line of 1st portion of token that is not skipped */\r
45int zzchar; /* character to determine next state */\r
46int zzbufovf; /* indicates that buffer too small for text */\r
47int zzcharfull = 0;\r
48static zzchar_t *zznextpos;/* points to next available position in zzlextext*/\r
49static int zzclass;\r
50\r
51#ifdef __USE_PROTOS\r
52void zzerrstd(const char *);\r
53void (*zzerr)(const char *)=zzerrstd;/* pointer to error reporting function */\r
54extern int zzerr_in(void);\r
55static int (*zzfunc_in)(void) = zzerr_in; /* MR20 */\r
56#else\r
57void zzerrstd();\r
58void (*zzerr)()=zzerrstd; /* pointer to error reporting function */\r
59extern int zzerr_in();\r
60static int (*zzfunc_in)() = zzerr_in; /* MR20 */\r
61#endif\r
62\r
63static FILE *zzstream_in=0;\r
64static zzchar_t *zzstr_in=0;\r
65\r
66#ifdef USER_ZZMODE_STACK\r
67int zzauto = 0;\r
68#else\r
69static int zzauto = 0;\r
70#endif\r
71static int zzadd_erase;\r
72static char zzebuf[70];\r
73\r
74#ifdef ZZCOL\r
75#define ZZINC (++zzendcol)\r
76#else\r
77#define ZZINC\r
78#endif\r
79\r
80\r
81#define ZZGETC_STREAM {zzchar = getc(zzstream_in); zzclass = ZZSHIFT(zzchar);}\r
82#define ZZGETC_FUNC {zzchar = (*zzfunc_in)(); zzclass = ZZSHIFT(zzchar);}\r
83#define ZZGETC_STR { \\r
84 if (*zzstr_in){ \\r
85 zzchar = *zzstr_in; \\r
86 ++zzstr_in; \\r
87 }else{ \\r
88 zzchar = EOF; \\r
89 } \\r
90 zzclass = ZZSHIFT(zzchar); \\r
91}\r
92\r
93#define ZZNEWSTATE (newstate = dfa[state][zzclass])\r
94\r
95#ifndef ZZCOPY\r
96#define ZZCOPY \\r
97 /* Truncate matching buffer to size (not an error) */ \\r
98 if (zznextpos < lastpos){ \\r
99 *(zznextpos++) = zzchar; \\r
100 }else{ \\r
101 zzbufovf = 1; \\r
102 }\r
103#endif\r
104\r
105void\r
106#ifdef __USE_PROTOS\r
107zzrdstream( FILE *f )\r
108#else\r
109zzrdstream( f )\r
110FILE *f;\r
111#endif\r
112{\r
113 /* make sure that it is really set to something, otherwise just\r
114 leave it be.\r
115 */\r
116 if (f){\r
117 /* make sure that there is always someplace to get input\r
118 before closing zzstream_in\r
119 */\r
120#if 0\r
121 if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );\r
122#endif\r
123 zzline = 1;\r
124 zzstream_in = f;\r
125 zzfunc_in = NULL;\r
126 zzstr_in = 0;\r
127 zzcharfull = 0;\r
128 }\r
129}\r
130\r
131void\r
132#ifdef __USE_PROTOS\r
133zzrdfunc( int (*f)(void) )\r
134#else\r
135zzrdfunc( f )\r
136int (*f)();\r
137#endif\r
138{\r
139 /* make sure that it is really set to something, otherwise just\r
140 leave it be.\r
141 */\r
142 if (f){\r
143 /* make sure that there is always someplace to get input\r
144 before closing zzstream_in\r
145 */\r
146#if 0\r
147 if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );\r
148#endif\r
149 zzline = 1;\r
150 zzstream_in = NULL;\r
151 zzfunc_in = f;\r
152 zzstr_in = 0;\r
153 zzcharfull = 0;\r
154 }\r
155}\r
156\r
157\r
158void\r
159#ifdef __USE_PROTOS\r
160zzrdstr( zzchar_t *s )\r
161#else\r
162zzrdstr( s )\r
163zzchar_t *s;\r
164#endif\r
165{\r
166 /* make sure that it is really set to something, otherwise just\r
167 leave it be.\r
168 */\r
169 if (s){\r
170 /* make sure that there is always someplace to get input\r
171 before closing zzstream_in\r
172 */\r
173#if 0\r
174 if (zzstream_in && zzstream_in!=stdin) fclose( zzstream_in );\r
175#endif\r
176 zzline = 1;\r
177 zzstream_in = NULL;\r
178 zzfunc_in = 0;\r
179 zzstr_in = s;\r
180 zzcharfull = 0;\r
181 }\r
182}\r
183\r
184\r
185#ifdef __USE_PROTOS\r
186void zzclose_stream(void)\r
187#else\r
188void zzclose_stream()\r
189#endif\r
190{\r
191#if 0\r
192 fclose( zzstream_in );\r
193 zzstream_in = NULL;\r
194 zzfunc_in = NULL;\r
195#endif\r
196}\r
197\r
198/* saves dlg state, but not what feeds dlg (such as file position) */\r
199void\r
200#ifdef __USE_PROTOS\r
201zzsave_dlg_state(struct zzdlg_state *state)\r
202#else\r
203zzsave_dlg_state(state)\r
204struct zzdlg_state *state;\r
205#endif\r
206{\r
207 state->stream = zzstream_in;\r
208 state->func_ptr = zzfunc_in;\r
209 state->str = zzstr_in;\r
210 state->auto_num = zzauto;\r
211 state->add_erase = zzadd_erase;\r
212 state->lookc = zzchar;\r
213 state->char_full = zzcharfull;\r
214 state->begcol = zzbegcol;\r
215 state->endcol = zzendcol;\r
216 state->line = zzline;\r
217 state->lextext = zzlextext;\r
218 state->begexpr = zzbegexpr;\r
219 state->endexpr = zzendexpr;\r
220 state->bufsize = zzbufsize;\r
221 state->bufovf = zzbufovf;\r
222 state->nextpos = zznextpos;\r
223 state->class_num = zzclass;\r
224}\r
225\r
226void\r
227#ifdef __USE_PROTOS\r
228zzrestore_dlg_state(struct zzdlg_state *state)\r
229#else\r
230zzrestore_dlg_state(state)\r
231struct zzdlg_state *state;\r
232#endif\r
233{\r
234 zzstream_in = state->stream;\r
235 zzfunc_in = state->func_ptr;\r
236 zzstr_in = state->str;\r
237 zzauto = state->auto_num;\r
238 zzadd_erase = state->add_erase;\r
239 zzchar = state->lookc;\r
240 zzcharfull = state->char_full;\r
241 zzbegcol = state->begcol;\r
242 zzendcol = state->endcol;\r
243 zzline = state->line;\r
244 zzlextext = state->lextext;\r
245 zzbegexpr = state->begexpr;\r
246 zzendexpr = state->endexpr;\r
247 zzbufsize = state->bufsize;\r
248 zzbufovf = state->bufovf;\r
249 zznextpos = state->nextpos;\r
250 zzclass = state->class_num;\r
251}\r
252\r
253void\r
254#ifdef __USE_PROTOS\r
255zzmode( int m )\r
256#else\r
257zzmode( m )\r
258int m;\r
259#endif\r
260{\r
261 /* points to base of dfa table */\r
262 if (m<MAX_MODE){\r
263 zzauto = m;\r
264 /* have to redo class since using different compression */\r
265 zzclass = ZZSHIFT(zzchar);\r
266 }else{\r
267 sprintf(zzebuf,"Invalid automaton mode = %d ",m);\r
268 zzerr(zzebuf);\r
269 }\r
270}\r
271\r
272/* erase what is currently in the buffer, and get a new reg. expr */\r
273\r
274#ifdef __USE_PROTOS\r
275void zzskip(void)\r
276#else\r
277void zzskip()\r
278#endif\r
279{\r
280 zzadd_erase = 1;\r
281}\r
282\r
283/* don't erase what is in the zzlextext buffer, add on to it */\r
284#ifdef __USE_PROTOS\r
285void zzmore()\r
286#else\r
287void zzmore()\r
288#endif\r
289{\r
290 zzadd_erase = 2;\r
291}\r
292\r
293/* substitute c for the reg. expr last matched and is in the buffer */\r
294#ifdef __USE_PROTOS\r
295void\r
296zzreplchar(zzchar_t c)\r
297#else\r
298void\r
299zzreplchar(c)\r
300zzchar_t c;\r
301#endif\r
302{\r
303 /* can't allow overwriting null at end of string */\r
304 if (zzbegexpr < &zzlextext[zzbufsize-1]){\r
305 *zzbegexpr = c;\r
306 *(zzbegexpr+1) = '\0';\r
307 }\r
308 zzendexpr = zzbegexpr;\r
309 zznextpos = zzbegexpr + 1;\r
310}\r
311\r
312/* replace the string s for the reg. expr last matched and in the buffer */\r
313void\r
314#ifdef __USE_PROTOS\r
315zzreplstr(register zzchar_t *s)\r
316#else\r
317zzreplstr(s)\r
318register zzchar_t *s;\r
319#endif\r
320{\r
321 register zzchar_t *l= &zzlextext[zzbufsize -1];\r
322\r
323 zznextpos = zzbegexpr;\r
324 if (s){\r
325 while ((zznextpos <= l) && (*(zznextpos++) = *(s++))!=0){\r
326 /* empty */\r
327 }\r
328 /* correct for NULL at end of string */\r
329 zznextpos--;\r
330 }\r
331 if ((zznextpos <= l) && (*(--s) == 0)){\r
332 zzbufovf = 0;\r
333 }else{\r
334 zzbufovf = 1;\r
335 }\r
336 *(zznextpos) = '\0';\r
337 zzendexpr = zznextpos - 1;\r
338}\r
339\r
340#ifdef __USE_PROTOS\r
341void zzgettok(void)\r
342#else\r
343void zzgettok()\r
344#endif\r
345{\r
346 register int state, newstate;\r
347 /* last space reserved for the null char */\r
348 register zzchar_t *lastpos;\r
349\r
350skip:\r
351 zzreal_line = zzline;\r
352 zzbufovf = 0;\r
353 lastpos = &zzlextext[zzbufsize-1];\r
354 zznextpos = zzlextext;\r
355 zzbegcol = zzendcol+1;\r
356more:\r
357 zzbegexpr = zznextpos;\r
358#ifdef ZZINTERACTIVE\r
359 /* interactive version of automaton */\r
360 /* if there is something in zzchar, process it */\r
361 state = newstate = dfa_base[zzauto];\r
362 if (zzcharfull){\r
363 ZZINC;\r
364 ZZCOPY;\r
365 ZZNEWSTATE;\r
366 }\r
367 if (zzstr_in)\r
368 while (zzalternatives[newstate]){\r
369 state = newstate;\r
370 ZZGETC_STR;\r
371 ZZINC;\r
372 ZZCOPY;\r
373 ZZNEWSTATE;\r
374 }\r
375 else if (zzstream_in)\r
376 while (zzalternatives[newstate]){\r
377 state = newstate;\r
378 ZZGETC_STREAM;\r
379 ZZINC;\r
380 ZZCOPY;\r
381 ZZNEWSTATE;\r
382 }\r
383 else if (zzfunc_in)\r
384 while (zzalternatives[newstate]){\r
385 state = newstate;\r
386 ZZGETC_FUNC;\r
387 ZZINC;\r
388 ZZCOPY;\r
389 ZZNEWSTATE;\r
390 }\r
391 /* figure out if last character really part of token */\r
392 if ((state != dfa_base[zzauto]) && (newstate == DfaStates)){\r
393 zzcharfull = 1;\r
394 --zznextpos;\r
395 }else{\r
396 zzcharfull = 0;\r
397 state = newstate;\r
398 }\r
399 *(zznextpos) = '\0';\r
400 /* Able to transition out of start state to some non err state?*/\r
401 if ( state == dfa_base[zzauto] ){\r
402 /* make sure doesn't get stuck */\r
403 zzadvance();\r
404 }\r
405#else\r
406 /* non-interactive version of automaton */\r
407 if (!zzcharfull)\r
408 zzadvance();\r
409 else\r
410 ZZINC;\r
411 state = dfa_base[zzauto];\r
412 if (zzstr_in)\r
413 while (ZZNEWSTATE != DfaStates){\r
414 state = newstate;\r
415 ZZCOPY;\r
416 ZZGETC_STR;\r
417 ZZINC;\r
418 }\r
419 else if (zzstream_in)\r
420 while (ZZNEWSTATE != DfaStates){\r
421 state = newstate;\r
422 ZZCOPY;\r
423 ZZGETC_STREAM;\r
424 ZZINC;\r
425 }\r
426 else if (zzfunc_in)\r
427 while (ZZNEWSTATE != DfaStates){\r
428 state = newstate;\r
429 ZZCOPY;\r
430 ZZGETC_FUNC;\r
431 ZZINC;\r
432 }\r
433 zzcharfull = 1;\r
434 if ( state == dfa_base[zzauto] ){\r
435 if (zznextpos < lastpos){\r
436 *(zznextpos++) = zzchar;\r
437 }else{\r
438 zzbufovf = 1;\r
439 }\r
440 *zznextpos = '\0';\r
441 /* make sure doesn't get stuck */\r
442 zzadvance();\r
443 }else{\r
444 *zznextpos = '\0';\r
445 }\r
446#endif\r
447#ifdef ZZCOL\r
448 zzendcol -= zzcharfull;\r
449#endif\r
450 zzendexpr = zznextpos -1;\r
451 zzadd_erase = 0;\r
452 (*actions[accepts[state]])();\r
453 switch (zzadd_erase) {\r
454 case 1: goto skip;\r
455 case 2: goto more;\r
456 }\r
457}\r
458\r
459#ifdef __USE_PROTOS\r
460void zzadvance(void)\r
461#else\r
462void zzadvance()\r
463#endif\r
464{\r
465 if (zzstream_in) { ZZGETC_STREAM; zzcharfull = 1; ZZINC;}\r
466 if (zzfunc_in) { ZZGETC_FUNC; zzcharfull = 1; ZZINC;}\r
467 if (zzstr_in) { ZZGETC_STR; zzcharfull = 1; ZZINC;}\r
468 if (!(zzstream_in || zzfunc_in || zzstr_in)){\r
469 zzerr_in();\r
470 }\r
471}\r
472\r
473void\r
474#ifdef __USE_PROTOS\r
475zzerrstd(const char *s)\r
476#else\r
477zzerrstd(s)\r
478char *s;\r
479#endif\r
480{\r
481 zzLexErrCount++; /* MR11 */\r
482 fprintf(stderr,\r
483 "%s near line %d (text was '%s')\n",\r
484 ((s == NULL) ? "Lexical error" : s),\r
485 zzline,zzlextext);\r
486}\r
487\r
488#ifdef __USE_PROTOS\r
489int zzerr_in(void)\r
490#else\r
491int zzerr_in()\r
492#endif\r
493{\r
494 fprintf(stderr,"No input stream, function, or string\n");\r
495 /* return eof to get out gracefully */\r
496 return EOF;\r
497}\r
498\r
499#endif\r