]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/Pccts/h/dlgauto.h
5 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
6 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
7 * company may do whatever they wish with source code distributed with
8 * PCCTS or the code generated by PCCTS, including the incorporation of
9 * PCCTS, or its output, into commerical software.
11 * We encourage users to develop software with PCCTS. However, we do ask
12 * that credit is given to us for developing PCCTS. By "credit",
13 * we mean that if you incorporate our source code into one of your
14 * programs (commercial product, research project, or otherwise) that you
15 * acknowledge this fact somewhere in the documentation, research report,
16 * etc... If you like PCCTS and have developed a nice tool with the
17 * output, please mention that you developed it using PCCTS. In
18 * addition, we ask that this header remain intact in our source code.
19 * As long as these guidelines are kept, we expect to continue enhancing
20 * this system and expect to make other tools available as they are
24 * Will Cohen and Terence Parr
25 * Parr Research Corporation
26 * with Purdue University and AHPCRC, University of Minnesota
33 /* 10-Apr-97 133MR1 Uses __USE_PROTOS show should #include pcctscfg.h */
37 zzchar_t
*zzlextext
; /* text of most recently matched token */
38 zzchar_t
*zzbegexpr
; /* beginning of last reg expr recogn. */
39 zzchar_t
*zzendexpr
; /* beginning of last reg expr recogn. */
40 int zzbufsize
= 0; /* number of characters in zzlextext */ /* MR7 */
41 int zzbegcol
= 0; /* column that first character of token is in*/
42 int zzendcol
= 0; /* column that last character of token is in */
43 int zzline
= 1; /* line current token is on */
44 int zzreal_line
=1; /* line of 1st portion of token that is not skipped */
45 int zzchar
; /* character to determine next state */
46 int zzbufovf
; /* indicates that buffer too small for text */
48 static zzchar_t
*zznextpos
;/* points to next available position in zzlextext*/
52 void zzerrstd(const char *);
53 void (*zzerr
)(const char *)=zzerrstd
;/* pointer to error reporting function */
54 extern int zzerr_in(void);
55 static int (*zzfunc_in
)(void) = zzerr_in
; /* MR20 */
58 void (*zzerr
)()=zzerrstd
; /* pointer to error reporting function */
59 extern int zzerr_in();
60 static int (*zzfunc_in
)() = zzerr_in
; /* MR20 */
63 static FILE *zzstream_in
=0;
64 static zzchar_t
*zzstr_in
=0;
66 #ifdef USER_ZZMODE_STACK
69 static int zzauto
= 0;
71 static int zzadd_erase
;
72 static char zzebuf
[70];
75 #define ZZINC (++zzendcol)
81 #define ZZGETC_STREAM {zzchar = getc(zzstream_in); zzclass = ZZSHIFT(zzchar);}
82 #define ZZGETC_FUNC {zzchar = (*zzfunc_in)(); zzclass = ZZSHIFT(zzchar);}
83 #define ZZGETC_STR { \
90 zzclass = ZZSHIFT(zzchar); \
93 #define ZZNEWSTATE (newstate = dfa[state][zzclass])
97 /* Truncate matching buffer to size (not an error) */ \
98 if (zznextpos < lastpos){ \
99 *(zznextpos++) = zzchar; \
107 zzrdstream( FILE *f
)
113 /* make sure that it is really set to something, otherwise just
117 /* make sure that there is always someplace to get input
118 before closing zzstream_in
121 if (zzstream_in
&& zzstream_in
!=stdin
) fclose( zzstream_in
);
133 zzrdfunc( int (*f
)(void) )
139 /* make sure that it is really set to something, otherwise just
143 /* make sure that there is always someplace to get input
144 before closing zzstream_in
147 if (zzstream_in
&& zzstream_in
!=stdin
) fclose( zzstream_in
);
160 zzrdstr( zzchar_t
*s
)
166 /* make sure that it is really set to something, otherwise just
170 /* make sure that there is always someplace to get input
171 before closing zzstream_in
174 if (zzstream_in
&& zzstream_in
!=stdin
) fclose( zzstream_in
);
186 void zzclose_stream(void)
188 void zzclose_stream()
192 fclose( zzstream_in
);
198 /* saves dlg state, but not what feeds dlg (such as file position) */
201 zzsave_dlg_state(struct zzdlg_state
*state
)
203 zzsave_dlg_state(state
)
204 struct zzdlg_state
*state
;
207 state
->stream
= zzstream_in
;
208 state
->func_ptr
= zzfunc_in
;
209 state
->str
= zzstr_in
;
210 state
->auto_num
= zzauto
;
211 state
->add_erase
= zzadd_erase
;
212 state
->lookc
= zzchar
;
213 state
->char_full
= zzcharfull
;
214 state
->begcol
= zzbegcol
;
215 state
->endcol
= zzendcol
;
216 state
->line
= zzline
;
217 state
->lextext
= zzlextext
;
218 state
->begexpr
= zzbegexpr
;
219 state
->endexpr
= zzendexpr
;
220 state
->bufsize
= zzbufsize
;
221 state
->bufovf
= zzbufovf
;
222 state
->nextpos
= zznextpos
;
223 state
->class_num
= zzclass
;
228 zzrestore_dlg_state(struct zzdlg_state
*state
)
230 zzrestore_dlg_state(state
)
231 struct zzdlg_state
*state
;
234 zzstream_in
= state
->stream
;
235 zzfunc_in
= state
->func_ptr
;
236 zzstr_in
= state
->str
;
237 zzauto
= state
->auto_num
;
238 zzadd_erase
= state
->add_erase
;
239 zzchar
= state
->lookc
;
240 zzcharfull
= state
->char_full
;
241 zzbegcol
= state
->begcol
;
242 zzendcol
= state
->endcol
;
243 zzline
= state
->line
;
244 zzlextext
= state
->lextext
;
245 zzbegexpr
= state
->begexpr
;
246 zzendexpr
= state
->endexpr
;
247 zzbufsize
= state
->bufsize
;
248 zzbufovf
= state
->bufovf
;
249 zznextpos
= state
->nextpos
;
250 zzclass
= state
->class_num
;
261 /* points to base of dfa table */
264 /* have to redo class since using different compression */
265 zzclass
= ZZSHIFT(zzchar
);
267 sprintf(zzebuf
,"Invalid automaton mode = %d ",m
);
272 /* erase what is currently in the buffer, and get a new reg. expr */
283 /* don't erase what is in the zzlextext buffer, add on to it */
293 /* substitute c for the reg. expr last matched and is in the buffer */
296 zzreplchar(zzchar_t c
)
303 /* can't allow overwriting null at end of string */
304 if (zzbegexpr
< &zzlextext
[zzbufsize
-1]){
306 *(zzbegexpr
+1) = '\0';
308 zzendexpr
= zzbegexpr
;
310 zznextpos
= zzbegexpr
+ 1;
313 zznextpos
= zzbegexpr
; /* MR30 Zero terminates string. */
317 /* replace the string s for the reg. expr last matched and in the buffer */
320 zzreplstr(register zzchar_t
*s
)
323 register zzchar_t
*s
;
326 register zzchar_t
*l
= &zzlextext
[zzbufsize
-1];
328 zznextpos
= zzbegexpr
;
330 while ((zznextpos
<= l
) && (*(zznextpos
++) = *(s
++))!=0){
333 /* correct for NULL at end of string */
336 if ((zznextpos
<= l
) && (*(--s
) == 0)){
342 zzendexpr
= zznextpos
- 1;
351 register int state
, newstate
;
352 /* last space reserved for the null char */
353 zzchar_t
*lastpos
; /* MR27 Remove register since address operator used. */
356 zzreal_line
= zzline
;
358 lastpos
= &zzlextext
[zzbufsize
-1];
359 zznextpos
= zzlextext
;
360 zzbegcol
= zzendcol
+1;
362 zzbegexpr
= zznextpos
;
364 /* interactive version of automaton */
365 /* if there is something in zzchar, process it */
366 state
= newstate
= dfa_base
[zzauto
];
373 while (zzalternatives
[newstate
]){
380 else if (zzstream_in
)
381 while (zzalternatives
[newstate
]){
389 while (zzalternatives
[newstate
]){
396 /* figure out if last character really part of token */
397 if ((state
!= dfa_base
[zzauto
]) && (newstate
== DfaStates
)){
405 /* Able to transition out of start state to some non err state?*/
406 if ( state
== dfa_base
[zzauto
] ){
407 /* make sure doesn't get stuck */
411 /* non-interactive version of automaton */
416 state
= dfa_base
[zzauto
];
418 while (ZZNEWSTATE
!= DfaStates
){
424 else if (zzstream_in
)
425 while (ZZNEWSTATE
!= DfaStates
){
432 while (ZZNEWSTATE
!= DfaStates
){
439 if ( state
== dfa_base
[zzauto
] ){
440 if (zznextpos
< lastpos
){
441 *(zznextpos
++) = zzchar
;
446 /* make sure doesn't get stuck */
453 zzendcol
-= zzcharfull
;
455 zzendexpr
= zznextpos
-1;
457 (*actions
[accepts
[state
]])();
458 switch (zzadd_erase
) {
470 if (zzstream_in
) { ZZGETC_STREAM
; zzcharfull
= 1; ZZINC
;}
471 if (zzfunc_in
) { ZZGETC_FUNC
; zzcharfull
= 1; ZZINC
;}
472 if (zzstr_in
) { ZZGETC_STR
; zzcharfull
= 1; ZZINC
;}
473 if (!(zzstream_in
|| zzfunc_in
|| zzstr_in
)){
480 zzerrstd(const char *s
)
486 zzLexErrCount
++; /* MR11 */
488 "%s near line %d (text was '%s')\n",
489 ((s
== NULL
) ? "Lexical error" : s
),
499 fprintf(stderr
,"No input stream, function, or string\n");
500 /* return eof to get out gracefully */