--- loncom/homework/CAPA-converter/capaLexerDef.flex 2002/01/04 19:52:12 1.16 +++ loncom/homework/CAPA-converter/capaLexerDef.flex 2002/03/20 18:15:00 1.19 @@ -1,6 +1,6 @@ /* The LearningOnline Network with CAPA * CAPA lexer dfinition, heavily modified to become a LON-CAPA convertor - * $Id: capaLexerDef.flex,v 1.16 2002/01/04 19:52:12 albertel Exp $ + * $Id: capaLexerDef.flex,v 1.19 2002/03/20 18:15:00 albertel Exp $ * * Copyright Michigan State University Board of Trustees * @@ -488,40 +488,43 @@ EndLine ([\r][\n]|[\n]) } ^{Spaces}"/MAP" { LLDBUG_PRL1("[MAP]"); Pcount = 0; sccount = 0; BEGIN S_MAP; start_mode(MODE_SCRIPT,NULL);send("&map("); } ^{Spaces}"/RMAP" { LLDBUG_PRL1("[RMAP]"); Pcount = 0; sccount = 0; BEGIN S_MAP; start_mode(MODE_SCRIPT,NULL);send("&rmap("); } -^{Spaces}"/ENDWHILE"([^\n])* { long int file_pos; - int top_item, input_idx; - LLDBUG_PRL2("[ENDWHILE While_idx=<%d>]\n",While_idx); - - top_item = While_idx - 1; - if( top_item < 0 ) { /* strange things must have happened here! */ - - } else { - input_idx = WhileStack[top_item].input_idx; - file_pos = WhileStack[top_item].pos_idx; - Current_line[input_idx] = WhileStack[top_item].line_idx; - Lexi_pos[input_idx] = 0; - fseek(Input_stream[input_idx],file_pos,SEEK_SET); - fgets(Lexi_buf[input_idx],LEX_BUFLEN-1,Input_stream[input_idx]); - While_idx--; - } +^{Spaces}"/ENDWHILE"([^\n])* { + int i; + LLDBUG_PRL2("[ENDWHILE While_idx=<%d>]\n",IFcount); + IFcount--; + end_mode_stream(DEFAULT_DEST,0); + for(i=0;i"); + send_stream(1,"}"); + if (IFcount == 0) { + if (watch_mode[current_dest][1]) { + end_streams(DEFAULT_DEST,1); + } else { + end_streams(DEFAULT_DEST,0); + } + change_destination(DEFAULT_DEST); + } + delete_cache(); BEGIN S_TEXT; } "/WHILE" | -^{Spaces}"/WHILE" { long int file_pos; - int leng; - LLDBUG_PRL2("[WHILE While_idx=<%d>]\n",While_idx); - leng = strlen(Lexi_buf[Input_idx]); /* length of current line */ - /* <-- because we use fgets() to read input, - thus ftell() will give the starting position of next line */ - WhileStack[While_idx].input_idx = Input_idx; - file_pos = ftell(Input_stream[Input_idx]); - file_pos -= leng; /* calibrate the current line length */ - WhileStack[While_idx].pos_idx = file_pos; /* begin of current line */ - WhileStack[While_idx].line_idx = Current_line[Input_idx]; - While_idx++; /* advance the stack pointer */ - - BEGIN S_TRUE_FALSE_STMT; RETURN(CAPA_WHILE); - +^{Spaces}"/WHILE" { + int i; + LLDBUG_PRL2("[WHILE While_idx=<%d>]\n",IFcount); + IFcount++; /* advance the stack pointer */ + BEGIN S_TRUE_FALSE_STMT; + if ( IFcount == 1) { + start_streams(DEFAULT_DEST, 2); + change_destination(DEFAULT_DEST); + watch_mode[current_dest][1]=1; + } + end_mode_stream(DEFAULT_DEST, 0); + start_mode_stream(DEFAULT_DEST,1,MODE_SCRIPT,NULL); + for(i=1;i\n"); } [\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue](%s)",yytext); /* continuation on next line */ } ^{Spaces}"//"[^\n]*$ { LLDBUG_PRL2("[COMMENT<%s>]\n",yytext); start_mode(MODE_SCRIPT,NULL); @@ -812,7 +815,7 @@ EndLine ([\r][\n]|[\n]) } else { add_delayed("\" />\n\t"); } - add_delayed("]",aline); +{Alpha}{AlphaNum}*{Space}*[\[] { + LLDBUG_PR2("[ARRAY<%s>]",yytext); - yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */ - yylval->s_name = strsave(aline); /* free it in parser() */ - yylval->s_type = ARRAY_ID; - - yyless(yyleng-1); /* <-- push back char '[' */ - RETURN(ARRAY_ID); + yyless(yyleng-1); /*<-- push back char '[' */ + if (dosend==1) send("$%s",yytext); + if (dosend==2) add_delayed("$%s",yytext); } {Number}*"\."{Number}*[Ee]"+"{Number}+ | {Number}*"\."{Number}*[Ee]{Number}+ | @@ -906,8 +899,14 @@ EndLine ([\r][\n]|[\n]) if (dosend==1) send("%s",yytext); if (dosend==2) add_delayed("%s",yytext); } -[\[] { LLDBUG_PR1("[dis let ans map '[']"); return(yytext[0]); } -[\]] { LLDBUG_PR1("[dis let ans map ']']"); return(yytext[0]); } +[\[] { LLDBUG_PR1("[dis let ans map '[']"); + if(dosend==1) send("%s",yytext); + if(dosend==2) add_delayed("%s",yytext); + } +[\]] { LLDBUG_PR1("[dis let ans map ']']"); + if(dosend==1) send("%s",yytext); + if(dosend==2) add_delayed("%s",yytext); + } {Space}+ { /* LLDBUG_PR1("[SP ignored]"); Ignore Spaces */ } }