Annotation of capa/capa51/pProj/capaLexerDef.flex, revision 1.7
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
1.6 albertel 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
1.1 albertel 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]");
1.2 albertel 383: Dynamic_buf = (char *)capa_malloc(sizeof(char),10);
384: Dynamic_buf_max = 10;
1.1 albertel 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); }
1.7 ! albertel 711: [Vv][Ee][Rr][Bb][Aa][Tt][Ii][Mm] { LLDBUG_PR1("[VERBATIM]"); RETURN(ANS_VERBATIM); }
1.1 albertel 712: [Aa][Nn][Ss][Bb][Oo][Xx] { LLDBUG_PR1("[SHOW_ANS_BOX]"); RETURN(ANS_BOX_SHOW); }
713: [Hh][Ii][Nn][Tt] { LLDBUG_PR1("[HINT]"); RETURN(ANS_HINT); }
714: [Ee][Xx][Pp][Ll][Aa][Ii][Nn] { LLDBUG_PR1("[EXPLAIN]"); RETURN(ANS_EXPLAIN); }
715: [Ee][Xx][Tt][Ee][Rr][Nn][Aa][Ll] { LLDBUG_PR1("[EXTERNAL]"); RETURN(ANS_EXTERNAL); }
716: [Ee][Vv][Aa][Ll] |
717: [Ee][Vv][Aa][Ll][Uu][Aa][Tt][Ee] { LLDBUG_PR1("[EVAL]"); RETURN(ANS_EVAL); }
718: [\)] { LLDBUG_PR1("[)]"); Pcount--;
719: if(Pcount==0) {
720: BEGIN S_ANSCONTINUE;
721: }
722: return(yytext[0]);
723: }
724: }
725:
726: <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_ANSWER,S_MAP>{
727: {Alpha}{AlphaNum}* { LLDBUG_PR2("[ID<%s>]",yytext);LLDBUG_PR2("[SYMB CNT=<%d>]", Symb_count);
728: yylval = find_identifier(yytext); RETURN(IDENTIFIER);
729: }
730:
731: {Alpha}{AlphaNum}*{Space}*[(] { char aline[MAX_FUNC_NAME];
732: int i;
733: for(i=0;i < (yyleng-1); i++) {
734: if( yytext[i] == ' ' || yytext[i] == '\t' ||
735: yytext[i] == 0 || yytext[i] == '(' ) break;
736: aline[i] = yytext[i];
737: }
738: aline[i] = 0;
739: LLDBUG_PR3("[FUNCT<%s:%d>]",aline,Func_idx);
740: (FuncStack[Func_idx]).s_type = FUNCTION_ID;
741: (FuncStack[Func_idx]).s_name = strsave(aline); /* free it in parser() */
742: Func_idx++;
743: yyless(yyleng-1); /* <-- push back '(' char */
744: RETURN(FUNCTION_ID);
745: }
746: {Alpha}{AlphaNum}*{Space}*[\[] { char aline[MAX_FUNC_NAME];
747: int i;
748: for(i=0;i < (yyleng-1); i++) {
749: if( yytext[i] == ' ' || yytext[i] == '\t' ||
750: yytext[i] == 0 || yytext[i] == '[' ) break;
751: aline[i] = yytext[i];
752: }
753: aline[i] = 0;
754: LLDBUG_PR2("[ARRAY<%s>]",aline);
755:
756: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */
757: yylval->s_name = strsave(aline); /* free it in parser() */
758: yylval->s_type = ARRAY_ID;
759:
760: yyless(yyleng-1); /* <-- push back char '[' */
761: RETURN(ARRAY_ID);
762: }
763: {Number}*"\."{Number}*[Ee]"+"{Number}+ |
764: {Number}*"\."{Number}*[Ee]{Number}+ |
765: {Number}*"\."{Number}*[Ee]"-"{Number}+ |
766: {Number}+[Ee]"+"{Number}+ |
767: {Number}+[Ee]{Number}+ |
768: {Number}+[Ee]"-"{Number}+ |
769: {Number}+"\."{Number}* |
770: "\."{Number}+ { yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */
771: yylval->s_real = strtod(yytext, (char **) 0);
772: yylval->s_type = R_CONSTANT;
773: LLDBUG_PR2("[REAL<%s>]",yytext);
774: RETURN(R_CONSTANT);
775: }
776:
777: {Number}+ { yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */
778: yylval->s_int = strtol(yytext, (char **) 0, 0);
779: yylval->s_type= I_CONSTANT;
780: LLDBUG_PR2("[INT<%s>]",yytext);
781: RETURN(I_CONSTANT);
782: }
783: [\(] { LLDBUG_PR1("[dis let ans map (]"); Pcount++; return(yytext[0]); }
784: [\[] { LLDBUG_PR1("[dis let ans map '[']"); return(yytext[0]); }
785: [\]] { LLDBUG_PR1("[dis let ans map ']']"); return(yytext[0]); }
786: {Space}+ { /* LLDBUG_PR1("[SP ignored]"); Ignore Spaces */ }
787: [\"] { LLDBUG_PR1("[TF,V,LET,ANS,MAP str\" ]");
788: Current_char_p = String_buf;
789: yy_push_state(S_STRING);
790: }
791: }
792:
1.3 albertel 793: <S_VARIABLE,S_ANSWER>[:]{Number}+[EeFf] { char num[ONE_TWO_EIGHT], fmt[SMALL_LINE_BUFFER];
1.1 albertel 794: int i;
795: LLDBUG_PR2("[FORMAT<%s>]",yytext);
796: for(i=0;i<yyleng-2;i++) {
797: num[i] = yytext[i+1];
798: }
799: num[yyleng-2] = 0; /* terminate the numerical string */
800: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
801: i = strtol(num, (char **) 0, 0);
802: yylval->s_type=FORMAT;
803: switch( yytext[yyleng-1] ) {
804: case 'e': sprintf(fmt,"%%.%de", i);
805: yylval->s_distype = E_FORMAT; break;
806: case 'E': sprintf(fmt,"%%.%dE", i);
807: yylval->s_distype = E_FORMAT; break;
808: case 'f':
809: case 'F': sprintf(fmt,"%%.%df", i);
810: yylval->s_distype = F_FORMAT; break;
811: }
812: yylval->s_str = strsave(fmt);
813: RETURN(FORMAT);
814: }
815:
816: <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP>{
817: "==" { LLDBUG_PR1("[==]"); RETURN(EQ_op); }
818: "!=" { LLDBUG_PR1("[!=]"); RETURN(NE_op); }
819: ">" { LLDBUG_PR1("[>]"); RETURN(GT_op); }
820: ">=" { LLDBUG_PR1("[>=]"); RETURN(GE_op); }
821: "<" { LLDBUG_PR1("[<]"); RETURN(LT_op); }
822: "<=" { LLDBUG_PR1("[<=]"); RETURN(LE_op); }
823: "&&" { LLDBUG_PR1("[&&]"); RETURN(AND_op); }
824: "||" { LLDBUG_PR1("[||]"); RETURN(OR_op); }
825: "//" { if(Pcount==0) BEGIN S_SKIP; }
826: {Operator} { LLDBUG_PR2("[Op(%c) in VAR,TF_STMT,LET]",yytext[0]); return(yytext[0]); }
827: }
828:
829:
830: <S_RANDOMORDER>{
831: {Number}+ {
832: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
833: yylval->s_int = strtol(yytext, (char **) 0, 0);
834: yylval->s_type= I_CONSTANT;
835: LLDBUG_PR2("[INT<%s>]",yytext);
836: RETURN(I_CONSTANT);
837: }
838: [+~,\-!] { LLDBUG_PR2("[randqo(%s)]",yytext); return(yytext[0]); }
839: {EndLine} { LLDBUG_PR1("[EoLRQO]"); BEGIN S_TEXT; RETURN(EoL);}
840: }
841:
842: <S_VARIABLE>{
843: [\)] { LLDBUG_PR1("[)]"); Pcount--; if(Pcount == 0) BEGIN S_TEXT; return(yytext[0]); }
844: [\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue in S_VARIABLE (DIS?)](%s)",yytext); /* continuation on next line */ }
845: {EndLine} { LLDBUG_PR1("[EoL within /dis()]\n"); RETURN(EoL); }
846: . { char warn_msg[WARN_MSG_LENGTH];
847: sprintf(warn_msg,"When use a VARIABLE, an unexpected char [%c] is encountered.\n",yytext[0]);
848: capa_msg(MESSAGE_ERROR,warn_msg);
849: }
850: }
851:
852: <S_TRUE_FALSE_STMT>{
1.6 albertel 853: [\)] { LLDBUG_PRL1("[) in TRUE_FALSE]"); Pcount--; if(Pcount == 0) BEGIN S_NEXT_LINE; return(yytext[0]); }
1.1 albertel 854: [\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue in S_TRUE_FALSE_STMT](%s)",yytext); /* continuation on next line */ }
855: {EndLine} { LLDBUG_PR1("[EoL within /IF()]\n"); RETURN(EoL); }
856: . { char warn_msg[WARN_MSG_LENGTH];
857: sprintf(warn_msg,"In /IF(), an unexpected char [%c] is encountered.\n",yytext[0]);
858: capa_msg(MESSAGE_ERROR,warn_msg);
859: }
860: }
861:
862: <S_STRING>{
863: [\\][\\] { char *aptr = yytext;
864: while( *aptr ) *Current_char_p++ = *aptr++;
865: }
866: [\\][\"] { *Current_char_p++ = '"'; }
867: [\\]{Space}*[\n] { LLDBUG_PR2("[\\CR continue in S_STRING](%s)",yytext); /* continuation on next line */ }
868: [\"] { /* end of a string constant -- */
869: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
870: *Current_char_p = '\0';
871: yylval->s_str = strsave(String_buf); /* **** */
872: yylval->s_type = S_CONSTANT;
873: /* printf("STRING:%s\n", String_buf); */
874: LLDBUG_PR2("[%s\"END str]",String_buf);
875: yy_pop_state();
876: RETURN(S_CONSTANT); }
877: {EndLine} { /* check for termination of string constant */
878: char warn_msg[WARN_MSG_LENGTH];
879:
880: *Current_char_p = '\0';
881: sprintf(warn_msg,"STRING not terminated properly, an EoL encountered in the middle.\n%s\n",String_buf);
882: capa_msg(MESSAGE_ERROR,warn_msg);
883: yy_pop_state();
884: }
885: . { char *aptr = yytext;
886: while( *aptr ) *Current_char_p++ = *aptr++;
887: }
888: }
889:
890: <S_LET>[\)] { LLDBUG_PR1("[) in LET]"); Pcount--; return(yytext[0]); }
891:
892: <S_SKIP>{
893: [^\n]+$ { }
894: {EndLine} { BEGIN S_TEXT; RETURN(EoL); }
895: }
896:
897: <S_LET,S_ANSWER,S_MAP>{
898: [\\]{Space}*{EndLine} { LLDBUG_PR1("[\\EoL let ans map]"); /* continuation */ }
899: {EndLine} { LLDBUG_PR1("[EoL END let ans map]\n"); if(Pcount == 0) BEGIN S_TEXT; RETURN(EoL); }
900: }
901:
902: <S_MAP>{
903: [;,] { LLDBUG_PR2("[%c]",yytext[0]); return(yytext[0]); }
904: [\)] { LLDBUG_PR1("[) in MAP]"); Pcount--;
905: if(Pcount==0) {
906: BEGIN S_SKIP;
907: }
908: return(yytext[0]);
909: }
910: }
911:
912: <S_ANSCONTINUE>{
913: {Space}+ { /* ignore white spaces */ }
914: [\\]{Space}*{EndLine} { /* continuation */ }
915: {EndLine} { /* end of answer and/or other answers */ LLDBUG_PR1("[complete an answer<EoL>]");
916: BEGIN S_TEXT; }
917: "/AND" { LLDBUG_PR1("[AND]"); RETURN(ANS_AND); }
918: "/OR" { LLDBUG_PR1("[OR]"); RETURN(ANS_OR); }
919: }
920:
921: <S_IF_SKIP>{
922: ^{Spaces}"/IF"[^\n]*{EndLine} { IFcount++; LLDBUG_PRL2("[Skip IF <IFcount=%d>]\n",IFcount);
923: IFstatus[IFcount] = IF_DONT_CARE;
924: }
925: ^{Spaces}"/ELSE"[^\n]*{EndLine} { LLDBUG_PRL2("[Skip ELSE <IFcount=%d>]",IFcount);
926: IFcurrent[IFcount]=RUN_ELSE_PORTION;
927: if( IFstatus[IFcount] == IF_FALSE ) {
928: LLDBUG_PRL1("[ELSE begin TEXT CR]\n");
929: BEGIN S_TEXT;
930: }
931: if( IFstatus[IFcount] == IF_TRUE ) {
932: LLDBUG_PRL1("[ELSE THIS SHOULD NEVER HAPPEN.]\n");
933: }
934: }
935: ^{Spaces}"/ENDIF"[^\n]*{EndLine} { IFcount--; LLDBUG_PRL2("[Skip ENDIF <IFcount=%d>]\n",IFcount);
936: if( IFcount == 0 ) {
937: LLDBUG_PRL1("[ENDIF begin TEXT CR]\n");
938: BEGIN S_TEXT;
939: }
940: if( (IFcurrent[IFcount] == RUN_IF_PORTION )&&(IFstatus[IFcount] == IF_TRUE)) {
941: LLDBUG_PRL1("[ENDIF begin TEXT CR]\n");
942: BEGIN S_TEXT;
943: }
944: if( (IFcurrent[IFcount] == RUN_ELSE_PORTION )&&(IFstatus[IFcount] == IF_FALSE)) {
945: LLDBUG_PRL1("[ENDIF begin TEXT CR]\n");
946: BEGIN S_TEXT;
947: }
948: }
949: {EndLine} { LLDBUG_PRL1("[SkipIF a CR]\n"); }
950: [^\n]*$ { LLDBUG_PRL2("[SkipIF anything <IFcount=%d>]",IFcount); }
951: }
952: <S_NEXT_LINE>{
1.6 albertel 953: ([.]*){EndLine} { /* this ignores everything until it hits an EoL */
954: LLDBUG_PRL2("[<S_NEXT_LINE> skip \'%s\' until EoL]\n",yytext);
955: BEGIN S_TEXT;
956: }
1.1 albertel 957: }
958:
959: <S_WHILE_SKIP>{
960: ^{Spaces}"/WHILE"[^\n]*{EndLine} { Wcount++;
961: LLDBUG_PRL2("[SkipWHILE /WHILE <Wcount=%d>]\n",Wcount);
962: }
963: ^{Spaces}"/ENDWHILE"[^\n]*{EndLine} {
964: if(Wcount==0) {
965: LLDBUG_PRL2("[SkipWHILE->/ENDWHILE <Wcount=%d>]\n",Wcount);
966: BEGIN S_TEXT;
967: } else {
968: Wcount--;
969: LLDBUG_PRL2("[SkipWHILE /ENDWHILE <Wcount=%d>]\n",Wcount);
970: }
971: }
972: {EndLine} { LLDBUG_PRL1("[SkipWHILE a CR]\n"); }
973: [^\n]*$ { LLDBUG_PRL2("[SkipWHILE anything <Wcount=%d>]",Wcount); }
974: }
975:
976: <S_VERB>{
977: ^{Spaces}"/ENDVERB" { LLDBUG_PRL1("[END VERB]\n");
978: yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
979: yylval->s_str = strsave(Dynamic_buf); /* **** */
980: yylval->s_type = S_CONSTANT;
981: capa_mfree(Dynamic_buf);
982: Dynamic_buf_cur=-1;
983: Dynamic_buf_max=0;
984: BEGIN S_TEXT; RETURN(VERBATIM);
985: }
986: .*|{EndLine} { append_dynamic_buf(yytext); }
987: }
988:
989: %%
990:
991: /* ========================================================================================== */
992: extern void
993: begin_if_skip() { BEGIN S_IF_SKIP; }
994:
995: extern void
996: begin_while_skip() { Wcount=0; While_idx--; /* while is FALSE, pop it out from stack */ BEGIN S_WHILE_SKIP; }
997:
998: extern void
999: begin_next_line() { BEGIN S_NEXT_LINE; }
1000:
1001: extern void
1002: begin_var() { BEGIN S_VARIABLE; }
1003:
1004: extern void
1005: begin_let() { BEGIN S_LET; }
1006:
1007: extern void
1008: begin_def() { BEGIN S_DEFINE; }
1009:
1010: extern void
1011: begin_ans() { BEGIN S_ANSWER; }
1012:
1013: extern void
1014: begin_map() { BEGIN S_MAP; }
1015:
1016: extern void
1017: begin_ignore() { BEGIN S_IGNORE; }
1018:
1019: extern void
1020: begin_text() { BEGIN S_TEXT; }
1021:
1022: extern void
1023: begin_question() { LLDBUG_PR1("[<S_TEXT>]");
1024: IFcount = 0; While_idx=0; /* initialize some stacks */
1025: End_of_input = 0; YY_FLUSH_BUFFER; BEGIN S_TEXT; }
1026:
1027: extern void
1028: end_problemset() { End_of_input = 0; YY_FLUSH_BUFFER; BEGIN S_TEXT; }
1029:
1030:
1031: /* ========================================================================================== */
1032:
1033: #define NUM_KEY 2
1034: int
1035: match_keyword(key) char *key;
1036: {
1037: char *keyword[NUM_KEY] = {"/DIS", "/DIR" };
1038: int i;
1039:
1040: for(i=0;i < NUM_KEY; i++) {
1041: if( !strncmp(keyword[i], key, 4) ) {
1042: return (1);
1043: }
1044: }
1045: return (0);
1046: }
1047:
1048: int
1049: match_functionid(key) char *key;
1050: {
1051: char *keyword[NUM_KEY] = {"/DIS", "/DIR" };
1052: int i;
1053:
1054: for(i=0;i < NUM_KEY; i++) {
1055: if( !strncmp(keyword[i], key, 4) ) {
1056: return (1);
1057: }
1058: }
1059: return (0);
1060: }
1061: /* -------------------------------------------------------------------------- */
1062: /* -------------------------------------------------------------------------- */
1063:
1064: void init_funcstack()
1065: {
1066: int ii;
1067: for(ii=0;ii<Func_idx;ii++) {
1068: capa_mfree(FuncStack[ii].s_name);
1069: }
1070: Func_idx = 0;
1071: }
1072:
1073:
1074: /* -------------------------------------------------------------------------- */
1075: /* GET THE NEXT CHARACTER OF THE SOURCE FILE */
1076: /* -------------------------------------------------------------------------- */
1077:
1078: #ifdef FLEX
1079: int capaL_input()
1080: #else
1081: int /* RETURNS: next character */
1082: input() /* ARGUMENTS: (none) */
1083: #endif
1084:
1085: { /* LOCAL VARIABLES: */
1086: static int startup=1; /* First call flag */
1087:
1088: LLDBUG_PRL1("<<capaL_input() is called>>\n");
1089: if (!Lexi_line) { /* was startup */
1090: for(Input_idx=0;Input_idx < MAX_OPENED_FILE;Input_idx++) {
1091: /* for(ii=0;ii<LEX_BUFLEN;ii++) {
1092: Lexi_buf[Input_idx][ii]=0;
1093: }
1094: */
1095: Lexi_buf[Input_idx][0]=0;
1096: Lexi_pos[Input_idx] = 0;
1097: }
1098: Input_idx = 0;
1099: startup=0;
1100: yyin = Input_stream[Input_idx];
1101: }
1102: if (!Lexi_buf[Input_idx][Lexi_pos[Input_idx]]) {
1103: if (fgets(Lexi_buf[Input_idx],LEX_BUFLEN-1,Input_stream[Input_idx])==NULL) {
1104: /* EOF? */
1105: /* no use in flex
1106: printf("capaL_input()EOF %s\n",Opened_filename[Input_idx+1]); fflush(stdout); */
1107: return (0);
1108: }
1109: Lexi_pos[Input_idx] = 0;
1110: Lexi_line++;
1111: printf("input()(%d)\n",Lexi_line);
1112: }
1113: (Lexi_pos[Input_idx])++;
1114: return ( Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1] );
1115: }
1116:
1117: /******************************************************************************/
1118: /* PUSH BACK ONE CHARACTER OF THE INPUT */
1119: /******************************************************************************/
1120:
1121: int /* RETURNS: nothing */
1122: capaL_unput(ch) /* ARGUMENTS: */
1123: register int ch; /* Character to push */
1124: {
1125: if (ch) (Lexi_pos[Input_idx])--;
1126:
1127: /* unput() stream cannot be re-defined */
1128: /* unput(ch); inconsistency between YY_INPUT() and internal matched yytext */
1129: return (0);
1130:
1131: }
1132:
1133:
1134: /******************************************************/
1135:
1136: #ifndef DMALLOC
1137:
1138: char *
1139: strsave(char *s)
1140: {
1141: char *p;
1.4 albertel 1142: if (s==NULL) {return s;}
1.1 albertel 1143: p=capa_malloc(strlen(s)+1,1);
1144: strcpy(p,s);
1145: return (p);
1146: }
1147:
1148: #endif
1149:
1150: /* =========================================================================== */
1151:
1152: #ifndef DMALLOC
1153: char *
1154: capa_malloc(unsigned num,unsigned sz)
1155: {
1156: char *p;
1157: p = calloc(num, sz);
1158: bzero(p, num*sz); /* added Jan 21 1998 */
1159: return (p);
1160: }
1161:
1162: #endif
1163:
1164: #ifndef DMALLOC
1165: void
1166: capa_mfree(p) char *p;
1167: {
1168: free(p);
1169: }
1170: #endif
1171:
1172: void
1173: capa_msg(int type, char *p)
1174: { int idx, i, j;
1175: int len;
1176: char warn_msg[WARN_MSG_LENGTH];
1177: char tmp_line[ONE_TWO_EIGHT];
1178: char *tmp_str;
1179:
1180: strcpy(warn_msg,"File: ");
1181: idx=6;
1182: for(i=0;i<=Input_idx;i++) {
1183: len=strlen(Opened_filename[i]);
1184: for(j=0;j<len;j++) {
1185: warn_msg[idx++] = Opened_filename[i][j];
1186: }
1187: if(i < Input_idx) {
1188: warn_msg[idx++]='-';
1189: warn_msg[idx++]='>';
1190: }
1191: warn_msg[idx]=0;
1192: }
1193: switch (type) {
1194: case MESSAGE_ERROR:
1195: sprintf(tmp_line,", Line %d: ERROR:", Current_line[Input_idx]);
1196: len=strlen(tmp_line);
1197: for(j=0;j<len;j++) {
1198: warn_msg[idx++] = tmp_line[j];
1199: }
1200: warn_msg[idx]=0;
1201: append_error(warn_msg); append_error(p);
1.5 albertel 1202: break;
1.1 albertel 1203: case MESSAGE_WARN:
1204: default:
1205: sprintf(tmp_line,", Line %d: WARNING:", Current_line[Input_idx]);
1206: len=strlen(tmp_line);
1207: for(j=0;j<len;j++) {
1208: warn_msg[idx++] = tmp_line[j];
1209: }
1210: warn_msg[idx]=0;
1211: j = strlen(warn_msg);
1212: len = strlen(p);
1213: tmp_str = (char *)capa_malloc(len+j+1,1);
1214: for(i=0;i<j;i++) {
1215: tmp_str[i]=warn_msg[i];
1216: }
1217: for(i=j;i<j+len;i++) {
1218: tmp_str[i] = p[i-j];
1219: }
1220: append_warn(type,tmp_str);
1221: capa_mfree(tmp_str);
1222: break;
1223: }
1224: }
1225:
1226: /* ======================================================================== */
1227: void
1228: capa_warn_header(int type)
1229: {
1230: int idx, i, j;
1231: int len;
1232: char warn_msg[WARN_MSG_LENGTH];
1233: char tmp_line[ONE_TWO_EIGHT];
1234:
1235: strcpy(warn_msg,"File: ");
1236: idx=6;
1237: for(i=0;i<=Input_idx;i++) {
1238: len=strlen(Opened_filename[i]);
1239: for(j=0;j<len;j++) {
1240: warn_msg[idx++] = Opened_filename[i][j];
1241: }
1242: if(i < Input_idx) {
1243: warn_msg[idx++]='-';
1244: warn_msg[idx++]='>';
1245: }
1246: warn_msg[idx]=0;
1247: }
1248: switch (type) {
1249: case MESSAGE_ERROR:
1250: sprintf(tmp_line,", Line %d: ERROR:", Current_line[Input_idx]);
1251:
1252: break;
1253: case MESSAGE_WARN:
1254: sprintf(tmp_line,", Line %d: WARNING:", Current_line[Input_idx]);break;
1255: default:
1256: sprintf(tmp_line,", Line %d: ERROR:", Current_line[Input_idx]);break;
1257: }
1258: len=strlen(tmp_line);
1259: for(j=0;j<len;j++) {
1260: warn_msg[idx++] = tmp_line[j];
1261: }
1262: warn_msg[idx]=0;
1263: append_error(warn_msg);
1264: }
1265:
1266: /* --------------------------------------------------------------------------- */
1267: #ifdef AVOIDYYINPUT
1268:
1269: void change_file(char *fname)
1270: {
1271: char warn_msg[WARN_MSG_LENGTH];
1272: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1273: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n",
1274: fname);
1275: capa_msg(MESSAGE_ERROR,warn_msg);
1276: return;
1277: }
1278:
1279: if ( include_stack_ptr >= MAX_INCLUDE_DEPTH ) {
1280: sprintf(warn_msg,"Includes nested too deeply" );
1281: capa_msg(MESSAGE_ERROR,warn_msg);
1282: return;
1283: }
1284:
1285: include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER;
1286: yyin = fopen( fname, "r" );
1287: yy_switch_to_buffer( yy_create_buffer( yyin, YY_BUF_SIZE ) );
1288: }
1289:
1290: void
1291: parse_filename(char *line)
1292: {
1293: char *start, fname[MAX_BUFFER_SIZE], warn_msg[WARN_MSG_LENGTH];
1294: int ii,len;
1295:
1296: start = index(line, '\"'); /*** hpux complained */
1297: if( start == NULL ) {
1298: sprintf(warn_msg,"/IMP was not given a filename.\n");
1299: capa_msg(MESSAGE_ERROR,warn_msg);
1300: return;
1301: }
1302: start++; len = strlen(start) - 1;
1303: ii = 0;
1304: while( start[ii] != '\"' ) fname[ii++] = start[ii];
1305: fname[ii] = 0;
1306: LLDBUG_PR2("[parse_filename<%s>]\n",fname);
1307:
1308: change_file(fname);
1309: }
1310:
1311: void
1312: parse_import_id(char *line)
1313: {
1314: char fname[QUARTER_K], warn_msg[WARN_MSG_LENGTH];
1315: int ii, dup_open;
1316: Symbol *symb_p;
1317: int no_error = 0;
1318:
1319: ii = 0;
1320: while( line[ii] != '\0' && line[ii] != ' ' && line[ii] != '\n' && line[ii] != '\t' )
1321: fname[ii++] = line[ii];
1322: fname[ii] = 0;
1323:
1324: LLDBUG_PR2("[parse_import_id<%s>]\n",fname);
1325: symb_p = find_identifier(fname);
1326:
1327: switch (symb_p->s_type) {
1328: case IDENTIFIER:
1329: sprintf(warn_msg,"/IMP %s, var is not defined.\n", fname);
1330: capa_msg(MESSAGE_ERROR,warn_msg);
1331: break;
1332: case I_VAR: case I_CONSTANT: case R_VAR: case R_CONSTANT:
1333: sprintf(warn_msg,"var cannot be a number.\n");
1334: capa_msg(MESSAGE_ERROR,warn_msg);
1335: break;
1336: case S_VAR: case S_CONSTANT: sprintf(fname,"%s",symb_p->s_str);
1337: no_error = 1;
1338: break;
1339: }
1340: if( no_error ) change_file(fname);
1341: }
1342:
1343: #else
1344: void
1345: parse_filename(char *line)
1346: {
1347: char *start, fname[QUARTER_K], warn_msg[WARN_MSG_LENGTH];
1348: int ii, len, dup_open;
1349:
1350: /* printf("IMPORT %s\n", line); */
1351:
1352: start = index(line, '\"'); /*** hpux complained */
1353: if( start != NULL ) {
1354: start++; len = strlen(start) - 1;
1355: ii = 0;
1356: while( start[ii] != '\"' ) {
1357: fname[ii] = start[ii]; ii++;
1358: }
1359: fname[ii] = 0;
1360: LLDBUG_PR2("[parse_filename<%s>]\n",fname);
1361: if(Input_idx < (MAX_OPENED_FILE -1)) {
1362: dup_open = 0;
1363: /* -- no need to check duplicated opening a file
1364: for(ii=0;ii<Input_idx;ii++) {
1365: if(strcmp(Opened_filename[ii],fname)==0) {
1366: dup_open =1;
1367: }
1368: }
1369: */
1370: if( !dup_open ) {
1371: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1372: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n",fname);
1373: capa_msg(MESSAGE_ERROR,warn_msg);
1374: } else {
1375: Input_idx++;
1376: Input_stream[Input_idx]=fopen(fname,"r");
1377: sprintf(Opened_filename[Input_idx], "%s",fname);
1378: Current_line[Input_idx] = 0;
1379: }
1380: } else {
1381: /*
1382: sprintf(warn_msg,"/IMP \"%s\", import file has already been imported.\n",fname);
1383: capa_msg(MESSAGE_WARN,warn_msg);
1384: */
1385: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1386: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n",fname);
1387: capa_msg(MESSAGE_ERROR,warn_msg);
1388: } else {
1389: Input_idx++;
1390: Input_stream[Input_idx]=fopen(fname,"r");
1391: sprintf(Opened_filename[Input_idx], "%s",fname);
1392: Current_line[Input_idx] = 0;
1393: }
1394: }
1395: } else {
1396: sprintf(warn_msg,"/IMP more the %d levels deep ignoring further imports.\n",MAX_OPENED_FILE-1);
1397: capa_msg(MESSAGE_WARN,warn_msg);
1398: }
1399: } else {
1400: sprintf(warn_msg,"%s, is not a valid file name.\n",line);
1401: capa_msg(MESSAGE_ERROR,warn_msg);
1402: }
1403:
1404: }
1405:
1406: void
1407: parse_import_id(char *line)
1408: {
1409: char fname[QUARTER_K], warn_msg[WARN_MSG_LENGTH];
1410: int ii, dup_open;
1411: Symbol *symb_p;
1412: int no_error = 0;
1413:
1414: ii = 0;
1415: while (line[ii] != '\0' && line[ii] != ' ' && line[ii] != '\n' && line[ii] != '\t') {
1416: fname[ii] = line[ii]; ii++;
1417: }
1418: fname[ii] = 0;
1419: LLDBUG_PR2("[parse_import_id<%s>]\n",fname);
1420: symb_p = find_identifier(fname);
1421:
1422: switch (symb_p->s_type) {
1423: case IDENTIFIER:
1424: sprintf(warn_msg,"/IMP %s, var is not defined.\n", fname);
1425: capa_msg(MESSAGE_ERROR,warn_msg);
1426: break;
1427: case I_VAR: case I_CONSTANT: case R_VAR: case R_CONSTANT:
1428: sprintf(warn_msg,"var cannot be a number.\n");
1429: capa_msg(MESSAGE_ERROR,warn_msg);
1430: break;
1431: case S_VAR:
1432: case S_CONSTANT:
1433: sprintf(fname,"%s",symb_p->s_str);
1434: no_error = 1;
1435: break;
1436: }
1437: if( no_error ) {
1438: if(Input_idx < (MAX_OPENED_FILE -1) ) {
1439: dup_open = 0;
1440: /* no need to check duplicated opening a file
1441: for(ii=0;ii<Input_idx;ii++) {
1442: if(strcmp(Opened_filename[ii],fname)==0) dup_open =1;
1443: }
1444: */
1445: if( !dup_open ) {
1446: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1447: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n", fname);
1448: capa_msg(MESSAGE_ERROR,warn_msg);
1449: } else {
1450: Input_idx++;
1451: Input_stream[Input_idx]=fopen(fname,"r");
1452: sprintf(Opened_filename[Input_idx], "%s",fname);
1453: Current_line[Input_idx] = 0;
1454: }
1455: } else {
1456: /* NO warning on duplicated open a file
1457: sprintf(warn_msg,"/IMP \"%s\", file has already been imported.\n", fname);
1458: capa_msg(MESSAGE_WARN,warn_msg);
1459: */
1460: if( capa_access(fname, (F_OK | R_OK)) == -1 ) {
1461: sprintf(warn_msg,"/IMP \"%s\", import file does not exist or is not readable.\n", fname);
1462: capa_msg(MESSAGE_ERROR,warn_msg);
1463: } else {
1464: Input_idx++;
1465: Input_stream[Input_idx]=fopen(fname,"r");
1466: sprintf(Opened_filename[Input_idx], "%s",fname);
1467: Current_line[Input_idx] = 0;
1468: }
1469:
1470: }
1471: } else {
1472: sprintf(warn_msg,"/IMP , too many files has been imported. The maximum is %d files.\n",
1473: MAX_OPENED_FILE-1);
1474: capa_msg(MESSAGE_WARN,warn_msg);
1475: }
1476: }
1477: }
1478: #endif /*AVOIDYYINPUT*/
1479:
1480: void append_dynamic_buf(new_str) char *new_str;
1481: {
1482: int ii,len;
1483:
1484: if(new_str==NULL) return;
1485: len=strlen(new_str);
1486: #ifdef LEX_DBUG
1487: printf("before: len %d; Dynamic_buf_cur %d; Dynamic_buf_max %d\n",
1488: len,Dynamic_buf_cur,Dynamic_buf_max);
1489: #endif /* LEX_DBUG */
1490: if (Dynamic_buf_cur+len+1>Dynamic_buf_max) {
1491: char *temp_text;
1492: Dynamic_buf_max=(Dynamic_buf_cur+len)*2;
1493: temp_text=(char*)capa_malloc(sizeof(char),Dynamic_buf_max);
1494: strncpy(temp_text,Dynamic_buf,Dynamic_buf_max);
1495: free(Dynamic_buf);
1496: Dynamic_buf=temp_text;
1497: }
1498: for(ii=0;ii<len;ii++) {
1499: Dynamic_buf[Dynamic_buf_cur+ii]=new_str[ii];
1500: }
1501: Dynamic_buf_cur += len;
1502: Dynamic_buf[Dynamic_buf_cur+1]='\0';
1503: #ifdef LEX_DBUG
1504: printf("after: len %d; Dynamic_buf_cur %d; Dynamic_buf_max %d\n",
1505: len,Dynamic_buf_cur,Dynamic_buf_max);
1.2 albertel 1506: printf("Dyn_buf %s; added %s\n",Dynamic_buf,new_str);
1.1 albertel 1507: #endif /* LEX_DBUG */
1508: }
1509:
1510: char* parser_status()
1511: {
1512: char *buf,small[SMALL_LINE_BUFFER];
1513: int i,j,totlen=0,len,idx=0;
1514:
1515: for(i=0;i<=Input_idx;i++) totlen+=strlen(Opened_filename[i])+6;
1516: buf=capa_malloc(sizeof(char),totlen);
1517: for(i=0;i<=Input_idx;i++) {
1518: len=strlen(Opened_filename[i]);
1519: for(j=0;j<len;j++) buf[idx++] = Opened_filename[i][j];
1520: buf[idx++] = ':';
1521: sprintf(small,"%d",Current_line[i]);
1522: len=strlen(small);
1523: for(j=0;j<len;j++) buf[idx++] = small[j];
1524: buf[idx++]=' ';
1525: buf[idx]='\0';
1526: }
1527: return buf;
1528: }
1529:
1530: void yyfatalerror(char*msg)
1531: {
1532: char warn_msg[WARN_MSG_LENGTH];
1.6 albertel 1533: sprintf(warn_msg,"Invalid character[\'%s\']\n",yytext);
1.1 albertel 1534: capa_msg(MESSAGE_ERROR,warn_msg);
1.6 albertel 1535: capa_msg(MESSAGE_ERROR,msg);
1.1 albertel 1536: }
1537: void yyerror(char* msg)
1538: {
1539: char warn_msg[WARN_MSG_LENGTH];
1540: sprintf(warn_msg,"%s\n",msg);
1541: capa_msg(MESSAGE_ERROR,warn_msg);
1542: }
1543:
1544: void newyy_input (char *buf,int *result,int max_size)
1545: { int ii, leng, out_of_char;
1546: if (!Lexi_line) { /* was startup */
1547: for(ii=0;ii < MAX_OPENED_FILE;ii++) {
1548: Lexi_buf[ii] = NULL;
1549: Lexi_pos[ii] = 0;
1550: Current_line[ii] = 0;
1551: }
1552: Input_idx = 0;
1553: first_run=0;
1554: yyin = Input_stream[Input_idx]; LIDBUG_PR1("<<yy_input() startup>>\n");
1555: }
1556: out_of_char = 0;
1557: if ( Lexi_buf[Input_idx] == NULL ) {
1558: Lexi_buf[Input_idx] = (char *)capa_malloc(sizeof(char)*LEX_BUFLEN+1,1); out_of_char=1;
1559: } else {
1560: if (!Lexi_buf[Input_idx][Lexi_pos[Input_idx]]) {
1561: /* test if the line buffer is empty or at the end */
1562: out_of_char=1;
1563: }
1564: }
1565: if( out_of_char ) {
1566: if (fgets(Lexi_buf[Input_idx],LEX_BUFLEN-1,Input_stream[Input_idx])==NULL) {
1567: /* read in one line */
1568: LIDBUG_PR2("<<yy_input() fgets() returns NULL, input index=%d>>\n",Input_idx);
1569: if( (Input_idx > 0) && ( Lexi_buf[Input_idx][Lexi_pos[Input_idx]] == '\0') ) {
1570: LIDBUG_PR2("<<yy_input() close an input stream, input index=%d>>\n",Input_idx);
1571: fclose(Input_stream[Input_idx]);
1572: capa_mfree((char *)Lexi_buf[Input_idx]);
1573: Lexi_buf[Input_idx] = NULL;
1574: Input_idx--;
1575: yyin = Input_stream[Input_idx];
1576: /* (Lexi_pos[Input_idx])++; */
1577: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1];
1578: *result = 1;
1579: } else {
1580: *result = YY_NULL; /* End of File */
1581: }
1582: } else { /* successfully read in one line */
1583: leng = strlen(Lexi_buf[Input_idx]);
1584: LIDBUG_PR3("<<yy_input() read into buffer a line(leng=%d), input index=%d>>\n",
1585: leng,Input_idx);
1586: Lexi_pos[Input_idx] = 0;
1587: Lexi_line++;
1588: Current_line[Input_idx]++;
1589: (Lexi_pos[Input_idx])++;
1590: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1];
1591: /* need to take care of return continuation conditions */
1592: /* so, we return to one-char-at-a-time approach */
1593: /* for(ii=0;ii<leng;ii++) { */
1594: /* buf[ii] = Lexi_buf[Input_idx][ii]; */
1595: /* } */
1596: /* buf[ii] = '\0'; */
1597: /* printf("YY_INPUT()(Lexi_line=%d,max size=%d)(%c)",Lexi_line,max_size,buf[0]); */
1598: *result = 1;
1599: }
1600: } else {
1601: /* LIDBUG_PR2("<<yy_input() increase Lexi_pos, input index=%d>>\n",Input_idx); */
1602: (Lexi_pos[Input_idx])++;
1603: buf[0] = Lexi_buf[Input_idx][Lexi_pos[Input_idx]-1];
1604: *result = 1;
1605: }
1606: if (Stop_Parser==1) *result = YY_NULL;
1607: }
1608:
1609: int capa_eof()
1610: {
1611: #ifdef AVOIDYYINPUT
1612: if ( --include_stack_ptr < 0 ) yyterminate();
1613: else {
1614: yy_delete_buffer( YY_CURRENT_BUFFER );
1615: yy_switch_to_buffer(include_stack[include_stack_ptr]);
1616: }
1617: #else
1618: if(Input_idx == 0) {
1619: fclose(Input_stream[Input_idx]);
1620: capa_mfree((char *)Lexi_buf[Input_idx]);
1621: free_problems(LexiProblem_p);
1622: LexiProblem_p=NULL;
1623: /* printf("\nCAPA EOF\n"); fflush(stdout); */
1624: }
1625: return (0);
1626: #endif /*AVOIDYYINPUT*/
1627: }
1628: /* ------------ */
1629:
1630:
1631: /* =========================================================== */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>