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