]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/CCode/Source/Pccts/h/dlgauto.h
remove unnecessary check for NULL pointer.
[mirror_edk2.git] / Tools / CCode / Source / Pccts / h / dlgauto.h
CommitLineData
878ddf1f 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-2000\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 if (c != '\0') {\r
310 zznextpos = zzbegexpr + 1;\r
311 }\r
312 else {\r
313 zznextpos = zzbegexpr; /* MR30 Zero terminates string. */\r
314 }\r
315}\r
316\r
317/* replace the string s for the reg. expr last matched and in the buffer */\r
318void\r
319#ifdef __USE_PROTOS\r
320zzreplstr(register zzchar_t *s)\r
321#else\r
322zzreplstr(s)\r
323register zzchar_t *s;\r
324#endif\r
325{\r
326 register zzchar_t *l= &zzlextext[zzbufsize -1];\r
327\r
328 zznextpos = zzbegexpr;\r
329 if (s){\r
330 while ((zznextpos <= l) && (*(zznextpos++) = *(s++))!=0){\r
331 /* empty */\r
332 }\r
333 /* correct for NULL at end of string */\r
334 zznextpos--;\r
335 }\r
336 if ((zznextpos <= l) && (*(--s) == 0)){\r
337 zzbufovf = 0;\r
338 }else{\r
339 zzbufovf = 1;\r
340 }\r
341 *(zznextpos) = '\0';\r
342 zzendexpr = zznextpos - 1;\r
343}\r
344\r
345#ifdef __USE_PROTOS\r
346void zzgettok(void)\r
347#else\r
348void zzgettok()\r
349#endif\r
350{\r
351 register int state, newstate;\r
352 /* last space reserved for the null char */\r
353 zzchar_t *lastpos; /* MR27 Remove register since address operator used. */\r
354\r
355skip:\r
356 zzreal_line = zzline;\r
357 zzbufovf = 0;\r
358 lastpos = &zzlextext[zzbufsize-1];\r
359 zznextpos = zzlextext;\r
360 zzbegcol = zzendcol+1;\r
361more:\r
362 zzbegexpr = zznextpos;\r
363#ifdef ZZINTERACTIVE\r
364 /* interactive version of automaton */\r
365 /* if there is something in zzchar, process it */\r
366 state = newstate = dfa_base[zzauto];\r
367 if (zzcharfull){\r
368 ZZINC;\r
369 ZZCOPY;\r
370 ZZNEWSTATE;\r
371 }\r
372 if (zzstr_in)\r
373 while (zzalternatives[newstate]){\r
374 state = newstate;\r
375 ZZGETC_STR;\r
376 ZZINC;\r
377 ZZCOPY;\r
378 ZZNEWSTATE;\r
379 }\r
380 else if (zzstream_in)\r
381 while (zzalternatives[newstate]){\r
382 state = newstate;\r
383 ZZGETC_STREAM;\r
384 ZZINC;\r
385 ZZCOPY;\r
386 ZZNEWSTATE;\r
387 }\r
388 else if (zzfunc_in)\r
389 while (zzalternatives[newstate]){\r
390 state = newstate;\r
391 ZZGETC_FUNC;\r
392 ZZINC;\r
393 ZZCOPY;\r
394 ZZNEWSTATE;\r
395 }\r
396 /* figure out if last character really part of token */\r
397 if ((state != dfa_base[zzauto]) && (newstate == DfaStates)){\r
398 zzcharfull = 1;\r
399 --zznextpos;\r
400 }else{\r
401 zzcharfull = 0;\r
402 state = newstate;\r
403 }\r
404 *(zznextpos) = '\0';\r
405 /* Able to transition out of start state to some non err state?*/\r
406 if ( state == dfa_base[zzauto] ){\r
407 /* make sure doesn't get stuck */\r
408 zzadvance();\r
409 }\r
410#else\r
411 /* non-interactive version of automaton */\r
412 if (!zzcharfull)\r
413 zzadvance();\r
414 else\r
415 ZZINC;\r
416 state = dfa_base[zzauto];\r
417 if (zzstr_in)\r
418 while (ZZNEWSTATE != DfaStates){\r
419 state = newstate;\r
420 ZZCOPY;\r
421 ZZGETC_STR;\r
422 ZZINC;\r
423 }\r
424 else if (zzstream_in)\r
425 while (ZZNEWSTATE != DfaStates){\r
426 state = newstate;\r
427 ZZCOPY;\r
428 ZZGETC_STREAM;\r
429 ZZINC;\r
430 }\r
431 else if (zzfunc_in)\r
432 while (ZZNEWSTATE != DfaStates){\r
433 state = newstate;\r
434 ZZCOPY;\r
435 ZZGETC_FUNC;\r
436 ZZINC;\r
437 }\r
438 zzcharfull = 1;\r
439 if ( state == dfa_base[zzauto] ){\r
440 if (zznextpos < lastpos){\r
441 *(zznextpos++) = zzchar;\r
442 }else{\r
443 zzbufovf = 1;\r
444 }\r
445 *zznextpos = '\0';\r
446 /* make sure doesn't get stuck */\r
447 zzadvance();\r
448 }else{\r
449 *zznextpos = '\0';\r
450 }\r
451#endif\r
452#ifdef ZZCOL\r
453 zzendcol -= zzcharfull;\r
454#endif\r
455 zzendexpr = zznextpos -1;\r
456 zzadd_erase = 0;\r
457 (*actions[accepts[state]])();\r
458 switch (zzadd_erase) {\r
459 case 1: goto skip;\r
460 case 2: goto more;\r
461 }\r
462}\r
463\r
464#ifdef __USE_PROTOS\r
465void zzadvance(void)\r
466#else\r
467void zzadvance()\r
468#endif\r
469{\r
470 if (zzstream_in) { ZZGETC_STREAM; zzcharfull = 1; ZZINC;}\r
471 if (zzfunc_in) { ZZGETC_FUNC; zzcharfull = 1; ZZINC;}\r
472 if (zzstr_in) { ZZGETC_STR; zzcharfull = 1; ZZINC;}\r
473 if (!(zzstream_in || zzfunc_in || zzstr_in)){\r
474 zzerr_in();\r
475 }\r
476}\r
477\r
478void\r
479#ifdef __USE_PROTOS\r
480zzerrstd(const char *s)\r
481#else\r
482zzerrstd(s)\r
483char *s;\r
484#endif\r
485{\r
486 zzLexErrCount++; /* MR11 */\r
487 fprintf(stderr,\r
488 "%s near line %d (text was '%s')\n",\r
489 ((s == NULL) ? "Lexical error" : s),\r
490 zzline,zzlextext);\r
491}\r
492\r
493#ifdef __USE_PROTOS\r
494int zzerr_in(void)\r
495#else\r
496int zzerr_in()\r
497#endif\r
498{\r
499 fprintf(stderr,"No input stream, function, or string\n");\r
500 /* return eof to get out gracefully */\r
501 return EOF;\r
502}\r
503\r
504#endif\r