version 1.9, 2001/11/15 21:42:42
|
version 1.21, 2002/09/12 15:54:06
|
Line 1
|
Line 1
|
|
/* The LearningOnline Network with CAPA |
|
* CAPA lexer dfinition, heavily modified to become a LON-CAPA convertor |
|
* $Id$ |
|
* |
|
* 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 */ |
/* capaLexerDef.flex created by Isaac Tsai Jul 15 1996 */ |
/* added /END(variable) */ |
/* added /END(variable) */ |
Line 119 Symbol *FmlSymbLast_p;
|
Line 146 Symbol *FmlSymbLast_p;
|
int FmlSymb_cnt; |
int FmlSymb_cnt; |
int Symb_count; |
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; |
int IFcount; |
WhileLoop_t WhileStack[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */ |
WhileLoop_t WhileStack[MAX_FUNC_NEST]; /* <-- perhaps we can use linked list */ |
int While_idx, Wcount; |
int While_idx, Wcount; |
int sccount; /* Semi-colon count for MAP and RMAP */ |
int sccount; /* Semi-colon count for MAP and RMAP */ |
|
int HINTflag=0; |
|
int EXPflag=0; |
|
int EVALflag=0; |
|
int compound_answer=0; |
|
int essay_answer=0; |
|
|
#ifdef USE_DYNAMIC_SYMBOLS |
#ifdef USE_DYNAMIC_SYMBOLS |
Symbol *SymbList_p; |
Symbol *SymbList_p; |
Line 217 void newyy_input (char *buf,int *result,
|
Line 247 void newyy_input (char *buf,int *result,
|
} \ |
} \ |
Input_idx = 0; \ |
Input_idx = 0; \ |
first_run=0; \ |
first_run=0; \ |
yyin = Input_stream[Input_idx]; LIDBUG_PR1("<<yy_input() startup>>\n"); \ |
yyin = Input_stream[Input_idx]; LIDBUG_PR1("<<yy_input() startup>>\n"); \ |
} \ |
} \ |
out_of_char = 0; \ |
out_of_char = 0; \ |
if ( Lexi_buf[Input_idx] == NULL ) { \ |
if ( Lexi_buf[Input_idx] == NULL ) { \ |
Line 362 EndLine ([\r][\n]|[\n])
|
Line 392 EndLine ([\r][\n]|[\n])
|
%n 1000 |
%n 1000 |
%x S_COMMENT S_HINT S_HINTEXLAINX S_IMPORT S_EXPLAIN S_ENDX S_UNIT S_IGNORE |
%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_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_STRING S_ANSCONTINUE S_TRUE_FALSE_STMT S_WHILE_SKIP |
%x S_NEXT_LINE S_VERB S_ECHO S_STRINGINANS |
%x S_NEXT_LINE S_VERB S_ECHO S_STRINGINANS |
%array |
%array |
|
|
Line 402 EndLine ([\r][\n]|[\n])
|
Line 432 EndLine ([\r][\n]|[\n])
|
send("<PRE>\n"); |
send("<PRE>\n"); |
} |
} |
^{Spaces}"/HIN"{Alpha}*{Spaces} { LLDBUG_PRL1("[HIN]"); |
^{Spaces}"/HIN"{Alpha}*{Spaces} { LLDBUG_PRL1("[HIN]"); |
start_mode(MODE_HINT, ""); |
/* start_mode(MODE_HINT, "");*/ |
|
if (!HINTflag) { |
|
start_streams(HINT_DEST,1); |
|
HINTflag=-1; |
|
} |
|
change_destination(HINT_DEST); |
|
send("\t",NULL); |
BEGIN S_HINT; |
BEGIN S_HINT; |
} |
} |
^{Spaces}"/EXP"{Alpha}*{Spaces} { start_mode(MODE_BLOCK,"condition=&explanation"); |
^{Spaces}"/EXP"{Alpha}*{Spaces} { |
|
if (!EXPflag) { |
|
start_streams(EXP_DEST,1); |
|
EXPflag=-1; |
|
} |
|
change_destination(EXP_DEST); |
|
send("\t",NULL); |
LLDBUG_PRL1("[EXP]"); Current_char_p = String_buf; BEGIN S_EXPLAIN; } |
LLDBUG_PRL1("[EXP]"); Current_char_p = String_buf; BEGIN S_EXPLAIN; } |
^{Spaces}"/IMP"{Alpha}*{Space}+ { LLDBUG_PRL1("[IMP]"); BEGIN S_IMPORT; end_mode(); } |
^{Spaces}"/IMP"{Alpha}*{Space}+ { LLDBUG_PRL1("[IMP]"); BEGIN S_IMPORT; end_mode(); } |
^{Spaces}"/END" { LLDBUG_PRL1("[END]"); |
^{Spaces}"/END" { LLDBUG_PRL1("[END]"); |
Line 439 EndLine ([\r][\n]|[\n])
|
Line 481 EndLine ([\r][\n]|[\n])
|
send("<numericalresponse answer=\""); |
send("<numericalresponse answer=\""); |
dosend=1; |
dosend=1; |
firstparam=1; |
firstparam=1; |
|
compound_answer=0; |
|
essay_answer=0; |
} |
} |
^{Spaces}"/SUBJECTIVE" { LLDBUG_PRL1("[SUBJECTIVE ANSWER]"); |
^{Spaces}"/SUBJECTIVE" { LLDBUG_PRL1("[SUBJECTIVE ANSWER]"); |
Pcount = 0; |
Pcount = 0; |
BEGIN S_ANSWER; |
BEGIN S_ANSWER; |
end_mode(); |
end_mode(); |
send("<capasubjectiveresponse"); |
start_mode(MODE_ANSWER,NULL); |
dosend=1; |
send("<essayresponse"); |
|
dosend=1; |
firstparam=1; |
firstparam=1; |
|
compound_answer=0; |
|
essay_answer=-1; |
} |
} |
^{Spaces}"/MAP" { LLDBUG_PRL1("[MAP]"); Pcount = 0; sccount = 0; BEGIN S_MAP; start_mode(MODE_SCRIPT,NULL);send("&map("); } |
^{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}"/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; |
^{Spaces}"/ENDWHILE"([^\n])* { |
int top_item, input_idx; |
int i; |
LLDBUG_PRL2("[ENDWHILE While_idx=<%d>]\n",While_idx); |
LLDBUG_PRL2("[ENDWHILE While_idx=<%d>]\n",IFcount); |
|
IFcount--; |
top_item = While_idx - 1; |
end_mode_stream(DEFAULT_DEST,0); |
if( top_item < 0 ) { /* strange things must have happened here! */ |
for(i=0;i<IFcount;i++) {send("\t",NULL);} |
|
send_stream(0,"</while>"); |
} else { |
send_stream(1,"}"); |
input_idx = WhileStack[top_item].input_idx; |
if (IFcount == 0) { |
file_pos = WhileStack[top_item].pos_idx; |
if (watch_mode[current_dest][1]) { |
Current_line[input_idx] = WhileStack[top_item].line_idx; |
end_streams(DEFAULT_DEST,1); |
Lexi_pos[input_idx] = 0; |
} else { |
fseek(Input_stream[input_idx],file_pos,SEEK_SET); |
end_streams(DEFAULT_DEST,0); |
fgets(Lexi_buf[input_idx],LEX_BUFLEN-1,Input_stream[input_idx]); |
} |
While_idx--; |
change_destination(DEFAULT_DEST); |
} |
} |
|
delete_cache(); |
BEGIN S_TEXT; |
BEGIN S_TEXT; |
} |
} |
"/WHILE" | |
"/WHILE" | |
^{Spaces}"/WHILE" { long int file_pos; |
^{Spaces}"/WHILE" { |
int leng; |
int i; |
LLDBUG_PRL2("[WHILE While_idx=<%d>]\n",While_idx); |
LLDBUG_PRL2("[WHILE While_idx=<%d>]\n",IFcount); |
leng = strlen(Lexi_buf[Input_idx]); /* length of current line */ |
IFcount++; /* advance the stack pointer */ |
/* <-- because we use fgets() to read input, |
BEGIN S_TRUE_FALSE_STMT; |
thus ftell() will give the starting position of next line */ |
if ( IFcount == 1) { |
WhileStack[While_idx].input_idx = Input_idx; |
start_streams(DEFAULT_DEST, 2); |
file_pos = ftell(Input_stream[Input_idx]); |
change_destination(DEFAULT_DEST); |
file_pos -= leng; /* calibrate the current line length */ |
watch_mode[current_dest][1]=1; |
WhileStack[While_idx].pos_idx = file_pos; /* begin of current line */ |
} |
WhileStack[While_idx].line_idx = Current_line[Input_idx]; |
end_mode_stream(DEFAULT_DEST, 0); |
While_idx++; /* advance the stack pointer */ |
start_mode_stream(DEFAULT_DEST,1,MODE_SCRIPT,NULL); |
|
for(i=1;i<IFcount;i++) {send("\t",NULL);} |
BEGIN S_TRUE_FALSE_STMT; RETURN(CAPA_WHILE); |
send_stream(0,"<while condition=\"",NULL); |
|
send_stream(1,"while (",NULL); |
|
new_cache(); |
|
start_cache(); |
} |
} |
^{Spaces}"/IF" { IFcount++; IFcurrent[IFcount] = RUN_IF_PORTION; |
^{Spaces}"/IF" { int i; |
LLDBUG_PRL2("[IF <IFcount=%d>]",IFcount); BEGIN S_TRUE_FALSE_STMT; RETURN(CAPA_IF); } |
IFcount++; |
^{Spaces}"/ELSE"([^\n])* { LLDBUG_PRL2("[ELSE <IFcount=%d>]\n",IFcount); |
LLDBUG_PRL2("[IF <IFcount=%d>]",IFcount); |
IFcurrent[IFcount] = RUN_ELSE_PORTION; |
BEGIN S_TRUE_FALSE_STMT; |
if( IFstatus[IFcount] == IF_TRUE ) { |
if ( IFcount == 1) { |
LLDBUG_PRL1("[ELSE begin Skip]\n"); |
start_streams(DEFAULT_DEST, 2); |
BEGIN S_IF_SKIP; |
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<IFcount;i++) {send("\t",NULL);} |
|
send_stream(0,"<block condition=\"",NULL); |
|
send_stream(1,"if (",NULL); |
|
new_cache(); |
|
start_cache(); |
|
} |
|
^{Spaces}"/ELSE"([^\n])* { int i; |
|
LLDBUG_PRL2("[ELSE <IFcount=%d>]\n",IFcount); |
|
end_mode_stream(DEFAULT_DEST,0); |
|
for(i=1;i<IFcount;i++) {send("\t",NULL);} |
|
send_stream(0, |
|
"</block>\n<block condition=\"!(%s)\">", |
|
cached_data[current_cache].str); |
|
send_stream(1,"} else {"); |
} |
} |
^{Spaces}"/ENDIF"([^\n])* { IFcount--; LLDBUG_PRL2("[ENDIF <IFcount=%d>]\n",IFcount); |
^{Spaces}"/ENDIF"([^\n])* { int i; |
|
IFcount--; |
|
end_mode_stream(DEFAULT_DEST,0); |
|
for(i=0;i<IFcount;i++) {send("\t",NULL);} |
|
send_stream(0,"</block>"); |
|
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(); |
|
LLDBUG_PRL2("[ENDIF <IFcount=%d>]\n",IFcount); |
} |
} |
"/AND" { LLDBUG_PRL1("[AND]"); BEGIN S_ANSCONTINUE; RETURN(ANS_AND); } |
|
"/DIS" { /* since S_VARIABLE treat {Space} as null, so here we do not match ( */ |
"/DIS" { /* since S_VARIABLE treat {Space} as null, so here we do not match ( */ |
/* so that between /DIS and ( can have as many {Space} as we want */ |
/* so that between /DIS and ( can have as many {Space} as we want */ |
|
start_mode(MODE_OUTTEXT,NULL); |
LLDBUG_PR1("[DIS<]"); |
LLDBUG_PR1("[DIS<]"); |
init_funcstack(); |
init_funcstack(); |
Pcount = 0; BEGIN S_VARIABLE; |
Pcount = 0; BEGIN S_VARIABLE; |
|
send("<display>"); |
start_delayed(); |
start_delayed(); |
} |
} |
"/OR" { LLDBUG_PRL1("[OR]"); BEGIN S_ANSCONTINUE; RETURN(ANS_OR); } |
|
{EndLine} { LLDBUG_PR1("[EoL within S_TEXT]\n"); /* end of the whole text line */ |
{EndLine} { LLDBUG_PR1("[EoL within S_TEXT]\n"); /* end of the whole text line */ |
send("\n"); } |
send("\n"); } |
[\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue](%s)",yytext); /* continuation on next line */ } |
[\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue](%s)",yytext); /* continuation on next line */ } |
Line 629 EndLine ([\r][\n]|[\n])
|
Line 711 EndLine ([\r][\n]|[\n])
|
<S_HINT,S_EXPLAIN>{ |
<S_HINT,S_EXPLAIN>{ |
[/][Dd][Ii][Ss]{Space}*[\(]{Space}* { yy_push_state(S_HINTEXLAINX); } |
[/][Dd][Ii][Ss]{Space}*[\(]{Space}* { yy_push_state(S_HINTEXLAINX); } |
[^/\n]+[/\\] { char *aptr = yytext; |
[^/\n]+[/\\] { char *aptr = yytext; |
int ii; |
|
|
|
yyless(yyleng-1); |
yyless(yyleng-1); |
send(aptr); |
send(aptr); |
} |
} |
[/] { send("/"); } |
[/] { send("/"); } |
[\\] { send("\\"); } |
[\\] { send("\\"); } |
[\\]{Space}*[\n] { LLDBUG_PR1("[\\CR hint explain continue]"); /* Hint and explain continuation */ } |
[\\]{Space}*[\n] { LLDBUG_PR1("[\\CR hint explain continue]"); /* Hint and explain continuation */ send("\n\t");} |
[^/\n\\]+$ {char *aptr = yytext; |
[^/\n\\]+$ {char *aptr = yytext; |
int ii; |
send(aptr); |
send(aptr); |
|
} |
} |
} |
} |
<S_HINT>{ |
<S_HINT>{ |
{EndLine} { LLDBUG_PR1("[CR hint]"); |
{EndLine} { LLDBUG_PR1("[CR hint]"); |
send("\n"); |
send("\n"); |
|
change_destination(DEFAULT_DEST); |
BEGIN S_TEXT; |
BEGIN S_TEXT; |
} |
} |
} |
} |
<S_EXPLAIN>{ |
<S_EXPLAIN>{ |
{EndLine} { LLDBUG_PR1("[CR explain]"); |
{EndLine} { LLDBUG_PR1("[CR explain]"); |
send("\n"); |
send("\n"); |
|
change_destination(DEFAULT_DEST); |
BEGIN S_TEXT; |
BEGIN S_TEXT; |
} |
} |
} |
} |
Line 662 EndLine ([\r][\n]|[\n])
|
Line 743 EndLine ([\r][\n]|[\n])
|
} |
} |
|
|
<S_IMPORT>{ |
<S_IMPORT>{ |
{FileName}{Space}* { end_mode();send("<import>/res/ohiou/%s</import>\n",yytext); BEGIN S_SKIP; } |
{FileName}{Space}* { |
{Identifier}{Space}* { end_mode();send("<import>$%s</import>\n",yytext); BEGIN S_SKIP; } |
char *endquote; |
|
end_mode(); |
|
start_mode(MODE_IMPORT,NULL); |
|
/* Get rid of leading and trailing quotes */ |
|
endquote = strrchr(yytext,'\"'); |
|
*endquote = '\0'; |
|
if (yytext[1] == '/') { |
|
send("%s%s",import_prefix,&yytext[1]); |
|
} else { |
|
send("%s",&yytext[1]); |
|
} |
|
end_mode(); |
|
BEGIN S_SKIP; |
|
} |
|
{Identifier}{Space}* { end_mode(); |
|
start_mode(MODE_IMPORT,NULL); |
|
send("${%s}",yytext); |
|
end_mode(); |
|
BEGIN S_SKIP; |
|
} |
} |
} |
|
|
<S_ANSWER>{ |
<S_ANSWER>{ |
Line 685 EndLine ([\r][\n]|[\n])
|
Line 785 EndLine ([\r][\n]|[\n])
|
[,=] { LLDBUG_PR2("[symbol(%s)]",yytext);} |
[,=] { LLDBUG_PR2("[symbol(%s)]",yytext);} |
[%] { LLDBUG_PR2("[symbol(%s)]",yytext); |
[%] { LLDBUG_PR2("[symbol(%s)]",yytext); |
if (dosend==1) send("%s",yytext); |
if (dosend==1) send("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
if (dosend==2) add_delayed("%%%s",yytext); |
} |
} |
[:@#-] { LLDBUG_PR2("[symbol(%s)]",yytext); |
[:@#-] { LLDBUG_PR2("[symbol(%s)]",yytext); |
if (dosend==1) send("%s",yytext); |
if (dosend==1) send("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
} |
} |
"<" { LLDBUG_PR2("[symbol(%s)]",yytext); |
"<" { LLDBUG_PR2("[symbol(%s)]",yytext); |
|
if (!EVALflag) { |
if (dosend==1) send("%s",yytext); |
if (dosend==1) send("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
} |
} |
|
} |
">" { LLDBUG_PR2("[symbol(%s)]",yytext); |
">" { LLDBUG_PR2("[symbol(%s)]",yytext); |
|
if (!EVALflag) { |
if (dosend==1) send("%s",yytext); |
if (dosend==1) send("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
|
} else { |
|
EVALflag = 0; |
|
} |
} |
} |
|
|
[Pp][Cc][Rr] | |
[Pp][Cc][Rr] | |
[Hh][Gg][Rr] { if (firstparam) firstparam=0; else add_delayed("\" />\n\t"); |
[Hh][Gg][Rr] { if (firstparam) { |
|
firstparam=0; |
|
} else { |
|
add_delayed("\" />\n\t"); |
|
} |
add_delayed("<responseparam name=\"hgr\" type=\"on|off\" default=\""); |
add_delayed("<responseparam name=\"hgr\" type=\"on|off\" default=\""); |
dosend=2; |
dosend=2; |
} |
} |
[Tt][Oo][Ll] { LLDBUG_PR2("[tol(%s)]",yytext); |
[Tt][Oo][Ll] { LLDBUG_PR2("[tol(%s)]",yytext); |
if (firstparam) firstparam=0; else add_delayed("\" />\n\t"); |
if (firstparam) { |
|
firstparam=0; |
|
} else { |
|
add_delayed("\" />\n\t"); |
|
} |
add_delayed("<responseparam name=\"tol\" type=\"tolerance\" description=\"Numerical Tolerance\" default=\""); |
add_delayed("<responseparam name=\"tol\" type=\"tolerance\" description=\"Numerical Tolerance\" default=\""); |
dosend=2; |
dosend=2; |
} |
} |
[Ss][Ii][Gg] { |
[Ss][Ii][Gg] { |
LLDBUG_PR2("[SIG(%s)]",yytext); |
LLDBUG_PR2("[SIG(%s)]",yytext); |
if (firstparam) firstparam=0; else add_delayed("\" />\n\t"); |
if (firstparam) { |
add_delayed("<responseparam name=\"sig\" type=\"int,range,0-12\" description=\"Significant Figures\" default=\""); |
firstparam=0; |
|
} else { |
|
add_delayed("\" />\n\t"); |
|
} |
|
add_delayed("<responseparam name=\"sig\" type=\"int_range,0-12\" description=\"Significant Figures\" default=\""); |
dosend=2; |
dosend=2; |
} |
} |
|
|
[Ss][Tt][Rr] { LLDBUG_PR1("[STR]"); send("\" str=\""); dosend=1; } |
[Ss][Tt][Rr] { LLDBUG_PR1("[STR]"); send("\" type=\""); dosend=1; } |
[Ee][Vv][Aa][Ll] | |
[Ee][Vv][Aa][Ll] | |
[Ee][Vv][Aa][Ll][Uu][Aa][Tt][Ee] { LLDBUG_PR1("[EVAL]");send("\" eval="); dosend=1;} |
[Ee][Vv][Aa][Ll][Uu][Aa][Tt][Ee] { LLDBUG_PR1("[EVAL]");send("\" eval=\""); EVALflag=1; dosend=1;} |
[Uu][Nn][Ii][Tt] | |
[Uu][Nn][Ii][Tt] | |
[Uu][Nn][Ii][Tt][Ss] { LLDBUG_PR1("[UNIT]"); send("\" units=\""); dosend=1;} |
[Uu][Nn][Ii][Tt][Ss] { LLDBUG_PR1("[UNIT]"); send("\" unit=\""); dosend=1;} |
|
|
[Ee][Xx][Tt][Ee][Rr][Nn][Aa][Ll] { LLDBUG_PR1("[EXTERNAL]"); dosend=0; } |
[Ee][Xx][Tt][Ee][Rr][Nn][Aa][Ll] { LLDBUG_PR1("[EXTERNAL]"); dosend=0; } |
[Aa][Nn][Ss][Bb][Oo][Xx] { LLDBUG_PR1("[SHOW_ANS_BOX]"); dosend=0; } |
[Aa][Nn][Ss][Bb][Oo][Xx] { LLDBUG_PR1("[SHOW_ANS_BOX]"); dosend=0; } |
Line 740 EndLine ([\r][\n]|[\n])
|
Line 858 EndLine ([\r][\n]|[\n])
|
if(Pcount==0) { |
if(Pcount==0) { |
BEGIN S_ANSCONTINUE; |
BEGIN S_ANSCONTINUE; |
} |
} |
|
if (essay_answer) { |
|
send(">\n\t"); |
|
} else { |
send("\">\n\t"); |
send("\">\n\t"); |
|
} |
dosend=1; |
dosend=1; |
flush_delayed(); |
flush_delayed(); |
if (!firstparam) send("\" />"); |
if (firstparam!=1) send("\" />\n"); |
send("\n\t<textline />\n</numericalresponse>\n"); |
if (essay_answer) { |
|
send(" <textfield>Enter your answer here.</textfield>\n"); |
|
} else { |
|
send("\t<textline />\n"); |
|
} |
|
/* Fill in Hints */ |
|
if ( !is_dest_empty(HINT_DEST) ) { |
|
send("\t<hintgroup>\n\t<hintpart on=\"default\">\n\t<startouttext />"); |
|
end_streams(HINT_DEST,0); |
|
HINTflag=0; |
|
send("\t<endouttext />\n\t</hintpart>\n\t</hintgroup>\n"); |
|
} |
|
if (essay_answer) { |
|
send("</essayresponse>\n"); |
|
} else { |
|
send("</numericalresponse>\n"); |
|
} |
|
|
|
} |
|
} |
|
|
|
<S_VARIABLE>{ |
|
{Alpha}{AlphaNum}* { LLDBUG_PR2("[ID<%s>]",yytext); |
|
LLDBUG_PR2("[SYMB CNT=<%d>]", Symb_count); |
|
if(Pcount <= 1) { |
|
if (dosend==1) send("${%s}",yytext); |
|
if (dosend==2) add_delayed("${%s}",yytext); |
|
} else { |
|
if (dosend==1) send("$%s",yytext); |
|
if (dosend==2) add_delayed("$%s",yytext); |
|
} |
} |
} |
} |
} |
|
|
Line 759 EndLine ([\r][\n]|[\n])
|
Line 911 EndLine ([\r][\n]|[\n])
|
if (dosend==2) add_delayed("&%s",yytext); |
if (dosend==2) add_delayed("&%s",yytext); |
Pcount++; |
Pcount++; |
} |
} |
{Alpha}{AlphaNum}*{Space}*[\[] { char aline[MAX_FUNC_NAME]; |
{Alpha}{AlphaNum}*{Space}*[\[] { |
int i; |
LLDBUG_PR2("[ARRAY<%s>]",yytext); |
for(i=0;i < (yyleng-1); i++) { |
yyless(yyleng-1); /*<-- push back char '[' */ |
if( yytext[i] == ' ' || yytext[i] == '\t' || |
if (dosend==1) send("$%s",yytext); |
yytext[i] == 0 || yytext[i] == '[' ) break; |
if (dosend==2) add_delayed("$%s",yytext); |
aline[i] = yytext[i]; |
|
} |
|
aline[i] = 0; |
|
LLDBUG_PR2("[ARRAY<%s>]",aline); |
|
|
|
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); |
|
} |
} |
{Number}*"\."{Number}*[Ee]"+"{Number}+ | |
{Number}*"\."{Number}*[Ee]"+"{Number}+ | |
{Number}*"\."{Number}*[Ee]{Number}+ | |
{Number}*"\."{Number}*[Ee]{Number}+ | |
Line 792 EndLine ([\r][\n]|[\n])
|
Line 933 EndLine ([\r][\n]|[\n])
|
if (dosend==1) send("%s",yytext); |
if (dosend==1) send("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
if (dosend==2) add_delayed("%s",yytext); |
} |
} |
[\[] { LLDBUG_PR1("[dis let ans map '[']"); return(yytext[0]); } |
[\[] { LLDBUG_PR1("[dis let ans map '[']"); |
[\]] { LLDBUG_PR1("[dis let ans map ']']"); return(yytext[0]); } |
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 */ } |
{Space}+ { /* LLDBUG_PR1("[SP ignored]"); Ignore Spaces */ } |
} |
} |
|
|
Line 813 EndLine ([\r][\n]|[\n])
|
Line 960 EndLine ([\r][\n]|[\n])
|
} |
} |
|
|
<S_VARIABLE,S_TRUE_FALSE_STMT,S_MAP,S_ANSWER>{ |
<S_VARIABLE,S_TRUE_FALSE_STMT,S_MAP,S_ANSWER>{ |
[\(] { LLDBUG_PR1("[dis let ans map (]"); |
[\(] { LLDBUG_PR1("[let if ans map (]"); |
Pcount++; |
Pcount++; |
if (Pcount > 1 ) { |
if (Pcount > 1 ) { |
if (dosend==1) send(yytext); |
if (dosend==1) send(yytext); |
Line 823 EndLine ([\r][\n]|[\n])
|
Line 970 EndLine ([\r][\n]|[\n])
|
} |
} |
|
|
<S_LET>{ |
<S_LET>{ |
[\(] { LLDBUG_PR1("[dis let ans map (]"); |
[\(] { LLDBUG_PR1("[let (]"); |
Pcount++; |
Pcount++; |
send(yytext); |
send(yytext); |
} |
} |
Line 867 EndLine ([\r][\n]|[\n])
|
Line 1014 EndLine ([\r][\n]|[\n])
|
} |
} |
} |
} |
|
|
|
<S_VARIABLE>{ |
|
"+" { send(".");} |
|
} |
|
|
<S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP>{ |
<S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP>{ |
"==" { LLDBUG_PR1("[==]"); send(yytext); } |
"==" { LLDBUG_PR1("[==]"); send(" eq "); } |
"!=" { LLDBUG_PR1("[!=]"); send(yytext); } |
"!=" { LLDBUG_PR1("[!=]"); send(" ne "); } |
">" { LLDBUG_PR1("[>]"); send(yytext); } |
">" { LLDBUG_PR1("[>]"); send(yytext); } |
">=" { LLDBUG_PR1("[>=]"); send(yytext); } |
">=" { LLDBUG_PR1("[>=]"); send(yytext); } |
"<" { LLDBUG_PR1("[<]"); send(yytext); } |
"<" { LLDBUG_PR1("[<]"); send(yytext); } |
Line 881 EndLine ([\r][\n]|[\n])
|
Line 1032 EndLine ([\r][\n]|[\n])
|
BEGIN S_ECHO; |
BEGIN S_ECHO; |
} |
} |
} |
} |
|
[%] {send("%%");} |
{Operator} { LLDBUG_PR2("[Op(%c) in VAR,TF_STMT,LET]",yytext[0]); send(yytext); } |
{Operator} { LLDBUG_PR2("[Op(%c) in VAR,TF_STMT,LET]",yytext[0]); send(yytext); } |
} |
} |
|
|
Line 890 EndLine ([\r][\n]|[\n])
|
Line 1042 EndLine ([\r][\n]|[\n])
|
[\)] { LLDBUG_PR1("[)]"); |
[\)] { LLDBUG_PR1("[)]"); |
Pcount--; |
Pcount--; |
if(Pcount == 0) { |
if(Pcount == 0) { |
|
send("</display>"); |
BEGIN S_TEXT; |
BEGIN S_TEXT; |
flush_delayed(); |
flush_delayed(); |
} else { |
} else { |
Line 905 EndLine ([\r][\n]|[\n])
|
Line 1058 EndLine ([\r][\n]|[\n])
|
} |
} |
|
|
<S_TRUE_FALSE_STMT>{ |
<S_TRUE_FALSE_STMT>{ |
[\)] { LLDBUG_PRL1("[) in TRUE_FALSE]"); Pcount--; if(Pcount == 0) BEGIN S_NEXT_LINE; return(yytext[0]); } |
[\)] { |
[\\]{Space}*{EndLine} { LLDBUG_PR2("[\\EoL continue in S_TRUE_FALSE_STMT](%s)",yytext); /* continuation on next line */ } |
LLDBUG_PRL1("[) in TRUE_FALSE]"); |
{EndLine} { LLDBUG_PR1("[EoL within /IF()]\n"); RETURN(EoL); } |
Pcount--; |
. { char warn_msg[WARN_MSG_LENGTH]; |
if(Pcount == 0) { |
|
stop_cache(); |
|
send_stream(0,"\">\n"); |
|
send_stream(1,") {\n"); |
|
BEGIN S_NEXT_LINE; |
|
} else { |
|
send_stream(0,")"); |
|
send_stream(1,")"); |
|
} |
|
} |
|
[\\]{Space}*{EndLine} { |
|
LLDBUG_PR2("[\\EoL continue in S_TRUE_FALSE_STMT](%s)",yytext); /* continuation on next line */ |
|
} |
|
{EndLine} { |
|
LLDBUG_PR1("[EoL within /IF()]\n"); RETURN(EoL); |
|
} |
|
. { |
|
char warn_msg[WARN_MSG_LENGTH]; |
sprintf(warn_msg,"In /IF(), an unexpected char [%c] is encountered.\n",yytext[0]); |
sprintf(warn_msg,"In /IF(), an unexpected char [%c] is encountered.\n",yytext[0]); |
capa_msg(MESSAGE_ERROR,warn_msg); |
capa_msg(MESSAGE_ERROR,warn_msg); |
} |
} |
Line 925 EndLine ([\r][\n]|[\n])
|
Line 1095 EndLine ([\r][\n]|[\n])
|
send("'"); |
send("'"); |
yy_pop_state(); |
yy_pop_state(); |
} |
} |
|
[%] { /*Escape percent signs so that vasprintf doesn't choke */ |
|
send("%%"); |
|
} |
|
[\'] { /* Escape single quotes so that perl doesn't choke */ |
|
send("\\\'"); |
|
} |
{EndLine} { /* check for termination of string constant */ |
{EndLine} { /* check for termination of string constant */ |
char warn_msg[WARN_MSG_LENGTH]; |
char warn_msg[WARN_MSG_LENGTH]; |
|
|
Line 987 EndLine ([\r][\n]|[\n])
|
Line 1163 EndLine ([\r][\n]|[\n])
|
} |
} |
|
|
<S_ANSCONTINUE>{ |
<S_ANSCONTINUE>{ |
{Space}+ { /* ignore white spaces */ } |
{Spaces}{EndLine}{Spaces}"/AND" { LLDBUG_PR1("[AND]"); |
[\\]{Space}*{EndLine} { /* continuation */ } |
compound_answer=-1; |
{EndLine} { /* end of answer and/or other answers */ LLDBUG_PR1("[complete an answer<EoL>]"); |
/* implicit in LON-CAPA */ } |
BEGIN S_TEXT; } |
{Spaces}{EndLine}{Spaces}"/OR" { LLDBUG_PR1("[OR]"); |
"/AND" { LLDBUG_PR1("[AND]"); RETURN(ANS_AND); } |
compound_answer=-1; |
"/OR" { LLDBUG_PR1("[OR]"); RETURN(ANS_OR); } |
/*RETURN(ANS_OR); */ } |
} |
{Spaces}{EndLine}{Spaces}"/ANS" { LLDBUG_PRL2("[ANS(%s)]",yytext); |
|
Pcount = 0; |
<S_IF_SKIP>{ |
BEGIN S_ANSWER; |
^{Spaces}"/IF"[^\n]*{EndLine} { IFcount++; LLDBUG_PRL2("[Skip IF <IFcount=%d>]\n",IFcount); |
end_mode(); |
IFstatus[IFcount] = IF_DONT_CARE; |
if (!compound_answer) { |
} |
if ( !is_dest_empty(EXP_DEST) ) { |
^{Spaces}"/ELSE"[^\n]*{EndLine} { LLDBUG_PRL2("[Skip ELSE <IFcount=%d>]",IFcount); |
send("<postanswerdate>\n\t<startouttext />\n"); |
IFcurrent[IFcount]=RUN_ELSE_PORTION; |
end_streams(EXP_DEST,0); |
if( IFstatus[IFcount] == IF_FALSE ) { |
EXPflag=0; |
LLDBUG_PRL1("[ELSE begin TEXT CR]\n"); |
send("\t<endouttext />\n</postanswerdate>\n"); |
BEGIN S_TEXT; |
} |
} |
send("</part>\n<part>\n"); |
if( IFstatus[IFcount] == IF_TRUE ) { |
} |
LLDBUG_PRL1("[ELSE THIS SHOULD NEVER HAPPEN.]\n"); |
start_mode(MODE_ANSWER,NULL); |
} |
send("<numericalresponse answer=\""); |
} |
dosend=1; |
^{Spaces}"/ENDIF"[^\n]*{EndLine} { IFcount--; LLDBUG_PRL2("[Skip ENDIF <IFcount=%d>]\n",IFcount); |
firstparam=1; |
if( IFcount == 0 ) { |
compound_answer=0; |
LLDBUG_PRL1("[ENDIF begin TEXT CR]\n"); |
essay_answer=0; |
BEGIN S_TEXT; |
} |
} |
{Spaces}{EndLine} { |
if( (IFcurrent[IFcount] == RUN_IF_PORTION )&&(IFstatus[IFcount] == IF_TRUE)) { |
/* end of answer and/or other answers */ |
LLDBUG_PRL1("[ENDIF begin TEXT CR]\n"); |
LLDBUG_PR1("[complete an answer<EoL>]"); |
BEGIN S_TEXT; |
if ( !is_dest_empty(EXP_DEST) ) { |
} |
send("<postanswerdate>\n\t<startouttext />\n"); |
if( (IFcurrent[IFcount] == RUN_ELSE_PORTION )&&(IFstatus[IFcount] == IF_FALSE)) { |
end_streams(EXP_DEST,0); |
LLDBUG_PRL1("[ENDIF begin TEXT CR]\n"); |
EXPflag=0; |
BEGIN S_TEXT; |
send("\t<endouttext />\n</postanswerdate>\n"); |
} |
} |
|
send("</part>\n<part>\n"); |
|
BEGIN S_TEXT; |
} |
} |
{EndLine} { LLDBUG_PRL1("[SkipIF a CR]\n"); } |
{Spaces} { /* Do nothing */ } |
[^\n]*$ { LLDBUG_PRL2("[SkipIF anything <IFcount=%d>]",IFcount); } |
|
} |
} |
|
|
<S_NEXT_LINE>{ |
<S_NEXT_LINE>{ |
([.]*){EndLine} { /* this ignores everything until it hits an EoL */ |
([.]*){EndLine} { /* this ignores everything until it hits an EoL */ |
LLDBUG_PRL2("[<S_NEXT_LINE> skip \'%s\' until EoL]\n",yytext); |
LLDBUG_PRL2("[<S_NEXT_LINE> skip \'%s\' until EoL]\n",yytext); |
Line 1062 EndLine ([\r][\n]|[\n])
|
Line 1240 EndLine ([\r][\n]|[\n])
|
%% |
%% |
|
|
/* ========================================================================================== */ |
/* ========================================================================================== */ |
extern void |
|
begin_if_skip() { BEGIN S_IF_SKIP; } |
|
|
|
extern void |
extern void |
begin_while_skip() { Wcount=0; While_idx--; /* while is FALSE, pop it out from stack */ BEGIN S_WHILE_SKIP; } |
begin_while_skip() { Wcount=0; While_idx--; /* while is FALSE, pop it out from stack */ BEGIN S_WHILE_SKIP; } |