Annotation of capa/capa51/pProj/capaLexerDef.flex, revision 1.1.1.1
1.1 albertel 1: /*------------------------------------------------------------------------*/
2: /* capaLexerDef.flex created by Isaac Tsai Jul 15 1996 */
3: /* added /END(variable) */
4: /* added /HIN .... /DIS(variable) ... */
5: /* Jan 15 1998 /{KeyWord}{KeyWord}{KeyWord} */
6: /* replaced by /DIS */
7: /* catch "No /END() statement found" */
8: /* catch "/DIS(")" and "/DIS(""")" errors " */
9: /* catch "/LET var = " */
10: /* add a new token EoL to indicate '\n' '\r''\n' and '\r' */
11: /* This file is based on flex 2.5.3, flex 2.3 apparantly cannot take it :-( */
12: /* DONE /RMAP() function July 14, 1998 */
13: /* DONE /AND /OR answer formats July 20, 1998 */
14: /* DONE /IF () /ENDIF July 26, 1998 */
15: /* DONE /WHILE () /ENDWHILE August 10 1998 */
16: /* DONE /VERB /ENDVERB Feb 20 1998 */
17: /*------------------------------------------------------------------------*/
18: /**************************************************************************/
19:
20: %{
21:
22: #include <stdio.h>
23: #include <stdlib.h> /* strtod(), strtol() */
24: #include <string.h>
25: #ifdef NeXT
26: #include <sys/file.h>
27: #else
28: #include <unistd.h> /* access() */
29: #endif
30:
31: #include "capaToken.h" /* from YACC -d capaGrammarDef.y */
32: #include "capaCommon.h" /* capa_access() */
33: #include "capaParser.h" /* _symbol structure def */
34: #include "lex_debug.h" /* defined RETURN(xxx) macro */
35:
36:
37:
38: /* ============================================== begin of code */
39:
40: #define LEX_BUFLEN (8*1024) /* lexical buffer size (for each opened file) */
41:
42: #ifdef YYLMAX
43: #undef YYLMAX
44: #define YYLMAX 8192
45: #endif
46:
47: void yyfatalerror(char*msg);
48: #define YY_FATAL_ERROR yyfatalerror
49:
50: #ifdef LEX_DBUG
51: #define LLDBUG_PRL1(xx) { printf("Line %d ",Current_line[Input_idx]); printf(xx); fflush(stdout); }
52: #define LLDBUG_PRL2(xx,yy) { printf("Line %d ",Current_line[Input_idx]); printf(xx,yy); fflush(stdout); }
53: #define LLDBUG_PR1(xx) { printf(xx); fflush(stdout); }
54: #define LLDBUG_PR2(xx,yy) { printf(xx,yy); fflush(stdout); }
55: #define LLDBUG_PR3(xx,yy,zz) { printf(xx,yy,zz); fflush(stdout); }
56: #else
57: #define LLDBUG_PRL1(xx) { }
58: #define LLDBUG_PRL2(xx,yy) { }
59: #define LLDBUG_PR1(xx) { }
60: #define LLDBUG_PR2(xx,yy) { }
61: #define LLDBUG_PR3(xx,yy,zz) { }
62: #endif
63:
64: #ifdef LEX_INPUT_DBUG
65: #define LIDBUG_PR1(xx) { printf(xx); fflush(stdout); }
66: #define LIDBUG_PR2(xx,yy) { printf(xx,yy); fflush(stdout); }
67: #define LIDBUG_PR3(xx,yy,zz) { printf(xx,yy,zz); fflush(stdout); }
68: #else
69: #define LIDBUG_PR1(xx) { }
70: #define LIDBUG_PR2(xx,yy) { }
71: #define LIDBUG_PR3(xx,yy,zz) { }
72: #endif
73:
74: #ifdef USE_DYNAMIC_SYMBOLS
75: #define USE_DYNAMIC_LEXBUFS
76: #endif
77:
78: Symbol *yylval; /* global pointer to symbol */
79:
80: FILE *(Input_stream[MAX_OPENED_FILE]); /* <-- perhaps we can use linked list */
81: char Opened_filename[MAX_OPENED_FILE][QUARTER_K]; /* <-- perhaps we can use linked list */
82: int Input_idx;
83: int Lexi_pos[MAX_OPENED_FILE]; /* Current position in the line */
84:
85: #ifdef USE_DYNAMIC_LEXBUFS
86: char *(Lexi_buf[MAX_OPENED_FILE]); /* Line Buffer for current file */
87:
88: #else
89: char Lexi_buf[MAX_OPENED_FILE][LEX_BUFLEN+4]; /* Line Buffer for current file */
90:
91: #endif /* USE_DYNAMIC_LEXBUFS */
92:
93: char String_buf[LEX_BUFLEN]; /* Constant String buffer <-- perhaps we can use char pointer */
94: char *Dynamic_buf;
95: int Dynamic_buf_max;
96: int Dynamic_buf_cur;
97:
98:
99: static int End_of_input;
100: static int Pcount, Bcount; /* static means only available in this file */
101: /* --------------------------------------------------------------------------- */
102: /* GLOBAL VARIABLES */
103: /* --------------------------------------------------------------------------- */
104: int Lexi_line; /* Current source file line number, counting from beginning */
105: extern int Current_line[MAX_OPENED_FILE];
106:
107: int Func_idx;
108: Symbol FuncStack[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */
109:
110: int Array_idx;
111: Symbol *ArraySymbList_p;
112: Symbol *ArraySymbLast_p;
113: Symbol *FmlSymbList_p;
114: Symbol *FmlSymbLast_p;
115: int FmlSymb_cnt;
116: int Symb_count;
117:
118: int IFstatus[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */
119: int IFcurrent[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */
120: int IFcount;
121: WhileLoop_t WhileStack[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */
122: int While_idx, Wcount;
123:
124: #ifdef USE_DYNAMIC_SYMBOLS
125: Symbol *SymbList_p;
126: Symbol *SymbLast_p;
127: #else
128: Symbol SymbArray[MAX_SYMB_COUNT];
129: #endif /* USE_DYNAMIC_SYMBOLS */
130:
131:
132: char *Current_char_p; /* Collect string constant */
133: extern char *EndText_p;
134: extern char *StartText_p;
135: extern Problem_t *LexiProblem_p;
136: extern Problem_t *LastProblem_p;
137: int first_run=1;
138: int Stop_Parser;
139: #define FLEX
140:
141: #define YY_STACK_USED 1 /* for yy_push_state(), yy_pop_state() */
142:
143: #ifdef FLEX
144:
145: int capaL_unput();
146: int capaL_input();
147:
148:
149: /* YY_INPUT()
150: Controls scanner input. By default, YY_INPUT reads from the
151: file-pointer yyin. Its action is to place up to max_size
152: characters in the character array buf and return in the
153: integer variable result either the number of characters read
154: or the constant YY_NULL to indicate EOF.
155: max_size is defined to be num_to_read = 8192 in liby
156: Following is a sample
157: redefinition of YY_INPUT, in the definitions section of
158: the input file:
159:
160: %{
161: #undef YY_INPUT
162: #define YY_INPUT(buf,result,max_size)\
163: {\
164: int c = getchar();\
165: result = (c == EOF) ? YY_NULL : (buf[0] = c, 1);\
166: }
167: %}
168:
169: */
170:
171: /* fgets() reads the input stream until
172: n-1 bytes have been read OR
173: a newline character is read and transferred to string OR
174: an EOF (End-of-File) condition is encountered
175:
176: The string is then terminated with a NULL character.
177:
178: ii = fseek(FILE *stream,0L,SEEK_END) ;
179: if(ii!=0) { error }
180: leng = ftell(FILE *stream) + 1 ;
181: fseek(FILE *stream,0L,SEEK_SET) ;
182: Lexi_buf[Input_idx] = (char *)capa_malloc(sizeof(char)*leng,1);
183:
184: */
185:
186:
187: #ifdef AVOIDYYINPUT
188: #define MAX_INCLUDE_DEPTH 10
189: YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
190: int include_stack_ptr = 0;
191: #else
192: #ifdef USE_DYNAMIC_LEXBUFS
193: #define NEWYYINPUT
194: #endif
195:
196: #ifdef NEWYYINPUT
197: void newyy_input (char *buf,int *result,int max_size);
198: #define YY_INPUT(buf,result,max_size) newyy_input(buf,&result,max_size)
199:
200: #else
201: #ifdef USE_DYNAMIC_LEXBUFS
202:
203: #define YY_INPUT(buf,result,max_size) \
204: { int ii, leng, out_of_char; \
205: if (!Lexi_line) { /* was startup */ \
206: for(ii=0;ii < MAX_OPENED_FILE;ii++) { \
207: Lexi_buf[ii] = NULL; \
208: Lexi_pos[ii] = 0; \
209: Current_line[ii] = 0; \
210: } \
211: Input_idx = 0; \
212: first_run=0; \
213: yyin = Input_stream[Input_idx]; LIDBUG_PR1("<<yy_input() startup>>\n"); \
214: } \
215: out_of_char = 0; \
216: if ( Lexi_buf[Input_idx] == NULL ) { \
217: Lexi_buf[Input_idx] = (char *)capa_malloc(sizeof(char)*LEX_BUFLEN+1,1); out_of_char=1; \
218: } else { \
219: if (!Lexi_buf[Input_idx][Lexi_pos[Input_idx]]) { /* test if the line buffer is empty or at the end */ \
220: out_of_char=1; \
221: } \
222: } \
223: if( out_of_char ) { \
224: if (fgets(Lexi_buf[Input_idx],LEX_BUFLEN-1,Input_stream[Input_idx])==NULL) { /* read in one line */ \
225: LIDBUG_PR2("<<yy_input() fgets() returns NULL, input index=%d>>\n",Input_idx); \
226: if( (Input_idx > 0) && ( Lexi_buf[Input_idx][Lexi_pos[Input_idx]] == '\0') ) { \
227: LIDBUG_PR2("<<yy_input() close an input stream, input index=%d>>\n",Input_idx); \
228: fclose(Input_stream[Input_idx]); \
229: capa_mfree((char *)Lexi_buf[Input_idx]); \
230: Lexi_buf[Input_idx] = NULL; \
231: Input_idx--; \
232: yyin = Input_stream[Input_idx]; \
233: /* (Lexi_pos[Input_idx])++; */ \
234: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1]; \
235: result = 1; \
236: } else { \
237: result = YY_NULL; /* End of File */ \
238: } \
239: } else { /* successfully read in one line */ \
240: if (Lexi_buf[Input_idx]==NULL) puts("Whatup?");\
241: leng = strlen(Lexi_buf[Input_idx]); \
242: LIDBUG_PR3("<<yy_input() read into buffer a line(leng=%d), input index=%d>>\n",leng,Input_idx); \
243: Lexi_pos[Input_idx] = 0; \
244: Lexi_line++; \
245: Current_line[Input_idx]++; \
246: (Lexi_pos[Input_idx])++; \
247: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1]; \
248: /* need to take care of return continuation conditions */ \
249: /* so, we return to one-char-at-a-time approach */ \
250: /* for(ii=0;ii<leng;ii++) { */ \
251: /* buf[ii] = Lexi_buf[Input_idx][ii]; */ \
252: /* } */ \
253: /* buf[ii] = '\0'; */ \
254: /* printf("YY_INPUT()(Lexi_line=%d,max size=%d)(%c)",Lexi_line,max_size,buf[0]); */ \
255: result = 1; \
256: } \
257: } else { \
258: /* LIDBUG_PR2("<<yy_input() increase Lexi_pos, input index=%d>>\n",Input_idx); */ \
259: (Lexi_pos[Input_idx])++; \
260: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1]; \
261: result = 1; \
262: } \
263: if (Stop_Parser==1) { \
264: result = YY_NULL; \
265: } \
266: }
267:
268: #else
269:
270: #define YY_INPUT(buf,result,max_size) \
271: { int ii, leng; \
272: if (!Lexi_line) { /* was startup */ \
273: for(ii=0;ii < MAX_OPENED_FILE;ii++) { \
274: Lexi_buf[ii][0]=0; \
275: Lexi_pos[ii] = 0; \
276: Current_line[ii] = 0; \
277: } \
278: Input_idx = 0; \
279: first_run=0; \
280: yyin = Input_stream[Input_idx]; LIDBUG_PR1("<<yy_input() startup>>\n"); \
281: } \
282: if (!Lexi_buf[Input_idx][Lexi_pos[Input_idx]]) { /* test if the line buffer is empty or at the end */ \
283: if (fgets(Lexi_buf[Input_idx],LEX_BUFLEN-1,Input_stream[Input_idx])==NULL) { /* read in one line */ \
284: LIDBUG_PR2("<<yy_input() fgets() returns NULL, input index=%d>>\n",Input_idx); \
285: if( (Input_idx > 0) && ( Lexi_buf[Input_idx][Lexi_pos[Input_idx]] == '\0') ) { \
286: LIDBUG_PR2("<<yy_input() close an input stream, input index=%d>>\n",Input_idx); \
287: fclose(Input_stream[Input_idx]); \
288: Input_idx--; \
289: yyin = Input_stream[Input_idx]; \
290: /* (Lexi_pos[Input_idx])++; */ \
291: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1]; \
292: result = 1; \
293: } else { \
294: result = YY_NULL; /* End of File */ \
295: } \
296: } else { /* successfully read in one line */ \
297: leng = strlen(Lexi_buf[Input_idx]); \
298: LIDBUG_PR3("<<yy_input() read into buffer a line(leng=%d), input index=%d>>\n",leng,Input_idx); \
299: Lexi_pos[Input_idx] = 0; \
300: Lexi_line++; \
301: Current_line[Input_idx]++; \
302: (Lexi_pos[Input_idx])++; \
303: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1]; \
304: /* need to take care of return continuation conditions */ \
305: /* so, we return to one-char-at-a-time approach */ \
306: /* for(ii=0;ii<leng;ii++) { */ \
307: /* buf[ii] = Lexi_buf[Input_idx][ii]; */ \
308: /* } */ \
309: /* buf[ii] = '\0'; */ \
310: /* printf("YY_INPUT()(Lexi_line=%d,max size=%d)(%c)",Lexi_line,max_size,buf[0]); */ \
311: result = 1; \
312: } \
313: } else { \
314: /* LIDBUG_PR2("<<yy_input() increase Lexi_pos, input index=%d>>\n",Input_idx); */ \
315: (Lexi_pos[Input_idx])++; \
316: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1]; \
317: result = 1; \
318: } \
319: if (Stop_Parser==1) { \
320: result = YY_NULL; \
321: } \
322: }
323: #endif /* USE_DYNAMIC_LEXBUFS */
324: #endif /*NEWYYINPUT*/
325: #endif /*AVOIDYYINPUT*/
326:
327: #else
328:
329: #undef input
330: #undef unput
331:
332: #endif
333:
334: int capa_eof();
335: %}
336:
337: Alpha [a-zA-Z_]
338: KeyChar [A-Z]
339: AlphaNum [a-zA-Z_0-9]
340: Number [0-9]
341: HexNumber [0-9a-fA-F]
342: Space [ \t]
343: Spaces ({Space}*)
344: FileName (\"[^"\n]*\")
345: Qchar ([0-9a-zA-Z \t!?\._,:;'"`~@#$%\^&\+\-\*=|\[\]{}()])
346: Operator ([=\+\-\*/%<>!&|,])
347: Identifier ([a-zA-Z_][a-zA-Z_0-9]*)
348: EndLine ([\r][\n]|[\n])
349:
350: %a 10500
351: %o 15000
352: %k 10000
353: %p 10000
354: %n 1000
355: %x S_COMMENT S_HINT S_HINTEXLAINX S_IMPORT S_EXPLAIN S_ENDX S_UNIT S_IGNORE
356: %x S_SKIP S_VARIABLE S_LET S_DEFINE S_TEXT S_MAP S_FIGURE S_ANSWER
357: %x S_STRING S_ANSCONTINUE S_TRUE_FALSE_STMT S_IF_SKIP S_WHILE_SKIP
358: %x S_NEXT_LINE S_RANDOMORDER S_VERB
359: %array
360:
361:
362:
363: %%
364:
365: <S_IGNORE>{
366: {EndLine} BEGIN S_IGNORE;
367: [^\n]*$ BEGIN S_IGNORE;
368: <<EOF>> {
369: capa_eof();
370: #ifndef AVOIDYYINPUT
371: yyterminate();
372: #endif
373: }
374: }
375:
376: <S_COMMENT>[^\n]*{EndLine} BEGIN S_TEXT;
377:
378: <S_TEXT>{
379: ^{Spaces}"/LET" |
380: ^{Spaces}"/BEG" { LLDBUG_PRL1("[LET]"); Pcount = 0; init_funcstack(); BEGIN S_LET; RETURN(CAPA_LET); }
381: ^{Spaces}"/VERB" {
382: LLDBUG_PRL1("[VERBATIM]");
383: Dynamic_buf = (char *)capa_malloc(sizeof(char),1);
384: Dynamic_buf_max = 1;
385: Dynamic_buf_cur = 0;
386: Dynamic_buf[0] = '\0';
387: BEGIN S_VERB;
388: }
389: ^{Spaces}"/HIN"{Alpha}*{Spaces} { LLDBUG_PRL1("[HIN]"); Current_char_p = String_buf; BEGIN S_HINT; }
390: ^{Spaces}"/EXP"{Alpha}*{Spaces} { LLDBUG_PRL1("[EXP]"); Current_char_p = String_buf; BEGIN S_EXPLAIN; }
391: ^{Spaces}"/IMP"{Alpha}*{Space}+ { LLDBUG_PRL1("[IMP]"); BEGIN S_IMPORT; }
392: ^{Spaces}"/END" { LLDBUG_PRL1("[END]");
393: if ( (LexiProblem_p !=NULL) &&
394: (LexiProblem_p->question != NULL) &&
395: (LexiProblem_p->ans_type == 0)) {
396: EndText_p=strsave(LexiProblem_p->question);
397: free_problems(LexiProblem_p);
398: LexiProblem_p=NULL;
399: } else {
400: EndText_p=NULL;
401: }
402: End_of_input = 1; BEGIN S_IGNORE;RETURN(CAPA_END);
403: }
404: ^{Spaces}"/START"[^\n]* { LLDBUG_PRL1("[START]");
405: if (LexiProblem_p !=NULL &&
406: LexiProblem_p->question != NULL) {
407: StartText_p=strsave(LexiProblem_p->question);
408: } else {
409: StartText_p=NULL;
410: }
411: BEGIN S_TEXT;
412: RETURN(CAPA_START);
413: }
414:
415: ^{Spaces}"/END"{Spaces}[\(]{Spaces} { LLDBUG_PRL1("[END()]"); BEGIN S_ENDX; }
416: ^"/DEF" { Bcount = 0; BEGIN S_DEFINE; RETURN(CAPA_DEF); }
417: ^{Spaces}"/ANS" { LLDBUG_PRL2("[ANS(%s)]",yytext); Pcount = 0; BEGIN S_ANSWER; RETURN(CAPA_ANS); }
418: ^{Spaces}"/SUBJECTIVE" { LLDBUG_PRL1("[SUBJECTIVE ANSWER]"); Pcount = 0; BEGIN S_ANSWER; RETURN(CAPA_SUBJ); }
419: ^{Spaces}"/MAP" { LLDBUG_PRL1("[MAP]"); Pcount = 0; BEGIN S_MAP; RETURN(CAPA_MAP); }
420: ^{Spaces}"/RMAP" { LLDBUG_PRL1("[RMAP]"); Pcount = 0; BEGIN S_MAP; RETURN(CAPA_RMAP); }
421: ^{Spaces}"/RQO"{Spaces}* { LLDBUG_PRL1("[RQO]"); BEGIN S_RANDOMORDER;
422: RETURN(CAPA_RQO);}
423: ^{Spaces}"/ENDWHILE"([^\n])* { long int file_pos;
424: int top_item, input_idx;
425: LLDBUG_PRL2("[ENDWHILE While_idx=<%d>]\n",While_idx);
426:
427: top_item = While_idx - 1;
428: if( top_item < 0 ) { /* strange things must have happened here! */
429:
430: } else {
431: input_idx = WhileStack[top_item].input_idx;
432: file_pos = WhileStack[top_item].pos_idx;
433: Current_line[input_idx] = WhileStack[top_item].line_idx;
434: Lexi_pos[input_idx] = 0;
435: fseek(Input_stream[input_idx],file_pos,SEEK_SET);
436: fgets(Lexi_buf[input_idx],LEX_BUFLEN-1,Input_stream[input_idx]);
437: While_idx--;
438: }
439: BEGIN S_TEXT;
440: }
441: "/WHILE" |
442: ^{Spaces}"/WHILE" { long int file_pos;
443: int leng;
444: LLDBUG_PRL2("[WHILE While_idx=<%d>]\n",While_idx);
445: leng = strlen(Lexi_buf[Input_idx]); /* length of current line */
446: /* <-- because we use fgets() to read input,
447: thus ftell() will give the starting position of next line */
448: WhileStack[While_idx].input_idx = Input_idx;
449: file_pos = ftell(Input_stream[Input_idx]);
450: file_pos -= leng; /* calibrate the current line length */
451: WhileStack[While_idx].pos_idx = file_pos; /* begin of current line */
452: WhileStack[While_idx].line_idx = Current_line[Input_idx];
453: While_idx++; /* advance the stack pointer */
454:
455: BEGIN S_TRUE_FALSE_STMT; RETURN(CAPA_WHILE);
456:
457: }
458: ^{Spaces}"/IF" { IFcount++; IFcurrent[IFcount] = RUN_IF_PORTION;
459: LLDBUG_PRL2("[IF <IFcount=%d>]",IFcount); BEGIN S_TRUE_FALSE_STMT; RETURN(CAPA_IF); }
460: ^{Spaces}"/ELSE"([^\n])* { LLDBUG_PRL2("[ELSE <IFcount=%d>]\n",IFcount);
461: IFcurrent[IFcount] = RUN_ELSE_PORTION;
462: if( IFstatus[IFcount] == IF_TRUE ) {
463: LLDBUG_PRL1("[ELSE begin Skip]\n");
464: BEGIN S_IF_SKIP;
465: }
466: }
467: ^{Spaces}"/ENDIF"([^\n])* { IFcount--; LLDBUG_PRL2("[ENDIF <IFcount=%d>]\n",IFcount);
468: }
469: "/AND" { LLDBUG_PRL1("[AND]"); BEGIN S_ANSCONTINUE; RETURN(ANS_AND); }
470: "/DIS" { /* since S_VARIABLE treat {Space} as null, so here we do not match ( */
471: /* so that between /DIS and ( can have as many {Space} as we want */
472: LLDBUG_PR1("[DIS<]");
473: init_funcstack();
474: Pcount = 0; BEGIN S_VARIABLE;
475: RETURN(CAPA_VAR);
476: }
477: "/OR" { LLDBUG_PRL1("[OR]"); BEGIN S_ANSCONTINUE; RETURN(ANS_OR); }
478: {EndLine} { LLDBUG_PR1("[EoL within S_TEXT]\n"); /* end of the whole text line */
479: RETURN(EoL); }
480: [\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue](%s)",yytext); /* continuation on next line */ }
481: ^{Spaces}"//"[^\n]*$ { LLDBUG_PRL2("[COMMENT<%s>]\n",yytext); BEGIN S_COMMENT; }
482: [^/\n\\]+$ |
483: [/] |
484: [\\] { yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
485: yylval->s_str = strsave(yytext);
486: LLDBUG_PR2("[TEXT_LINE<%s>]",yytext);
487: RETURN(TEXT_LINE);
488: }
489: ([^/\n])+[/] |
490: ([^/\n])+[\\] { /* matches anything until a '/' or a '\' */
491: LLDBUG_PR2("[TEXT_LINE( )<%s>]",yytext);
492:
493: yyless(yyleng-1); /* push back the last char */
494: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
495: yylval->s_str = strsave(yytext);
496:
497: BEGIN S_TEXT;
498: RETURN(TEXT_LINE);
499: }
500: <<EOF>> {
501: #ifdef AVOIDYYINPUT
502: char warn_msg[ONE_K];
503:
504: if ( (--include_stack_ptr < 0) || Stop_Parser) {
505: if (Stop_Parser) {
506: if ( LexiProblem_p!=NULL &&
507: LexiProblem_p->question != NULL)
508: EndText_p=strsave(LexiProblem_p->question);
509: while (include_stack_ptr >= 0) {
510: yy_delete_buffer( YY_CURRENT_BUFFER );
511: yy_switch_to_buffer(
512: include_stack[include_stack_ptr]);
513: --include_stack_ptr;
514: }
515: } else {
516: sprintf(warn_msg,
517: "at End-of-File, a /END is needed.\n");
518: capa_msg(MESSAGE_ERROR,warn_msg);
519: }
520: free_problems(LexiProblem_p);
521: LexiProblem_p=NULL;
522: yyterminate();
523: } else {
524: yy_delete_buffer( YY_CURRENT_BUFFER );
525: yy_switch_to_buffer(include_stack[include_stack_ptr]);
526: }
527: #else
528: char warn_msg[ONE_K];
529: if (!Stop_Parser) {
530: sprintf(warn_msg,"at End-of-File, a /END is needed.\n");
531: capa_msg(MESSAGE_ERROR,warn_msg);
532: } else {
533: if (LexiProblem_p != NULL &&
534: LexiProblem_p->question != NULL)
535: EndText_p=strsave(LexiProblem_p->question);
536: }
537: capa_eof();
538: yyterminate();
539: #endif
540: }
541: }
542:
543:
544: <S_ENDX>{
545: {Alpha}{AlphaNum}* { /* DONE: add codes to handle /END() */
546: char *question_end=NULL;
547: End_of_input = 1;
548: if (EndText_p!=NULL) capa_mfree((char*)EndText_p);
549: if ((LexiProblem_p!=NULL) &&
550: (LexiProblem_p->question != NULL) &&
551: (LexiProblem_p->ans_type == 0)) {
552: question_end=strsave(LexiProblem_p->question);
553: }
554: if( yyleng > 0 ) {
555:
556: LLDBUG_PRL2("[END()<%s>]\n",yytext);
557: yylval = find_identifier(yytext);
558:
559: switch(yylval->s_type) {
560: case IDENTIFIER:
561: case I_VAR: case I_CONSTANT:
562: case R_VAR: case R_CONSTANT:
563: break;
564: case S_VAR: case S_CONSTANT:
565: EndText_p = strsave(yylval->s_str);
566: if (question_end) {
567: int leng; char *new_end;
568: leng = strlen(EndText_p) +
569: strlen(question_end) + 1;
570: new_end = capa_malloc(sizeof(char), leng);
571: strcat(new_end, question_end);
572: strcat(new_end, EndText_p);
573: capa_mfree(EndText_p);
574: capa_mfree(question_end);
575: EndText_p=new_end;
576: }
577: break;
578: default: break;
579: }
580: }
581: BEGIN S_IGNORE; RETURN(CAPA_END);
582: }
583: {Space}* { /* ignore spaces */ }
584: [\)] { /* a right paren */
585: if ( (LexiProblem_p != NULL) &&
586: (LexiProblem_p->question != NULL) &&
587: (LexiProblem_p->ans_type == 0)) {
588: EndText_p=strsave(LexiProblem_p->question);
589: } else {
590: EndText_p=NULL;
591: }
592: BEGIN S_IGNORE;
593: RETURN(CAPA_END);
594: }
595: }
596:
597: <S_HINT,S_EXPLAIN>{
598: [/][Dd][Ii][Ss]{Space}*[\(]{Space}* { yy_push_state(S_HINTEXLAINX); }
599: [^/\n]+[/\\] { char *aptr = yytext;
600: int ii;
601:
602: yyless(yyleng-1);
603: for(ii=0;ii<yyleng;ii++) {
604: *Current_char_p++ = *aptr++;
605: }
606:
607: }
608: [/] { *Current_char_p++ = '/'; }
609: [\\] { *Current_char_p++ = '\\'; }
610: [\\]{Space}*[\n] { LLDBUG_PR1("[\\CR hint explain continue]"); /* Hint and explain continuation */ }
611: [^/\n\\]+$ { char *aptr = yytext;
612: int ii;
613: for(ii=0;ii<yyleng;ii++) {
614: *Current_char_p++ = *aptr++;
615: }
616: }
617: }
618: <S_HINT>{
619: {EndLine} { LLDBUG_PR1("[CR hint]");
620: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
621: *Current_char_p++ = '\n'; *Current_char_p = '\0';
622: yylval->s_str = strsave(String_buf);
623: BEGIN S_TEXT; RETURN(HINT_LINE);
624: }
625: }
626: <S_EXPLAIN>{
627: {EndLine} { LLDBUG_PR1("[CR explain]");
628: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
629: *Current_char_p++ = '\n'; *Current_char_p = '\0';
630: yylval->s_str = strsave(String_buf);
631: BEGIN S_TEXT; RETURN(EXPLAIN_LINE);
632: }
633: }
634:
635: <S_HINTEXLAINX>{
636: {Alpha}{AlphaNum}* { char *aptr;
637: char tmp_str[QUARTER_K],warn_msg[ONE_K];
638: int ii, len;
639: Symbol *tmp_p;
640:
641: tmp_p = find_identifier(yytext);
642: switch(tmp_p->s_type) {
643: case IDENTIFIER:
644: sprintf(warn_msg,"var %s not defined.\n", yytext);
645: capa_msg(MESSAGE_ERROR,warn_msg);
646: break;
647: case I_VAR:
648: case I_CONSTANT:
649: sprintf(tmp_str,"%ld",tmp_p->s_int);
650: len = strlen(tmp_str);
651: for(ii=0;ii< len;ii++) {
652: *Current_char_p++ = tmp_str[ii];
653: }
654: break;
655: case R_VAR:
656: case R_CONSTANT:
657: sprintf(tmp_str,"%g",tmp_p->s_real);
658: len = strlen(tmp_str);
659: for(ii=0;ii< len;ii++) {
660: *Current_char_p++ = tmp_str[ii];
661: }
662: break;
663: case S_VAR:
664: case S_CONSTANT:
665: len = strlen(tmp_p->s_str);
666: aptr = tmp_p->s_str;
667: for(ii=0;ii< len;ii++) {
668: *Current_char_p++ = *aptr++;
669: }
670: break;
671: }
672: }
673: {Space}+ { }
674: [)] { yy_pop_state(); }
675: }
676:
677: <S_IMPORT>{
678: {FileName}{Space}* { parse_filename(yytext); BEGIN S_SKIP; }
679: {Identifier}{Space}* { parse_import_id(yytext); BEGIN S_SKIP; }
680: }
681:
682: <S_ANSWER>{
683: [Pp][Ll][Uu][Ss] { LLDBUG_PR1("[PLUS]"); RETURN(ANS_PLUS); }
684: [Mm][Ii][Nn][Uu][Ss] { LLDBUG_PR1("[MINUS]"); RETURN(ANS_MINUS); }
685: [Cc][Ss] { LLDBUG_PR1("[CS]"); RETURN(ANS_CS); }
686: [Cc][Ii] { LLDBUG_PR1("[CI]"); RETURN(ANS_CI); }
687: [Mm][Cc] { LLDBUG_PR1("[MC]"); RETURN(ANS_MC); }
688: [Oo][Nn] |
689: [Yy][Ee][Ss] { LLDBUG_PR1("[ON]"); RETURN(ANS_ON); }
690: [Oo][Ff][Ff] |
691: [Nn][Oo] { LLDBUG_PR1("[OFF]"); RETURN(ANS_OFF); }
692: [Ff][Mm][Ll] { LLDBUG_PR1("[FORMULA]"); RETURN(ANS_FORMULA); }
693: [Ff][Mm][Tt] { LLDBUG_PR1("[FMT]"); RETURN(ANS_FMT); }
694: [Uu][Nn][Ff][Mm][Tt] { LLDBUG_PR1("[UNFMT]"); RETURN(ANS_UNFMT); }
695: [,:%=@#-] { LLDBUG_PR2("[symbol(%s)]",yytext); return(yytext[0]); }
696: "<" { LLDBUG_PR2("[symbol(%s)]",yytext); return(yytext[0]); }
697: ">" { LLDBUG_PR2("[symbol(%s)]",yytext); return(yytext[0]); }
698: [Ss][Ii][Gg] { LLDBUG_PR2("[SIG(%s)]",yytext); RETURN(ANS_SIG); }
699: [Tt][Oo][Ll] { LLDBUG_PR2("[tol(%s)]",yytext); RETURN(ANS_TOLERANCE); }
700: [Ss][Tt][Rr] { LLDBUG_PR1("[STR]"); RETURN(ANS_COMPARE); }
701: [Ww][Gg][Tt] { LLDBUG_PR1("[WGT]"); RETURN(ANS_WEIGHT); }
702: [Pp][Cc][Rr] |
703: [Hh][Gg][Rr] { RETURN(ANS_PCREDIT); }
704: [Pp][Aa][Tt][Hh] { RETURN(ANS_PATH); }
705: [Cc][Aa][Ll][Cc] { RETURN(ANS_CALC); }
706: [Tt][Rr][Yy] |
707: [Tt][Rr][Ii][Ee][Ss] { LLDBUG_PR1("[TRY]"); RETURN(ANS_TRY); }
708: [Uu][Nn][Ii][Tt] |
709: [Uu][Nn][Ii][Tt][Ss] { LLDBUG_PR1("[UNIT]"); RETURN(ANS_UNIT); }
710: [Bb][Rr] { LLDBUG_PR1("[SHOW_BR]"); RETURN(ANS_SHOW_BR); }
711: [Aa][Nn][Ss][Bb][Oo][Xx] { LLDBUG_PR1("[SHOW_ANS_BOX]"); RETURN(ANS_BOX_SHOW); }
712: [Hh][Ii][Nn][Tt] { LLDBUG_PR1("[HINT]"); RETURN(ANS_HINT); }
713: [Ee][Xx][Pp][Ll][Aa][Ii][Nn] { LLDBUG_PR1("[EXPLAIN]"); RETURN(ANS_EXPLAIN); }
714: [Ee][Xx][Tt][Ee][Rr][Nn][Aa][Ll] { LLDBUG_PR1("[EXTERNAL]"); RETURN(ANS_EXTERNAL); }
715: [Ee][Vv][Aa][Ll] |
716: [Ee][Vv][Aa][Ll][Uu][Aa][Tt][Ee] { LLDBUG_PR1("[EVAL]"); RETURN(ANS_EVAL); }
717: [\)] { LLDBUG_PR1("[)]"); Pcount--;
718: if(Pcount==0) {
719: BEGIN S_ANSCONTINUE;
720: }
721: return(yytext[0]);
722: }
723: }
724:
725: <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_ANSWER,S_MAP>{
726: {Alpha}{AlphaNum}* { LLDBUG_PR2("[ID<%s>]",yytext);LLDBUG_PR2("[SYMB CNT=<%d>]", Symb_count);
727: yylval = find_identifier(yytext); RETURN(IDENTIFIER);
728: }
729:
730: {Alpha}{AlphaNum}*{Space}*[(] { char aline[MAX_FUNC_NAME];
731: int i;
732: for(i=0;i < (yyleng-1); i++) {
733: if( yytext[i] == ' ' || yytext[i] == '\t' ||
734: yytext[i] == 0 || yytext[i] == '(' ) break;
735: aline[i] = yytext[i];
736: }
737: aline[i] = 0;
738: LLDBUG_PR3("[FUNCT<%s:%d>]",aline,Func_idx);
739: (FuncStack[Func_idx]).s_type = FUNCTION_ID;
740: (FuncStack[Func_idx]).s_name = strsave(aline); /* free it in parser() */
741: Func_idx++;
742: yyless(yyleng-1); /* <-- push back '(' char */
743: RETURN(FUNCTION_ID);
744: }
745: {Alpha}{AlphaNum}*{Space}*[\[] { char aline[MAX_FUNC_NAME];
746: int i;
747: for(i=0;i < (yyleng-1); i++) {
748: if( yytext[i] == ' ' || yytext[i] == '\t' ||
749: yytext[i] == 0 || yytext[i] == '[' ) break;
750: aline[i] = yytext[i];
751: }
752: aline[i] = 0;
753: LLDBUG_PR2("[ARRAY<%s>]",aline);
754:
755: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */
756: yylval->s_name = strsave(aline); /* free it in parser() */
757: yylval->s_type = ARRAY_ID;
758:
759: yyless(yyleng-1); /* <-- push back char '[' */
760: RETURN(ARRAY_ID);
761: }
762: {Number}*"\."{Number}*[Ee]"+"{Number}+ |
763: {Number}*"\."{Number}*[Ee]{Number}+ |
764: {Number}*"\."{Number}*[Ee]"-"{Number}+ |
765: {Number}+[Ee]"+"{Number}+ |
766: {Number}+[Ee]{Number}+ |
767: {Number}+[Ee]"-"{Number}+ |
768: {Number}+"\."{Number}* |
769: "\."{Number}+ { yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */
770: yylval->s_real = strtod(yytext, (char **) 0);
771: yylval->s_type = R_CONSTANT;
772: LLDBUG_PR2("[REAL<%s>]",yytext);
773: RETURN(R_CONSTANT);
774: }
775:
776: {Number}+ { yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */
777: yylval->s_int = strtol(yytext, (char **) 0, 0);
778: yylval->s_type= I_CONSTANT;
779: LLDBUG_PR2("[INT<%s>]",yytext);
780: RETURN(I_CONSTANT);
781: }
782: [\(] { LLDBUG_PR1("[dis let ans map (]"); Pcount++; return(yytext[0]); }
783: [\[] { LLDBUG_PR1("[dis let ans map '[']"); return(yytext[0]); }
784: [\]] { LLDBUG_PR1("[dis let ans map ']']"); return(yytext[0]); }
785: {Space}+ { /* LLDBUG_PR1("[SP ignored]"); Ignore Spaces */ }
786: [\"] { LLDBUG_PR1("[TF,V,LET,ANS,MAP str\" ]");
787: Current_char_p = String_buf;
788: yy_push_state(S_STRING);
789: }
790: }
791:
792: <S_VARIABLE,S_ANSWER>[:]{Number}+[EeFf] { char num[ONE_TWO_EIGHT], fmt[SIXTEEN];
793: int i;
794: LLDBUG_PR2("[FORMAT<%s>]",yytext);
795: for(i=0;i<yyleng-2;i++) {
796: num[i] = yytext[i+1];
797: }
798: num[yyleng-2] = 0; /* terminate the numerical string */
799: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
800: i = strtol(num, (char **) 0, 0);
801: yylval->s_type=FORMAT;
802: switch( yytext[yyleng-1] ) {
803: case 'e': sprintf(fmt,"%%.%de", i);
804: yylval->s_distype = E_FORMAT; break;
805: case 'E': sprintf(fmt,"%%.%dE", i);
806: yylval->s_distype = E_FORMAT; break;
807: case 'f':
808: case 'F': sprintf(fmt,"%%.%df", i);
809: yylval->s_distype = F_FORMAT; break;
810: }
811: yylval->s_str = strsave(fmt);
812: RETURN(FORMAT);
813: }
814:
815: <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP>{
816: "==" { LLDBUG_PR1("[==]"); RETURN(EQ_op); }
817: "!=" { LLDBUG_PR1("[!=]"); RETURN(NE_op); }
818: ">" { LLDBUG_PR1("[>]"); RETURN(GT_op); }
819: ">=" { LLDBUG_PR1("[>=]"); RETURN(GE_op); }
820: "<" { LLDBUG_PR1("[<]"); RETURN(LT_op); }
821: "<=" { LLDBUG_PR1("[<=]"); RETURN(LE_op); }
822: "&&" { LLDBUG_PR1("[&&]"); RETURN(AND_op); }
823: "||" { LLDBUG_PR1("[||]"); RETURN(OR_op); }
824: "//" { if(Pcount==0) BEGIN S_SKIP; }
825: {Operator} { LLDBUG_PR2("[Op(%c) in VAR,TF_STMT,LET]",yytext[0]); return(yytext[0]); }
826: }
827:
828:
829: <S_RANDOMORDER>{
830: {Number}+ {
831: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
832: yylval->s_int = strtol(yytext, (char **) 0, 0);
833: yylval->s_type= I_CONSTANT;
834: LLDBUG_PR2("[INT<%s>]",yytext);
835: RETURN(I_CONSTANT);
836: }
837: [+~,\-!] { LLDBUG_PR2("[randqo(%s)]",yytext); return(yytext[0]); }
838: {EndLine} { LLDBUG_PR1("[EoLRQO]"); BEGIN S_TEXT; RETURN(EoL);}
839: }
840:
841: <S_VARIABLE>{
842: [\)] { LLDBUG_PR1("[)]"); Pcount--; if(Pcount == 0) BEGIN S_TEXT; return(yytext[0]); }
843: [\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue in S_VARIABLE (DIS?)](%s)",yytext); /* continuation on next line */ }
844: {EndLine} { LLDBUG_PR1("[EoL within /dis()]\n"); RETURN(EoL); }
845: . { char warn_msg[WARN_MSG_LENGTH];
846: sprintf(warn_msg,"When use a VARIABLE, an unexpected char [%c] is encountered.\n",yytext[0]);
847: capa_msg(MESSAGE_ERROR,warn_msg);
848: }
849: }
850:
851: <S_TRUE_FALSE_STMT>{
852: [\)] { LLDBUG_PR1("[) in TRUE_FALSE]"); Pcount--; if(Pcount == 0) BEGIN S_NEXT_LINE; return(yytext[0]); }
853: [\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue in S_TRUE_FALSE_STMT](%s)",yytext); /* continuation on next line */ }
854: {EndLine} { LLDBUG_PR1("[EoL within /IF()]\n"); RETURN(EoL); }
855: . { char warn_msg[WARN_MSG_LENGTH];
856: sprintf(warn_msg,"In /IF(), an unexpected char [%c] is encountered.\n",yytext[0]);
857: capa_msg(MESSAGE_ERROR,warn_msg);
858: }
859: }
860:
861: <S_STRING>{
862: [\\][\\] { char *aptr = yytext;
863: while( *aptr ) *Current_char_p++ = *aptr++;
864: }
865: [\\][\"] { *Current_char_p++ = '"'; }
866: [\\]{Space}*[\n] { LLDBUG_PR2("[\\CR continue in S_STRING](%s)",yytext); /* continuation on next line */ }
867: [\"] { /* end of a string constant -- */
868: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
869: *Current_char_p = '\0';
870: yylval->s_str = strsave(String_buf); /* **** */
871: yylval->s_type = S_CONSTANT;
872: /* printf("STRING:%s\n", String_buf); */
873: LLDBUG_PR2("[%s\"END str]",String_buf);
874: yy_pop_state();
875: RETURN(S_CONSTANT); }
876: {EndLine} { /* check for termination of string constant */
877: char warn_msg[WARN_MSG_LENGTH];
878:
879: *Current_char_p = '\0';
880: sprintf(warn_msg,"STRING not terminated properly, an EoL encountered in the middle.\n%s\n",String_buf);
881: capa_msg(MESSAGE_ERROR,warn_msg);
882: yy_pop_state();
883: }
884: . { char *aptr = yytext;
885: while( *aptr ) *Current_char_p++ = *aptr++;
886: }
887: }
888:
889: <S_LET>[\)] { LLDBUG_PR1("[) in LET]"); Pcount--; return(yytext[0]); }
890:
891: <S_SKIP>{
892: [^\n]+$ { }
893: {EndLine} { BEGIN S_TEXT; RETURN(EoL); }
894: }
895:
896: <S_LET,S_ANSWER,S_MAP>{
897: [\\]{Space}*{EndLine} { LLDBUG_PR1("[\\EoL let ans map]"); /* continuation */ }
898: {EndLine} { LLDBUG_PR1("[EoL END let ans map]\n"); if(Pcount == 0) BEGIN S_TEXT; RETURN(EoL); }
899: }
900:
901: <S_MAP>{
902: [;,] { LLDBUG_PR2("[%c]",yytext[0]); return(yytext[0]); }
903: [\)] { LLDBUG_PR1("[) in MAP]"); Pcount--;
904: if(Pcount==0) {
905: BEGIN S_SKIP;
906: }
907: return(yytext[0]);
908: }
909: }
910:
911: <S_ANSCONTINUE>{
912: {Space}+ { /* ignore white spaces */ }
913: [\\]{Space}*{EndLine} { /* continuation */ }
914: {EndLine} { /* end of answer and/or other answers */ LLDBUG_PR1("[complete an answer<EoL>]");
915: BEGIN S_TEXT; }
916: "/AND" { LLDBUG_PR1("[AND]"); RETURN(ANS_AND); }
917: "/OR" { LLDBUG_PR1("[OR]"); RETURN(ANS_OR); }
918: }
919:
920: <S_IF_SKIP>{
921: ^{Spaces}"/IF"[^\n]*{EndLine} { IFcount++; LLDBUG_PRL2("[Skip IF <IFcount=%d>]\n",IFcount);
922: IFstatus[IFcount] = IF_DONT_CARE;
923: }
924: ^{Spaces}"/ELSE"[^\n]*{EndLine} { LLDBUG_PRL2("[Skip ELSE <IFcount=%d>]",IFcount);
925: IFcurrent[IFcount]=RUN_ELSE_PORTION;
926: if( IFstatus[IFcount] == IF_FALSE ) {
927: LLDBUG_PRL1("[ELSE begin TEXT CR]\n");
928: BEGIN S_TEXT;
929: }
930: if( IFstatus[IFcount] == IF_TRUE ) {
931: LLDBUG_PRL1("[ELSE THIS SHOULD NEVER HAPPEN.]\n");
932: }
933: }
934: ^{Spaces}"/ENDIF"[^\n]*{EndLine} { IFcount--; LLDBUG_PRL2("[Skip ENDIF <IFcount=%d>]\n",IFcount);
935: if( IFcount == 0 ) {
936: LLDBUG_PRL1("[ENDIF begin TEXT CR]\n");
937: BEGIN S_TEXT;
938: }
939: if( (IFcurrent[IFcount] == RUN_IF_PORTION )&&(IFstatus[IFcount] == IF_TRUE)) {
940: LLDBUG_PRL1("[ENDIF begin TEXT CR]\n");
941: BEGIN S_TEXT;
942: }
943: if( (IFcurrent[IFcount] == RUN_ELSE_PORTION )&&(IFstatus[IFcount] == IF_FALSE)) {
944: LLDBUG_PRL1("[ENDIF begin TEXT CR]\n");
945: BEGIN S_TEXT;
946: }
947: }
948: {EndLine} { LLDBUG_PRL1("[SkipIF a CR]\n"); }
949: [^\n]*$ { LLDBUG_PRL2("[SkipIF anything <IFcount=%d>]",IFcount); }
950: }
951: <S_NEXT_LINE>{
952: ([.]*){EndLine} { /* this ignores everything until it hits an EoL */ BEGIN S_TEXT; }
953: }
954:
955: <S_WHILE_SKIP>{
956: ^{Spaces}"/WHILE"[^\n]*{EndLine} { Wcount++;
957: LLDBUG_PRL2("[SkipWHILE /WHILE <Wcount=%d>]\n",Wcount);
958: }
959: ^{Spaces}"/ENDWHILE"[^\n]*{EndLine} {
960: if(Wcount==0) {
961: LLDBUG_PRL2("[SkipWHILE->/ENDWHILE <Wcount=%d>]\n",Wcount);
962: BEGIN S_TEXT;
963: } else {
964: Wcount--;
965: LLDBUG_PRL2("[SkipWHILE /ENDWHILE <Wcount=%d>]\n",Wcount);
966: }
967: }
968: {EndLine} { LLDBUG_PRL1("[SkipWHILE a CR]\n"); }
969: [^\n]*$ { LLDBUG_PRL2("[SkipWHILE anything <Wcount=%d>]",Wcount); }
970: }
971:
972: <S_VERB>{
973: ^{Spaces}"/ENDVERB" { LLDBUG_PRL1("[END VERB]\n");
974: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
975: yylval->s_str = strsave(Dynamic_buf); /* **** */
976: yylval->s_type = S_CONSTANT;
977: capa_mfree(Dynamic_buf);
978: Dynamic_buf_cur=-1;
979: Dynamic_buf_max=0;
980: BEGIN S_TEXT; RETURN(VERBATIM);
981: }
982: .*|{EndLine} { append_dynamic_buf(yytext); }
983: }
984:
985: %%
986:
987: /* ========================================================================================== */
988: extern void
989: begin_if_skip() { BEGIN S_IF_SKIP; }
990:
991: extern void
992: begin_while_skip() { Wcount=0; While_idx--; /* while is FALSE, pop it out from stack */ BEGIN S_WHILE_SKIP; }
993:
994: extern void
995: begin_next_line() { BEGIN S_NEXT_LINE; }
996:
997: extern void
998: begin_var() { BEGIN S_VARIABLE; }
999:
1000: extern void
1001: begin_let() { BEGIN S_LET; }
1002:
1003: extern void
1004: begin_def() { BEGIN S_DEFINE; }
1005:
1006: extern void
1007: begin_ans() { BEGIN S_ANSWER; }
1008:
1009: extern void
1010: begin_map() { BEGIN S_MAP; }
1011:
1012: extern void
1013: begin_ignore() { BEGIN S_IGNORE; }
1014:
1015: extern void
1016: begin_text() { BEGIN S_TEXT; }
1017:
1018: extern void
1019: begin_question() { LLDBUG_PR1("[<S_TEXT>]");
1020: IFcount = 0; While_idx=0; /* initialize some stacks */
1021: End_of_input = 0; YY_FLUSH_BUFFER; BEGIN S_TEXT; }
1022:
1023: extern void
1024: end_problemset() { End_of_input = 0; YY_FLUSH_BUFFER; BEGIN S_TEXT; }
1025:
1026:
1027: /* ========================================================================================== */
1028:
1029: #define NUM_KEY 2
1030: int
1031: match_keyword(key) char *key;
1032: {
1033: char *keyword[NUM_KEY] = {"/DIS", "/DIR" };
1034: int i;
1035:
1036: for(i=0;i < NUM_KEY; i++) {
1037: if( !strncmp(keyword[i], key, 4) ) {
1038: return (1);
1039: }
1040: }
1041: return (0);
1042: }
1043:
1044: int
1045: match_functionid(key) char *key;
1046: {
1047: char *keyword[NUM_KEY] = {"/DIS", "/DIR" };
1048: int i;
1049:
1050: for(i=0;i < NUM_KEY; i++) {
1051: if( !strncmp(keyword[i], key, 4) ) {
1052: return (1);
1053: }
1054: }
1055: return (0);
1056: }
1057: /* -------------------------------------------------------------------------- */
1058: /* -------------------------------------------------------------------------- */
1059:
1060: void init_funcstack()
1061: {
1062: int ii;
1063: for(ii=0;ii<Func_idx;ii++) {
1064: capa_mfree(FuncStack[ii].s_name);
1065: }
1066: Func_idx = 0;
1067: }
1068:
1069:
1070: /* -------------------------------------------------------------------------- */
1071: /* GET THE NEXT CHARACTER OF THE SOURCE FILE */
1072: /* -------------------------------------------------------------------------- */
1073:
1074: #ifdef FLEX
1075: int capaL_input()
1076: #else
1077: int /* RETURNS: next character */
1078: input() /* ARGUMENTS: (none) */
1079: #endif
1080:
1081: { /* LOCAL VARIABLES: */
1082: static int startup=1; /* First call flag */
1083:
1084: LLDBUG_PRL1("<<capaL_input() is called>>\n");
1085: if (!Lexi_line) { /* was startup */
1086: for(Input_idx=0;Input_idx < MAX_OPENED_FILE;Input_idx++) {
1087: /* for(ii=0;ii<LEX_BUFLEN;ii++) {
1088: Lexi_buf[Input_idx][ii]=0;
1089: }
1090: */
1091: Lexi_buf[Input_idx][0]=0;
1092: Lexi_pos[Input_idx] = 0;
1093: }
1094: Input_idx = 0;
1095: startup=0;
1096: yyin = Input_stream[Input_idx];
1097: }
1098: if (!Lexi_buf[Input_idx][Lexi_pos[Input_idx]]) {
1099: if (fgets(Lexi_buf[Input_idx],LEX_BUFLEN-1,Input_stream[Input_idx])==NULL) {
1100: /* EOF? */
1101: /* no use in flex
1102: printf("capaL_input()EOF %s\n",Opened_filename[Input_idx+1]); fflush(stdout); */
1103: return (0);
1104: }
1105: Lexi_pos[Input_idx] = 0;
1106: Lexi_line++;
1107: printf("input()(%d)\n",Lexi_line);
1108: }
1109: (Lexi_pos[Input_idx])++;
1110: return ( Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1] );
1111: }
1112:
1113: /******************************************************************************/
1114: /* PUSH BACK ONE CHARACTER OF THE INPUT */
1115: /******************************************************************************/
1116:
1117: int /* RETURNS: nothing */
1118: capaL_unput(ch) /* ARGUMENTS: */
1119: register int ch; /* Character to push */
1120: {
1121: if (ch) (Lexi_pos[Input_idx])--;
1122:
1123: /* unput() stream cannot be re-defined */
1124: /* unput(ch); inconsistency between YY_INPUT() and internal matched yytext */
1125: return (0);
1126:
1127: }
1128:
1129:
1130: /******************************************************/
1131:
1132: #ifndef DMALLOC
1133:
1134: char *
1135: strsave(char *s)
1136: {
1137: char *p;
1138: p=capa_malloc(strlen(s)+1,1);
1139: strcpy(p,s);
1140: return (p);
1141: }
1142:
1143: #endif
1144:
1145: /* =========================================================================== */
1146:
1147: #ifndef DMALLOC
1148: char *
1149: capa_malloc(unsigned num,unsigned sz)
1150: {
1151: char *p;
1152: p = calloc(num, sz);
1153: bzero(p, num*sz); /* added Jan 21 1998 */
1154: return (p);
1155: }
1156:
1157: #endif
1158:
1159: #ifndef DMALLOC
1160: void
1161: capa_mfree(p) char *p;
1162: {
1163: free(p);
1164: }
1165: #endif
1166:
1167: void
1168: capa_msg(int type, char *p)
1169: { int idx, i, j;
1170: int len;
1171: char warn_msg[WARN_MSG_LENGTH];
1172: char tmp_line[ONE_TWO_EIGHT];
1173: char *tmp_str;
1174:
1175: strcpy(warn_msg,"File: ");
1176: idx=6;
1177: for(i=0;i<=Input_idx;i++) {
1178: len=strlen(Opened_filename[i]);
1179: for(j=0;j<len;j++) {
1180: warn_msg[idx++] = Opened_filename[i][j];
1181: }
1182: if(i < Input_idx) {
1183: warn_msg[idx++]='-';
1184: warn_msg[idx++]='>';
1185: }
1186: warn_msg[idx]=0;
1187: }
1188: switch (type) {
1189: case MESSAGE_ERROR:
1190: sprintf(tmp_line,", Line %d: ERROR:", Current_line[Input_idx]);
1191: len=strlen(tmp_line);
1192: for(j=0;j<len;j++) {
1193: warn_msg[idx++] = tmp_line[j];
1194: }
1195: warn_msg[idx]=0;
1196: append_error(warn_msg); append_error(p);
1197: break;
1198: case MESSAGE_WARN:
1199: default:
1200: sprintf(tmp_line,", Line %d: WARNING:", Current_line[Input_idx]);
1201: len=strlen(tmp_line);
1202: for(j=0;j<len;j++) {
1203: warn_msg[idx++] = tmp_line[j];
1204: }
1205: warn_msg[idx]=0;
1206: j = strlen(warn_msg);
1207: len = strlen(p);
1208: tmp_str = (char *)capa_malloc(len+j+1,1);
1209: for(i=0;i<j;i++) {
1210: tmp_str[i]=warn_msg[i];
1211: }
1212: for(i=j;i<j+len;i++) {
1213: tmp_str[i] = p[i-j];
1214: }
1215: append_warn(type,tmp_str);
1216: capa_mfree(tmp_str);
1217: break;
1218: }
1219: }
1220:
1221: /* ======================================================================== */
1222: void
1223: capa_warn_header(int type)
1224: {
1225: int idx, i, j;
1226: int len;
1227: char warn_msg[WARN_MSG_LENGTH];
1228: char tmp_line[ONE_TWO_EIGHT];
1229:
1230: strcpy(warn_msg,"File: ");
1231: idx=6;
1232: for(i=0;i<=Input_idx;i++) {
1233: len=strlen(Opened_filename[i]);
1234: for(j=0;j<len;j++) {
1235: warn_msg[idx++] = Opened_filename[i][j];
1236: }
1237: if(i < Input_idx) {
1238: warn_msg[idx++]='-';
1239: warn_msg[idx++]='>';
1240: }
1241: warn_msg[idx]=0;
1242: }
1243: switch (type) {
1244: case MESSAGE_ERROR:
1245: sprintf(tmp_line,", Line %d: ERROR:", Current_line[Input_idx]);
1246:
1247: break;
1248: case MESSAGE_WARN:
1249: sprintf(tmp_line,", Line %d: WARNING:", Current_line[Input_idx]);break;
1250: default:
1251: sprintf(tmp_line,", Line %d: ERROR:", Current_line[Input_idx]);break;
1252: }
1253: len=strlen(tmp_line);
1254: for(j=0;j<len;j++) {
1255: warn_msg[idx++] = tmp_line[j];
1256: }
1257: warn_msg[idx]=0;
1258: append_error(warn_msg);
1259: }
1260:
1261: /* --------------------------------------------------------------------------- */
1262: #ifdef AVOIDYYINPUT
1263:
1264: void change_file(char *fname)
1265: {
1266: char warn_msg[WARN_MSG_LENGTH];
1267: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1268: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n",
1269: fname);
1270: capa_msg(MESSAGE_ERROR,warn_msg);
1271: return;
1272: }
1273:
1274: if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
1275: sprintf(warn_msg,"Includes nested too deeply" );
1276: capa_msg(MESSAGE_ERROR,warn_msg);
1277: return;
1278: }
1279:
1280: include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
1281: yyin = fopen( fname, "r" );
1282: yy_switch_to_buffer( yy_create_buffer( yyin, YY_BUF_SIZE ) );
1283: }
1284:
1285: void
1286: parse_filename(char *line)
1287: {
1288: char *start, fname[MAX_BUFFER_SIZE], warn_msg[WARN_MSG_LENGTH];
1289: int ii,len;
1290:
1291: start = index(line, '\"'); /*** hpux complained */
1292: if( start == NULL ) {
1293: sprintf(warn_msg,"/IMP was not given a filename.\n");
1294: capa_msg(MESSAGE_ERROR,warn_msg);
1295: return;
1296: }
1297: start++; len = strlen(start) - 1;
1298: ii = 0;
1299: while( start[ii] != '\"' ) fname[ii++] = start[ii];
1300: fname[ii] = 0;
1301: LLDBUG_PR2("[parse_filename<%s>]\n",fname);
1302:
1303: change_file(fname);
1304: }
1305:
1306: void
1307: parse_import_id(char *line)
1308: {
1309: char fname[QUARTER_K], warn_msg[WARN_MSG_LENGTH];
1310: int ii, dup_open;
1311: Symbol *symb_p;
1312: int no_error = 0;
1313:
1314: ii = 0;
1315: while( line[ii] != '\0' && line[ii] != ' ' && line[ii] != '\n' && line[ii] != '\t' )
1316: fname[ii++] = line[ii];
1317: fname[ii] = 0;
1318:
1319: LLDBUG_PR2("[parse_import_id<%s>]\n",fname);
1320: symb_p = find_identifier(fname);
1321:
1322: switch (symb_p->s_type) {
1323: case IDENTIFIER:
1324: sprintf(warn_msg,"/IMP %s, var is not defined.\n", fname);
1325: capa_msg(MESSAGE_ERROR,warn_msg);
1326: break;
1327: case I_VAR: case I_CONSTANT: case R_VAR: case R_CONSTANT:
1328: sprintf(warn_msg,"var cannot be a number.\n");
1329: capa_msg(MESSAGE_ERROR,warn_msg);
1330: break;
1331: case S_VAR: case S_CONSTANT: sprintf(fname,"%s",symb_p->s_str);
1332: no_error = 1;
1333: break;
1334: }
1335: if( no_error ) change_file(fname);
1336: }
1337:
1338: #else
1339: void
1340: parse_filename(char *line)
1341: {
1342: char *start, fname[QUARTER_K], warn_msg[WARN_MSG_LENGTH];
1343: int ii, len, dup_open;
1344:
1345: /* printf("IMPORT %s\n", line); */
1346:
1347: start = index(line, '\"'); /*** hpux complained */
1348: if( start != NULL ) {
1349: start++; len = strlen(start) - 1;
1350: ii = 0;
1351: while( start[ii] != '\"' ) {
1352: fname[ii] = start[ii]; ii++;
1353: }
1354: fname[ii] = 0;
1355: LLDBUG_PR2("[parse_filename<%s>]\n",fname);
1356: if(Input_idx < (MAX_OPENED_FILE -1)) {
1357: dup_open = 0;
1358: /* -- no need to check duplicated opening a file
1359: for(ii=0;ii<Input_idx;ii++) {
1360: if(strcmp(Opened_filename[ii],fname)==0) {
1361: dup_open =1;
1362: }
1363: }
1364: */
1365: if( !dup_open ) {
1366: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1367: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n",fname);
1368: capa_msg(MESSAGE_ERROR,warn_msg);
1369: } else {
1370: Input_idx++;
1371: Input_stream[Input_idx]=fopen(fname,"r");
1372: sprintf(Opened_filename[Input_idx], "%s",fname);
1373: Current_line[Input_idx] = 0;
1374: }
1375: } else {
1376: /*
1377: sprintf(warn_msg,"/IMP \"%s\", import file has already been imported.\n",fname);
1378: capa_msg(MESSAGE_WARN,warn_msg);
1379: */
1380: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1381: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n",fname);
1382: capa_msg(MESSAGE_ERROR,warn_msg);
1383: } else {
1384: Input_idx++;
1385: Input_stream[Input_idx]=fopen(fname,"r");
1386: sprintf(Opened_filename[Input_idx], "%s",fname);
1387: Current_line[Input_idx] = 0;
1388: }
1389: }
1390: } else {
1391: sprintf(warn_msg,"/IMP more the %d levels deep ignoring further imports.\n",MAX_OPENED_FILE-1);
1392: capa_msg(MESSAGE_WARN,warn_msg);
1393: }
1394: } else {
1395: sprintf(warn_msg,"%s, is not a valid file name.\n",line);
1396: capa_msg(MESSAGE_ERROR,warn_msg);
1397: }
1398:
1399: }
1400:
1401: void
1402: parse_import_id(char *line)
1403: {
1404: char fname[QUARTER_K], warn_msg[WARN_MSG_LENGTH];
1405: int ii, dup_open;
1406: Symbol *symb_p;
1407: int no_error = 0;
1408:
1409: ii = 0;
1410: while (line[ii] != '\0' && line[ii] != ' ' && line[ii] != '\n' && line[ii] != '\t') {
1411: fname[ii] = line[ii]; ii++;
1412: }
1413: fname[ii] = 0;
1414: LLDBUG_PR2("[parse_import_id<%s>]\n",fname);
1415: symb_p = find_identifier(fname);
1416:
1417: switch (symb_p->s_type) {
1418: case IDENTIFIER:
1419: sprintf(warn_msg,"/IMP %s, var is not defined.\n", fname);
1420: capa_msg(MESSAGE_ERROR,warn_msg);
1421: break;
1422: case I_VAR: case I_CONSTANT: case R_VAR: case R_CONSTANT:
1423: sprintf(warn_msg,"var cannot be a number.\n");
1424: capa_msg(MESSAGE_ERROR,warn_msg);
1425: break;
1426: case S_VAR:
1427: case S_CONSTANT:
1428: sprintf(fname,"%s",symb_p->s_str);
1429: no_error = 1;
1430: break;
1431: }
1432: if( no_error ) {
1433: if(Input_idx < (MAX_OPENED_FILE -1) ) {
1434: dup_open = 0;
1435: /* no need to check duplicated opening a file
1436: for(ii=0;ii<Input_idx;ii++) {
1437: if(strcmp(Opened_filename[ii],fname)==0) dup_open =1;
1438: }
1439: */
1440: if( !dup_open ) {
1441: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1442: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n", fname);
1443: capa_msg(MESSAGE_ERROR,warn_msg);
1444: } else {
1445: Input_idx++;
1446: Input_stream[Input_idx]=fopen(fname,"r");
1447: sprintf(Opened_filename[Input_idx], "%s",fname);
1448: Current_line[Input_idx] = 0;
1449: }
1450: } else {
1451: /* NO warning on duplicated open a file
1452: sprintf(warn_msg,"/IMP \"%s\", file has already been imported.\n", fname);
1453: capa_msg(MESSAGE_WARN,warn_msg);
1454: */
1455: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1456: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n", fname);
1457: capa_msg(MESSAGE_ERROR,warn_msg);
1458: } else {
1459: Input_idx++;
1460: Input_stream[Input_idx]=fopen(fname,"r");
1461: sprintf(Opened_filename[Input_idx], "%s",fname);
1462: Current_line[Input_idx] = 0;
1463: }
1464:
1465: }
1466: } else {
1467: sprintf(warn_msg,"/IMP , too many files has been imported. The maximum is %d files.\n",
1468: MAX_OPENED_FILE-1);
1469: capa_msg(MESSAGE_WARN,warn_msg);
1470: }
1471: }
1472: }
1473: #endif /*AVOIDYYINPUT*/
1474:
1475: void append_dynamic_buf(new_str) char *new_str;
1476: {
1477: int ii,len;
1478:
1479: if(new_str==NULL) return;
1480: len=strlen(new_str);
1481: #define LEX_DBUG 1
1482: #ifdef LEX_DBUG
1483: printf("before: len %d; Dynamic_buf_cur %d; Dynamic_buf_max %d\n",
1484: len,Dynamic_buf_cur,Dynamic_buf_max);
1485: #endif /* LEX_DBUG */
1486: if (Dynamic_buf_cur+len+1>Dynamic_buf_max) {
1487: char *temp_text;
1488: Dynamic_buf_max=(Dynamic_buf_cur+len)*2;
1489: temp_text=(char*)capa_malloc(sizeof(char),Dynamic_buf_max);
1490: strncpy(temp_text,Dynamic_buf,Dynamic_buf_max);
1491: free(Dynamic_buf);
1492: Dynamic_buf=temp_text;
1493: }
1494: for(ii=0;ii<len;ii++) {
1495: Dynamic_buf[Dynamic_buf_cur+ii]=new_str[ii];
1496: }
1497: Dynamic_buf_cur += len;
1498: Dynamic_buf[Dynamic_buf_cur+1]='\0';
1499: #ifdef LEX_DBUG
1500: printf("after: len %d; Dynamic_buf_cur %d; Dynamic_buf_max %d\n",
1501: len,Dynamic_buf_cur,Dynamic_buf_max);
1502: #endif /* LEX_DBUG */
1503: }
1504:
1505: char* parser_status()
1506: {
1507: char *buf,small[SMALL_LINE_BUFFER];
1508: int i,j,totlen=0,len,idx=0;
1509:
1510: for(i=0;i<=Input_idx;i++) totlen+=strlen(Opened_filename[i])+6;
1511: buf=capa_malloc(sizeof(char),totlen);
1512: for(i=0;i<=Input_idx;i++) {
1513: len=strlen(Opened_filename[i]);
1514: for(j=0;j<len;j++) buf[idx++] = Opened_filename[i][j];
1515: buf[idx++] = ':';
1516: sprintf(small,"%d",Current_line[i]);
1517: len=strlen(small);
1518: for(j=0;j<len;j++) buf[idx++] = small[j];
1519: buf[idx++]=' ';
1520: buf[idx]='\0';
1521: }
1522: return buf;
1523: }
1524:
1525: void yyfatalerror(char*msg)
1526: {
1527: char warn_msg[WARN_MSG_LENGTH];
1528: sprintf(warn_msg,"Invalid character[%s]\n",yytext);
1529: capa_msg(MESSAGE_ERROR,warn_msg);
1530: }
1531: void yyerror(char* msg)
1532: {
1533: char warn_msg[WARN_MSG_LENGTH];
1534: sprintf(warn_msg,"%s\n",msg);
1535: capa_msg(MESSAGE_ERROR,warn_msg);
1536: }
1537:
1538: void newyy_input (char *buf,int *result,int max_size)
1539: { int ii, leng, out_of_char;
1540: if (!Lexi_line) { /* was startup */
1541: for(ii=0;ii < MAX_OPENED_FILE;ii++) {
1542: Lexi_buf[ii] = NULL;
1543: Lexi_pos[ii] = 0;
1544: Current_line[ii] = 0;
1545: }
1546: Input_idx = 0;
1547: first_run=0;
1548: yyin = Input_stream[Input_idx]; LIDBUG_PR1("<<yy_input() startup>>\n");
1549: }
1550: out_of_char = 0;
1551: if ( Lexi_buf[Input_idx] == NULL ) {
1552: Lexi_buf[Input_idx] = (char *)capa_malloc(sizeof(char)*LEX_BUFLEN+1,1); out_of_char=1;
1553: } else {
1554: if (!Lexi_buf[Input_idx][Lexi_pos[Input_idx]]) {
1555: /* test if the line buffer is empty or at the end */
1556: out_of_char=1;
1557: }
1558: }
1559: if( out_of_char ) {
1560: if (fgets(Lexi_buf[Input_idx],LEX_BUFLEN-1,Input_stream[Input_idx])==NULL) {
1561: /* read in one line */
1562: LIDBUG_PR2("<<yy_input() fgets() returns NULL, input index=%d>>\n",Input_idx);
1563: if( (Input_idx > 0) && ( Lexi_buf[Input_idx][Lexi_pos[Input_idx]] == '\0') ) {
1564: LIDBUG_PR2("<<yy_input() close an input stream, input index=%d>>\n",Input_idx);
1565: fclose(Input_stream[Input_idx]);
1566: capa_mfree((char *)Lexi_buf[Input_idx]);
1567: Lexi_buf[Input_idx] = NULL;
1568: Input_idx--;
1569: yyin = Input_stream[Input_idx];
1570: /* (Lexi_pos[Input_idx])++; */
1571: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1];
1572: *result = 1;
1573: } else {
1574: *result = YY_NULL; /* End of File */
1575: }
1576: } else { /* successfully read in one line */
1577: leng = strlen(Lexi_buf[Input_idx]);
1578: LIDBUG_PR3("<<yy_input() read into buffer a line(leng=%d), input index=%d>>\n",
1579: leng,Input_idx);
1580: Lexi_pos[Input_idx] = 0;
1581: Lexi_line++;
1582: Current_line[Input_idx]++;
1583: (Lexi_pos[Input_idx])++;
1584: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1];
1585: /* need to take care of return continuation conditions */
1586: /* so, we return to one-char-at-a-time approach */
1587: /* for(ii=0;ii<leng;ii++) { */
1588: /* buf[ii] = Lexi_buf[Input_idx][ii]; */
1589: /* } */
1590: /* buf[ii] = '\0'; */
1591: /* printf("YY_INPUT()(Lexi_line=%d,max size=%d)(%c)",Lexi_line,max_size,buf[0]); */
1592: *result = 1;
1593: }
1594: } else {
1595: /* LIDBUG_PR2("<<yy_input() increase Lexi_pos, input index=%d>>\n",Input_idx); */
1596: (Lexi_pos[Input_idx])++;
1597: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1];
1598: *result = 1;
1599: }
1600: if (Stop_Parser==1) *result = YY_NULL;
1601: }
1602:
1603: int capa_eof()
1604: {
1605: #ifdef AVOIDYYINPUT
1606: if ( --include_stack_ptr < 0 ) yyterminate();
1607: else {
1608: yy_delete_buffer( YY_CURRENT_BUFFER );
1609: yy_switch_to_buffer(include_stack[include_stack_ptr]);
1610: }
1611: #else
1612: if(Input_idx == 0) {
1613: fclose(Input_stream[Input_idx]);
1614: capa_mfree((char *)Lexi_buf[Input_idx]);
1615: free_problems(LexiProblem_p);
1616: LexiProblem_p=NULL;
1617: /* printf("\nCAPA EOF\n"); fflush(stdout); */
1618: }
1619: return (0);
1620: #endif /*AVOIDYYINPUT*/
1621: }
1622: /* ------------ */
1623:
1624:
1625: /* =========================================================== */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>