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