--- loncom/homework/CAPA-converter/capaLexerDef.flex 2000/05/03 15:35:11 1.2 +++ loncom/homework/CAPA-converter/capaLexerDef.flex 2001/11/29 18:43:55 1.13 @@ -119,11 +119,10 @@ Symbol *FmlSymbLast_p; int FmlSymb_cnt; int Symb_count; -int IFstatus[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */ -int IFcurrent[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */ int IFcount; WhileLoop_t WhileStack[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */ int While_idx, Wcount; +int sccount; /* Semi-colon count for MAP and RMAP */ #ifdef USE_DYNAMIC_SYMBOLS Symbol *SymbList_p; @@ -140,7 +139,8 @@ extern Problem_t *LexiPro extern Problem_t *LastProblem_p; int first_run=1; int Stop_Parser; -int scriptopen=0; +static int dosend=1; +static int firstparam=1; #define FLEX #define YY_STACK_USED 1 /* for yy_push_state(), yy_pop_state() */ @@ -337,6 +337,7 @@ void newyy_input (char *buf,int *result, #endif int capa_eof(); + %} Alpha [a-zA-Z_] @@ -359,8 +360,8 @@ EndLine ([\r][\n]|[\n]) %n 1000 %x S_COMMENT S_HINT S_HINTEXLAINX S_IMPORT S_EXPLAIN S_ENDX S_UNIT S_IGNORE %x S_SKIP S_VARIABLE S_LET S_DEFINE S_TEXT S_MAP S_FIGURE S_ANSWER -%x S_STRING S_ANSCONTINUE S_TRUE_FALSE_STMT S_IF_SKIP S_WHILE_SKIP -%x S_NEXT_LINE S_VERB +%x S_STRING S_ANSCONTINUE S_TRUE_FALSE_STMT S_WHILE_SKIP +%x S_NEXT_LINE S_VERB S_ECHO S_STRINGINANS %array @@ -379,33 +380,32 @@ EndLine ([\r][\n]|[\n]) } { -{EndLine}{Spaces}"//"[^\n]*$ {LLDBUG_PRL2("[COMMENT<%s>]\n",yytext); - remove_delayed(); - send("%s",yytext); - send_delayed("\n\n"); +{EndLine}{Spaces}"//"[^\n]*$ {LLDBUG_PRL2("[COMMENT<%s>]\n",yytext); + send("# %s\n",&yytext[2]); } -[^\n]*{EndLine} BEGIN S_TEXT; +[^\n]*{EndLine} { + send("\n"); BEGIN S_TEXT; + } } { ^{Spaces}"/LET" | - ^{Spaces}"/BEG" { LLDBUG_PRL1("[LET]"); Pcount = 0; BEGIN S_LET; if (!scriptopen){send(""); } +{ +[^\n]+$ { send(yytext); } +{EndLine} { send(yytext); BEGIN S_TEXT; } } -{ -[;,] { LLDBUG_PR2("[%c]",yytext[0]); return(yytext[0]); } -[\)] { LLDBUG_PR1("[) in MAP]"); Pcount--; - if(Pcount==0) { - BEGIN S_SKIP; - } - return(yytext[0]); +{ +[\\]{Space}*{EndLine} { LLDBUG_PR1("[\\EoL let ans map]"); /* continuation */ } +{EndLine} { LLDBUG_PR1("[EoL END let ans map]\n"); + if(Pcount == 0) BEGIN S_TEXT; + send(";%s",yytext); } } @@ -900,41 +1065,10 @@ send("$%s",yytext); [\\]{Space}*{EndLine} { /* continuation */ } {EndLine} { /* end of answer and/or other answers */ LLDBUG_PR1("[complete an answer]"); BEGIN S_TEXT; } -"/AND" { LLDBUG_PR1("[AND]"); RETURN(ANS_AND); } +"/AND" { LLDBUG_PR1("[AND]"); /* implicit in LON-CAPA */ } "/OR" { LLDBUG_PR1("[OR]"); RETURN(ANS_OR); } } -{ -^{Spaces}"/IF"[^\n]*{EndLine} { IFcount++; LLDBUG_PRL2("[Skip IF ]\n",IFcount); - IFstatus[IFcount] = IF_DONT_CARE; - } -^{Spaces}"/ELSE"[^\n]*{EndLine} { LLDBUG_PRL2("[Skip ELSE ]",IFcount); - IFcurrent[IFcount]=RUN_ELSE_PORTION; - if( IFstatus[IFcount] == IF_FALSE ) { - LLDBUG_PRL1("[ELSE begin TEXT CR]\n"); - BEGIN S_TEXT; - } - if( IFstatus[IFcount] == IF_TRUE ) { - LLDBUG_PRL1("[ELSE THIS SHOULD NEVER HAPPEN.]\n"); - } - } -^{Spaces}"/ENDIF"[^\n]*{EndLine} { IFcount--; LLDBUG_PRL2("[Skip ENDIF ]\n",IFcount); - if( IFcount == 0 ) { - LLDBUG_PRL1("[ENDIF begin TEXT CR]\n"); - BEGIN S_TEXT; - } - if( (IFcurrent[IFcount] == RUN_IF_PORTION )&&(IFstatus[IFcount] == IF_TRUE)) { - LLDBUG_PRL1("[ENDIF begin TEXT CR]\n"); - BEGIN S_TEXT; - } - if( (IFcurrent[IFcount] == RUN_ELSE_PORTION )&&(IFstatus[IFcount] == IF_FALSE)) { - LLDBUG_PRL1("[ENDIF begin TEXT CR]\n"); - BEGIN S_TEXT; - } - } -{EndLine} { LLDBUG_PRL1("[SkipIF a CR]\n"); } -[^\n]*$ { LLDBUG_PRL2("[SkipIF anything ]",IFcount); } -} { ([.]*){EndLine} { /* this ignores everything until it hits an EoL */ LLDBUG_PRL2("[ skip \'%s\' until EoL]\n",yytext); @@ -961,22 +1095,16 @@ send("$%s",yytext); { ^{Spaces}"/ENDVERB" { LLDBUG_PRL1("[END VERB]\n"); - yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); - yylval->s_str = strsave(Dynamic_buf); /* **** */ - yylval->s_type = S_CONSTANT; - capa_mfree(Dynamic_buf); - Dynamic_buf_cur=-1; - Dynamic_buf_max=0; - BEGIN S_TEXT; RETURN(VERBATIM); + BEGIN S_TEXT; + puts("\n\n"); + end_mode(); } -.*|{EndLine} { append_dynamic_buf(yytext); } +.*|{EndLine} { send(yytext); } } %% /* ========================================================================================== */ -extern void -begin_if_skip() { BEGIN S_IF_SKIP; } extern void begin_while_skip() { Wcount=0; While_idx--; /* while is FALSE, pop it out from stack */ BEGIN S_WHILE_SKIP; } @@ -1581,6 +1709,7 @@ int capa_eof() LexiProblem_p=NULL; /* printf("\nCAPA EOF\n"); fflush(stdout); */ } + end_mode(); return (0); #endif /*AVOIDYYINPUT*/ }