--- loncom/homework/CAPA-converter/capaLexerDef.flex 2000/05/03 15:35:11 1.2 +++ loncom/homework/CAPA-converter/capaLexerDef.flex 2002/01/04 19:52:12 1.16 @@ -1,3 +1,30 @@ +/* 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 $ + * + * Copyright Michigan State University Board of Trustees + * + * This file is part of the LearningOnline Network with CAPA (LON-CAPA). + * + * LON-CAPA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LON-CAPA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LON-CAPA; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * /home/httpd/html/adm/gpl.txt + * + * http://www.lon-capa.org/ + */ + /*------------------------------------------------------------------------*/ /* capaLexerDef.flex created by Isaac Tsai Jul 15 1996 */ /* added /END(variable) */ @@ -119,11 +146,12 @@ 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 */ +int HINTflag=0; +int EXPflag=0; #ifdef USE_DYNAMIC_SYMBOLS Symbol *SymbList_p; @@ -140,7 +168,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 +366,7 @@ void newyy_input (char *buf,int *result, #endif int capa_eof(); + %} Alpha [a-zA-Z_] @@ -359,8 +389,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 +409,42 @@ 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 +1123,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 +1153,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 +1767,7 @@ int capa_eof() LexiProblem_p=NULL; /* printf("\nCAPA EOF\n"); fflush(stdout); */ } + end_mode(); return (0); #endif /*AVOIDYYINPUT*/ }