Diff for /loncom/homework/CAPA-converter/capaLexerDef.flex between versions 1.1 and 1.16

version 1.1, 2000/04/12 20:06:16 version 1.16, 2002/01/04 19:52:12
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           HINTflag=0;
   int           EXPflag=0;
   
 #ifdef  USE_DYNAMIC_SYMBOLS  #ifdef  USE_DYNAMIC_SYMBOLS
 Symbol       *SymbList_p;  Symbol       *SymbList_p;
Line 140  extern        Problem_t         *LexiPro Line 168  extern        Problem_t         *LexiPro
 extern        Problem_t         *LastProblem_p;  extern        Problem_t         *LastProblem_p;
 int           first_run=1;  int           first_run=1;
 int           Stop_Parser;  int           Stop_Parser;
   static        int dosend=1;
   static        int firstparam=1;
 #define  FLEX  #define  FLEX
   
 #define  YY_STACK_USED   1  /* for yy_push_state(), yy_pop_state() */  #define  YY_STACK_USED   1  /* for yy_push_state(), yy_pop_state() */
Line 336  void newyy_input (char *buf,int *result, Line 366  void newyy_input (char *buf,int *result,
 #endif  #endif
   
 int capa_eof();  int capa_eof();
   
 %}  %}
   
 Alpha      [a-zA-Z_]  Alpha      [a-zA-Z_]
Line 358  EndLine    ([\r][\n]|[\n]) Line 389  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  %x  S_NEXT_LINE S_VERB   S_ECHO S_STRINGINANS
 %array  %array
   
   
Line 378  EndLine    ([\r][\n]|[\n]) Line 409  EndLine    ([\r][\n]|[\n])
 }  }
   
 <S_COMMENT>{  <S_COMMENT>{
 ^{Spaces}"//"[^\n]*$      { LLDBUG_PRL2("[COMMENT<%s>]\n",yytext);  {EndLine}{Spaces}"//"[^\n]*$ {LLDBUG_PRL2("[COMMENT<%s>]\n",yytext); 
                                         send(&yytext[2]);        send("# %s\n",&yytext[2]);
  send("\n");                               }
                                         BEGIN S_COMMENT;   [^\n]*{EndLine}      {
                                       }                         send("\n"); BEGIN S_TEXT;
 .      { send("</comment>\n"); BEGIN S_TEXT; }                       }
 }  }
   
   
 <S_TEXT>{  <S_TEXT>{
 ^{Spaces}"/LET" |  ^{Spaces}"/LET" |
 ^{Spaces}"/BEG"                  { LLDBUG_PRL1("[LET]"); Pcount = 0; init_funcstack(); BEGIN S_LET; RETURN(CAPA_LET); }     ^{Spaces}"/BEG"                  { LLDBUG_PRL1("[LET]"); Pcount = 0; BEGIN S_LET; start_mode(MODE_SCRIPT,NULL);
   }
 ^{Spaces}"/VERB"                 {   ^{Spaces}"/VERB"                 { 
                                    LLDBUG_PRL1("[VERBATIM]");                                     LLDBUG_PRL1("[VERBATIM]");
    Dynamic_buf = (char *)capa_malloc(sizeof(char),10);  
    Dynamic_buf_max = 10;  
    Dynamic_buf_cur = 0;  
    Dynamic_buf[0] = '\0';  
                                    BEGIN S_VERB;                                      BEGIN S_VERB; 
      start_mode(MODE_OUTTEXT,NULL);
      send("<PRE>\n");
                                  }                                   }
 ^{Spaces}"/HIN"{Alpha}*{Spaces}  { LLDBUG_PRL1("[HIN]"); Current_char_p = String_buf;  BEGIN S_HINT; }  ^{Spaces}"/HIN"{Alpha}*{Spaces}  { LLDBUG_PRL1("[HIN]"); 
 ^{Spaces}"/EXP"{Alpha}*{Spaces}  { LLDBUG_PRL1("[EXP]"); Current_char_p = String_buf;  BEGIN S_EXPLAIN; }                                 /*    start_mode(MODE_HINT, "");*/
 ^{Spaces}"/IMP"{Alpha}*{Space}+  { LLDBUG_PRL1("[IMP]"); BEGIN S_IMPORT; }                                     if (!HINTflag) {
                                        start_streams(HINT_DEST,1);
                                        HINTflag=-1;
                                      }
                                      change_destination(HINT_DEST);
      BEGIN S_HINT; 
                                    }
   ^{Spaces}"/EXP"{Alpha}*{Spaces}  { 
                                      if (!EXPflag) {
                                        start_streams(EXP_DEST,1);
                                        EXPflag=-1;
                                      }
                                      change_destination(EXP_DEST);
                                      LLDBUG_PRL1("[EXP]"); Current_char_p = String_buf;  BEGIN S_EXPLAIN; }
   ^{Spaces}"/IMP"{Alpha}*{Space}+  { LLDBUG_PRL1("[IMP]"); BEGIN S_IMPORT; end_mode(); }
 ^{Spaces}"/END"                  { LLDBUG_PRL1("[END]");    ^{Spaces}"/END"                  { LLDBUG_PRL1("[END]");  
                                     if ( (LexiProblem_p !=NULL) &&                                       if ( (LexiProblem_p !=NULL) && 
  (LexiProblem_p->question != NULL) &&    (LexiProblem_p->question != NULL) && 
Line 409  EndLine    ([\r][\n]|[\n]) Line 454  EndLine    ([\r][\n]|[\n])
     } else {      } else {
       EndText_p=NULL;        EndText_p=NULL;
     }      }
     End_of_input = 1; BEGIN S_IGNORE;RETURN(CAPA_END);       End_of_input = 1; BEGIN S_IGNORE; 
                                   }                                    }
 ^{Spaces}"/START"[^\n]*          { LLDBUG_PRL1("[START]");    ^{Spaces}"/START"[^\n]*          { LLDBUG_PRL1("[START]");  
                                     if (LexiProblem_p !=NULL &&                                       if (LexiProblem_p !=NULL && 
Line 419  EndLine    ([\r][\n]|[\n]) Line 464  EndLine    ([\r][\n]|[\n])
       StartText_p=NULL;        StartText_p=NULL;
     }      }
     BEGIN S_TEXT;      BEGIN S_TEXT;
     RETURN(CAPA_START);   
                                   }                                    }
                                                                       
 ^{Spaces}"/END"{Spaces}[\(]{Spaces}      { LLDBUG_PRL1("[END()]"); BEGIN S_ENDX; }  ^{Spaces}"/END"{Spaces}[\(]{Spaces}      { LLDBUG_PRL1("[END()]"); BEGIN S_ENDX; }
 ^"/DEF"                       { Bcount = 0; BEGIN S_DEFINE; RETURN(CAPA_DEF); }  ^"/DEF"                       { Bcount = 0; BEGIN S_DEFINE; RETURN(CAPA_DEF); }
 ^{Spaces}"/ANS"               { LLDBUG_PRL2("[ANS(%s)]",yytext); Pcount = 0; BEGIN S_ANSWER; RETURN(CAPA_ANS); }  ^{Spaces}"/ANS"               { LLDBUG_PRL2("[ANS(%s)]",yytext); 
 ^{Spaces}"/SUBJECTIVE"        { LLDBUG_PRL1("[SUBJECTIVE ANSWER]"); Pcount = 0; BEGIN S_ANSWER; RETURN(CAPA_SUBJ); }                                  Pcount = 0; 
 ^{Spaces}"/MAP"               { LLDBUG_PRL1("[MAP]");  Pcount = 0; BEGIN S_MAP;   RETURN(CAPA_MAP); }                                  BEGIN S_ANSWER; 
 ^{Spaces}"/RMAP"              { LLDBUG_PRL1("[RMAP]"); Pcount = 0; BEGIN S_MAP;   RETURN(CAPA_RMAP); }                                  end_mode();
    start_mode(MODE_ANSWER,NULL);
                                   send("<numericalresponse answer=\""); 
    dosend=1;
    firstparam=1;
                                 }
   ^{Spaces}"/SUBJECTIVE"        { LLDBUG_PRL1("[SUBJECTIVE ANSWER]"); 
                                   Pcount = 0; 
                                   BEGIN S_ANSWER;
                                   end_mode();
    start_mode(MODE_ANSWER,NULL);
                                   send("<capasubjectiveresponse");
    dosend=1; 
    firstparam=1;                            
                                 }
   ^{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;         ^{Spaces}"/ENDWHILE"([^\n])*          { long int  file_pos;       
                                 int   top_item, input_idx;                                  int   top_item, input_idx;
                                 LLDBUG_PRL2("[ENDWHILE While_idx=<%d>]\n",While_idx);                                  LLDBUG_PRL2("[ENDWHILE While_idx=<%d>]\n",While_idx);
Line 463  EndLine    ([\r][\n]|[\n]) Line 523  EndLine    ([\r][\n]|[\n])
                                 BEGIN S_TRUE_FALSE_STMT; RETURN(CAPA_WHILE);                                   BEGIN S_TRUE_FALSE_STMT; RETURN(CAPA_WHILE); 
                                                                   
                               }                                }
 ^{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); }  "/AND"                        { LLDBUG_PRL1("[AND]"); /*implict in LON-CAPA*/}
 "/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 */
                                 LLDBUG_PR1("[DIS<]");                                  LLDBUG_PR1("[DIS<]");
                                 init_funcstack();                                  init_funcstack();
                                 Pcount = 0; BEGIN S_VARIABLE;                                   Pcount = 0; BEGIN S_VARIABLE; 
                                 RETURN(CAPA_VAR);    start_delayed();
                               }                                }
 "/OR"                         { LLDBUG_PRL1("[OR]"); BEGIN S_ANSCONTINUE;  RETURN(ANS_OR); }  "/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 */ 
                                 RETURN(EoL); }                                  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 */ }                       
 ^{Spaces}"//"[^\n]*{EndLine}      { LLDBUG_PRL2("[COMMENT<%s>]\n",yytext);  ^{Spaces}"//"[^\n]*$      { LLDBUG_PRL2("[COMMENT<%s>]\n",yytext);
                                         send("<comment>\n");                                          start_mode(MODE_SCRIPT,NULL); 
                                         send(&yytext[2]);                                          send("# %s\n",&yytext[2]);
                                         BEGIN S_COMMENT;    BEGIN S_COMMENT;
                                       }                                        }
   
 [^/\n\\]+$  |  [^/\n\\]+$  |
 [/]         |   [/]         | 
 [\\]                          {  yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));  [\\]                          {  start_mode(MODE_OUTTEXT,NULL);
                                 yylval->s_str = strsave(yytext);  
                                 LLDBUG_PR2("[TEXT_LINE<%s>]",yytext);                                  LLDBUG_PR2("[TEXT_LINE<%s>]",yytext);
         RETURN(TEXT_LINE);    send(yytext);
       }        }
 ([^/\n])+[/] |  ([^/\n])+[/] |
 ([^/\n])+[\\]                 { /* matches anything until a '/' or a '\' */  ([^/\n])+[\\]                 { /* matches anything until a '/' or a '\' */
                                   start_mode(MODE_OUTTEXT,NULL);
                                 LLDBUG_PR2("[TEXT_LINE( )<%s>]",yytext);                                  LLDBUG_PR2("[TEXT_LINE( )<%s>]",yytext);
                                                                   
                                 yyless(yyleng-1); /* push back the last char */                                  yyless(yyleng-1); /* push back the last char */
                                 yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));  
                                 yylval->s_str = strsave(yytext);  
                                   
                                 BEGIN S_TEXT;                                  BEGIN S_TEXT;
                                 RETURN(TEXT_LINE);    send(yytext);
                               }                                }
 <<EOF>>                       {   <<EOF>>                       { 
 #ifdef AVOIDYYINPUT  #ifdef AVOIDYYINPUT
Line 526  EndLine    ([\r][\n]|[\n]) Line 616  EndLine    ([\r][\n]|[\n])
     }      }
   } else {    } else {
     sprintf(warn_msg,      sprintf(warn_msg,
     "at End-of-File, a /END is needed.\n");   "at End-of-File, a /END is needed.\n");
     capa_msg(MESSAGE_ERROR,warn_msg);      capa_msg(MESSAGE_ERROR,warn_msg);
   }    }
   free_problems(LexiProblem_p);    free_problems(LexiProblem_p);
Line 609  EndLine    ([\r][\n]|[\n]) Line 699  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);
                                   for(ii=0;ii<yyleng;ii++) {    send(aptr);
                                   *Current_char_p++ = *aptr++;  
                                 }                                  }
                                   [/]                            { send("/"); }
                               }  [\\]                           { send("\\"); }
 [/]                            { *Current_char_p++ = '/'; }  
 [\\]                           { *Current_char_p++ = '\\'; }  
 [\\]{Space}*[\n]               { LLDBUG_PR1("[\\CR hint explain continue]"); /* Hint and explain continuation */ }  [\\]{Space}*[\n]               { LLDBUG_PR1("[\\CR hint explain continue]"); /* Hint and explain continuation */ }
 [^/\n\\]+$                      { char  *aptr = yytext;  [^/\n\\]+$                     {char  *aptr = yytext;
                                 int    ii;                                  send(aptr);
                                 for(ii=0;ii<yyleng;ii++) {                                 }
                                   *Current_char_p++ = *aptr++;  
                                 }  
                               }  
 }  }
 <S_HINT>{  <S_HINT>{
 {EndLine}                     {  LLDBUG_PR1("[CR hint]");  {EndLine}                     {  LLDBUG_PR1("[CR hint]");
                                  yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));                                   send("\n"); 
                 *Current_char_p++ = '\n'; *Current_char_p = '\0';                                   change_destination(DEFAULT_DEST);
                          yylval->s_str = strsave(String_buf);                                   BEGIN S_TEXT;
                                  BEGIN S_TEXT; RETURN(HINT_LINE);   
                               }                                }
 }  }
 <S_EXPLAIN>{  <S_EXPLAIN>{
 {EndLine}                     {  LLDBUG_PR1("[CR explain]");  {EndLine}                     {  LLDBUG_PR1("[CR explain]");
                                  yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));                                   send("\n"); 
                 *Current_char_p++ = '\n'; *Current_char_p = '\0';                                   change_destination(DEFAULT_DEST);
                          yylval->s_str = strsave(String_buf);                                   BEGIN S_TEXT;
                                  BEGIN S_TEXT; RETURN(EXPLAIN_LINE);   
                               }                                }
 }  }
   
 <S_HINTEXLAINX>{  <S_HINTEXLAINX>{
 {Alpha}{AlphaNum}*            { char   *aptr;  {Alpha}{AlphaNum}*            {send("${%s}",yytext);}
                                 char    tmp_str[QUARTER_K],warn_msg[ONE_K];  
                                 int     ii, len;  
                                 Symbol *tmp_p;  
                                   
                                 /*tmp_p = find_identifier(yytext);*/  
                                 switch(tmp_p->s_type) {  
                                   case IDENTIFIER:  
                                         sprintf(warn_msg,"var %s not defined.\n", yytext);  
                                         capa_msg(MESSAGE_ERROR,warn_msg);  
                                        break;  
                                   case I_VAR:  
                                   case I_CONSTANT:   
                                          sprintf(tmp_str,"%ld",tmp_p->s_int);  
                                          len = strlen(tmp_str);  
                                          for(ii=0;ii< len;ii++) {  
                                            *Current_char_p++ = tmp_str[ii];  
                                          }  
                                        break;  
                                   case R_VAR:  
                                   case R_CONSTANT:   
                                          sprintf(tmp_str,"%g",tmp_p->s_real);  
                                          len = strlen(tmp_str);  
                                          for(ii=0;ii< len;ii++) {  
                                            *Current_char_p++ = tmp_str[ii];  
                                          }  
                                        break;  
                                   case S_VAR:  
                                   case S_CONSTANT:   
                                          len = strlen(tmp_p->s_str);  
                                          aptr = tmp_p->s_str;  
                                          for(ii=0;ii< len;ii++) {  
                                            *Current_char_p++ = *aptr++;  
                                          }  
                                        break;  
                                 }  
                               }  
 {Space}+                      { }  {Space}+                      { }
 [)]                           {  yy_pop_state(); }  [)]                           {  yy_pop_state(); }
 }  }
   
 <S_IMPORT>{  <S_IMPORT>{
 {FileName}{Space}*             { parse_filename(yytext);    BEGIN S_SKIP; }  {FileName}{Space}*             { char *endquote;
 {Identifier}{Space}*           { parse_import_id(yytext);   BEGIN S_SKIP; }                                   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>{
 [Pp][Ll][Uu][Ss]             { LLDBUG_PR1("[PLUS]");  RETURN(ANS_PLUS); }  [Pp][Ll][Uu][Ss]             { LLDBUG_PR1("[PLUS]"); add_delayed("+");}
 [Mm][Ii][Nn][Uu][Ss]         { LLDBUG_PR1("[MINUS]"); RETURN(ANS_MINUS); }  [Mm][Ii][Nn][Uu][Ss]         { LLDBUG_PR1("[MINUS]"); add_delayed("-");}
 [Cc][Ss]                     { LLDBUG_PR1("[CS]");    RETURN(ANS_CS); }  
 [Cc][Ii]                     { LLDBUG_PR1("[CI]");    RETURN(ANS_CI); }  [Cc][Ss]                     { LLDBUG_PR1("[CS]"); send("cs");}
 [Mm][Cc]                     { LLDBUG_PR1("[MC]");    RETURN(ANS_MC); }  [Cc][Ii]                     { LLDBUG_PR1("[CI]"); send("ci");}
   [Mm][Cc]                     { LLDBUG_PR1("[MC]"); send("mc");}
   [Ff][Mm][Ll]                 { LLDBUG_PR1("[FORMULA]"); send("fml"); }
   
 [Oo][Nn]                     |  [Oo][Nn]                     |
 [Yy][Ee][Ss]                 { LLDBUG_PR1("[ON]");    RETURN(ANS_ON); }  [Yy][Ee][Ss]                 { LLDBUG_PR1("[ON]"); send("on");}
 [Oo][Ff][Ff]                 |  [Oo][Ff][Ff]                 |
 [Nn][Oo]                     { LLDBUG_PR1("[OFF]");   RETURN(ANS_OFF); }  [Nn][Oo]                     { LLDBUG_PR1("[OFF]"); send("off");}
 [Ff][Mm][Ll]                 { LLDBUG_PR1("[FORMULA]");   RETURN(ANS_FORMULA); }  [Ff][Mm][Tt]                 { LLDBUG_PR1("[FMT]"); }
 [Ff][Mm][Tt]                 { LLDBUG_PR1("[FMT]");   RETURN(ANS_FMT); }  [Uu][Nn][Ff][Mm][Tt]         { LLDBUG_PR1("[UNFMT]"); }
 [Uu][Nn][Ff][Mm][Tt]         { LLDBUG_PR1("[UNFMT]"); RETURN(ANS_UNFMT); }  
 [,:%=@#-]                  { LLDBUG_PR2("[symbol(%s)]",yytext); return(yytext[0]); }  [,=]                  { LLDBUG_PR2("[symbol(%s)]",yytext);}
 "<"                          { LLDBUG_PR2("[symbol(%s)]",yytext); return(yytext[0]); }  [%]                  { LLDBUG_PR2("[symbol(%s)]",yytext); 
 ">"                          { LLDBUG_PR2("[symbol(%s)]",yytext); return(yytext[0]); }                         if (dosend==1) send("%s",yytext);
 [Ss][Ii][Gg]                 { LLDBUG_PR2("[SIG(%s)]",yytext);  RETURN(ANS_SIG); }                         if (dosend==2) add_delayed("%%%s",yytext);
 [Tt][Oo][Ll]                 { LLDBUG_PR2("[tol(%s)]",yytext);  RETURN(ANS_TOLERANCE); }                       }
 [Ss][Tt][Rr]                 { LLDBUG_PR1("[STR]");   RETURN(ANS_COMPARE); }  [:@#-]                  { LLDBUG_PR2("[symbol(%s)]",yytext); 
 [Ww][Gg][Tt]                 { LLDBUG_PR1("[WGT]");   RETURN(ANS_WEIGHT); }                            if (dosend==1) send("%s",yytext);
                             if (dosend==2) add_delayed("%s",yytext);
                           }
   "<"                          { LLDBUG_PR2("[symbol(%s)]",yytext);
                                  if (dosend==1) send("%s",yytext);
                                  if (dosend==2) add_delayed("%s",yytext);
                                }
   ">"                          { LLDBUG_PR2("[symbol(%s)]",yytext);
                                  if (dosend==1) send("%s",yytext);
                                  if (dosend==2) add_delayed("%s",yytext);
                                }
   
 [Pp][Cc][Rr]                 |  [Pp][Cc][Rr]                 |
 [Hh][Gg][Rr]                 { RETURN(ANS_PCREDIT); }  [Hh][Gg][Rr]                 { if (firstparam) {
 [Pp][Aa][Tt][Hh]             { RETURN(ANS_PATH); }   firstparam=0; 
 [Cc][Aa][Ll][Cc]             { RETURN(ANS_CALC); }         } else {
 [Tt][Rr][Yy]                 |   add_delayed("\" />\n\t");
 [Tt][Rr][Ii][Ee][Ss]         { LLDBUG_PR1("[TRY]");     RETURN(ANS_TRY); }         }
 [Uu][Nn][Ii][Tt]             |                                 add_delayed("<responseparam name=\"hgr\" type=\"on|off\" default=\""); 
 [Uu][Nn][Ii][Tt][Ss]         { LLDBUG_PR1("[UNIT]");    RETURN(ANS_UNIT); }                                 dosend=2;
 [Bb][Rr]                     { LLDBUG_PR1("[SHOW_BR]"); RETURN(ANS_SHOW_BR);  }                               }
 [Vv][Ee][Rr][Bb][Aa][Tt][Ii][Mm] { LLDBUG_PR1("[VERBATIM]"); RETURN(ANS_VERBATIM); }  [Tt][Oo][Ll]                 { LLDBUG_PR2("[tol(%s)]",yytext);
 [Aa][Nn][Ss][Bb][Oo][Xx]     { LLDBUG_PR1("[SHOW_ANS_BOX]"); RETURN(ANS_BOX_SHOW);  }                                 if (firstparam) {
 [Hh][Ii][Nn][Tt]             { LLDBUG_PR1("[HINT]");    RETURN(ANS_HINT); }   firstparam=0; 
 [Ee][Xx][Pp][Ll][Aa][Ii][Nn] { LLDBUG_PR1("[EXPLAIN]"); RETURN(ANS_EXPLAIN); }         } else {
 [Ee][Xx][Tt][Ee][Rr][Nn][Aa][Ll]  { LLDBUG_PR1("[EXTERNAL]"); RETURN(ANS_EXTERNAL); }   add_delayed("\" />\n\t");
          }
          add_delayed("<responseparam name=\"tol\" type=\"tolerance\" description=\"Numerical Tolerance\" default=\""); 
                                  dosend=2;
                                }
   [Ss][Ii][Gg]                 { 
                                  LLDBUG_PR2("[SIG(%s)]",yytext); 
                                  if (firstparam) {
    firstparam=0; 
          } else {
    add_delayed("\" />\n\t");
          }
          add_delayed("<responseparam name=\"sig\" type=\"int,range,0-12\" description=\"Significant Figures\" default=\""); 
                                  dosend=2;
                                }
   
   [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]"); RETURN(ANS_EVAL); }  [Ee][Vv][Aa][Ll][Uu][Aa][Tt][Ee] { LLDBUG_PR1("[EVAL]");send("\" eval="); dosend=1;}
   [Uu][Nn][Ii][Tt]             |
   [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; }
   [Aa][Nn][Ss][Bb][Oo][Xx]     { LLDBUG_PR1("[SHOW_ANS_BOX]"); dosend=0; }
   [Vv][Ee][Rr][Bb][Aa][Tt][Ii][Mm] { LLDBUG_PR1("[VERBATIM]"); dosend=0; }
   [Bb][Rr]                     { LLDBUG_PR1("[SHOW_BR]"); dosend=0; }
   [Pp][Aa][Tt][Hh]             { send("\" path=\""); dosend=0; }
   [Cc][Aa][Ll][Cc]             { send("\" calc=\""); dosend=0; }
   
   [Ee][Xx][Pp][Ll][Aa][Ii][Nn] { LLDBUG_PR1("[EXPLAIN]"); dosend=0; }
   [Hh][Ii][Nn][Tt]             { LLDBUG_PR1("[HINT]"); dosend=0; }
   [Tt][Rr][Yy]                 |
   [Tt][Rr][Ii][Ee][Ss]         { LLDBUG_PR1("[TRY]"); dosend=0; }
   [Ww][Gg][Tt]                 { LLDBUG_PR1("[WGT]"); dosend=0; }
   
 [\)]                         { LLDBUG_PR1("[)]"); Pcount--;   [\)]                         { LLDBUG_PR1("[)]"); Pcount--; 
                                if(Pcount==0) {                                 if(Pcount==0) {
                                    BEGIN S_ANSCONTINUE;                                      BEGIN S_ANSCONTINUE; 
                                }                                 }
                                return(yytext[0]);                                  send("\">\n\t");
          dosend=1;
          flush_delayed();
          if (firstparam!=1) send("\" />\n");
          send("\t<textline />\n");
                            /* Fill in Hints */ 
          if ( !is_dest_empty(HINT_DEST) ) {
            send("<hintgroup>\n\t<hintpart on=\"default\">\n\t<startouttext />");
                                    end_streams(HINT_DEST,0);
                                    HINTflag=0;
                                    send("\t<endouttext />\n\t</hintpart>\n</hintgroup>\n");
          }
          send("\n</numericalresponse>\n");
   
          if ( !is_dest_empty(EXP_DEST) ) {
            send("<postanswerdate>\n\t<startouttext />\n");
                                    end_streams(EXP_DEST,0);
                                    EXPflag=0;
                                    send("\t<endouttext />\n</postanswerdate>\n");
                                  }
                              }                               }
 }  }
   
 <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_ANSWER,S_MAP>{  <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP,S_ANSWER>{
 {Alpha}{AlphaNum}*             { LLDBUG_PR2("[ID<%s>]",yytext);LLDBUG_PR2("[SYMB CNT=<%d>]", Symb_count);   {Alpha}{AlphaNum}*             { LLDBUG_PR2("[ID<%s>]",yytext);
                                  /*yylval = find_identifier(yytext);*/ RETURN(IDENTIFIER);                                    LLDBUG_PR2("[SYMB CNT=<%d>]", Symb_count); 
                                    if (dosend==1) send("$%s",yytext); 
                                    if (dosend==2) add_delayed("$%s",yytext); 
                                }                                 }
   
 {Alpha}{AlphaNum}*{Space}*[(]  { char aline[MAX_FUNC_NAME];  {Alpha}{AlphaNum}*{Space}*[(]  { if (dosend==1) send("&%s",yytext);
                                  int  i;                                             if (dosend==2) add_delayed("&%s",yytext);
                                    for(i=0;i < (yyleng-1); i++) {   Pcount++;
                                      if( yytext[i] == ' ' || yytext[i] == '\t' ||   
                                          yytext[i] == 0   || yytext[i] == '(' )    break;  
                                      aline[i] = yytext[i];  
                                    }  
                                    aline[i] = 0;  
                                    LLDBUG_PR3("[FUNCT<%s:%d>]",aline,Func_idx);  
                             (FuncStack[Func_idx]).s_type = FUNCTION_ID;  
     (FuncStack[Func_idx]).s_name = strsave(aline); /* free it in parser() */  
    Func_idx++;  
    yyless(yyleng-1); /* <-- push back '(' char  */  
    RETURN(FUNCTION_ID);   
                                }                                 }
 {Alpha}{AlphaNum}*{Space}*[\[]  {  char aline[MAX_FUNC_NAME];  {Alpha}{AlphaNum}*{Space}*[\[]  {  char aline[MAX_FUNC_NAME];
                                    int  i;                                        int  i;   
Line 779  EndLine    ([\r][\n]|[\n]) Line 897  EndLine    ([\r][\n]|[\n])
 {Number}+[Ee]{Number}+    |  {Number}+[Ee]{Number}+    |
 {Number}+[Ee]"-"{Number}+ |  {Number}+[Ee]"-"{Number}+ |
 {Number}+"\."{Number}*    |  {Number}+"\."{Number}*    |
 "\."{Number}+             {  yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */  "\."{Number}+             {  LLDBUG_PR2("[REAL<%s>]",yytext);
                              yylval->s_real = strtod(yytext, (char **) 0);       if(dosend==1) send("%s",yytext);
                              yylval->s_type = R_CONSTANT;       if(dosend==2) add_delayed("%s",yytext);
                              LLDBUG_PR2("[REAL<%s>]",yytext);  
                              RETURN(R_CONSTANT);  
   }    }
   
 {Number}+                 {  yylval = (Symbol *) capa_malloc(1, sizeof(Symbol)); /* *** */  {Number}+                 {  LLDBUG_PR2("[INT<%s>]",yytext);
                              yylval->s_int = strtol(yytext, (char **) 0, 0);                               if (dosend==1) send("%s",yytext);
                              yylval->s_type= I_CONSTANT;                               if (dosend==2) add_delayed("%s",yytext);
                              LLDBUG_PR2("[INT<%s>]",yytext);  
                              RETURN(I_CONSTANT);  
   }    }
 [\(]                      { LLDBUG_PR1("[dis let ans map (]"); Pcount++; return(yytext[0]); }  
 [\[]                      { LLDBUG_PR1("[dis let ans map '[']");         return(yytext[0]); }  [\[]                      { LLDBUG_PR1("[dis let ans map '[']");         return(yytext[0]); }
 [\]]                      { LLDBUG_PR1("[dis let ans map ']']");         return(yytext[0]); }  [\]]                      { LLDBUG_PR1("[dis let ans map ']']");         return(yytext[0]); }
 {Space}+                  { /* LLDBUG_PR1("[SP ignored]");  Ignore Spaces */ }  {Space}+                  { /* LLDBUG_PR1("[SP ignored]");  Ignore Spaces */ }
 [\"]                      { LLDBUG_PR1("[TF,V,LET,ANS,MAP str\" ]");   }
   
   <S_VARIABLE,S_TRUE_FALSE_STMT,S_MAP,S_LET>{
   [\"]                      { LLDBUG_PR1("[TF,V,LET,MAP str\" ]"); 
                             Current_char_p = String_buf;                               Current_char_p = String_buf; 
                             yy_push_state(S_STRING);       send("'");
                               yy_push_state(S_STRING);
                           }                            }
 }  }
   
 <S_VARIABLE,S_ANSWER>[:]{Number}+[EeFf]   { char  num[ONE_TWO_EIGHT], fmt[SMALL_LINE_BUFFER];  <S_ANSWER>{
                              int   i;  [\"]                      { LLDBUG_PR1("[ANS str\" ]"); 
                              LLDBUG_PR2("[FORMAT<%s>]",yytext);                              Current_char_p = String_buf; 
                              for(i=0;i<yyleng-2;i++) {                              yy_push_state(S_STRINGINANS);
                                num[i] = yytext[i+1];                            }
                              }  }
                              num[yyleng-2] = 0; /* terminate the numerical string */  
                              yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));  <S_VARIABLE,S_TRUE_FALSE_STMT,S_MAP,S_ANSWER>{
                              i = strtol(num, (char **) 0, 0);  [\(]                      { LLDBUG_PR1("[let if ans map (]"); 
                              yylval->s_type=FORMAT;                              Pcount++; 
                              switch( yytext[yyleng-1] ) {      if (Pcount > 1 ) {
                                case 'e': sprintf(fmt,"%%.%de", i);        if (dosend==1) send(yytext);
                                          yylval->s_distype = E_FORMAT; break;        if (dosend==2) add_delayed(yytext);
                                case 'E': sprintf(fmt,"%%.%dE", i);      } 
                                          yylval->s_distype = E_FORMAT; break;                            }
                                case 'f':   }
                                case 'F': sprintf(fmt,"%%.%df", i);  
                                          yylval->s_distype = F_FORMAT; break;  <S_LET>{
                              }  [\(]                      { LLDBUG_PR1("[let (]"); 
                              yylval->s_str = strsave(fmt);                              Pcount++; 
                              RETURN(FORMAT);      send(yytext);
                             }
   }
   
   <S_VARIABLE>[:]{Number}+[EeFf]   { 
                                end_delayed();
                                send("&format(");
                                flush_delayed();
                                send(",'%s')",yytext+1);
                            }                             }
   <S_ANSWER>[:]{Number}+[EeFf]   { 
                                if (dosend) send("\" format=\"%s",yytext+1);
                              }
   
   <S_MAP>{
   [;]   { 
           if (sccount==0) {
             send(",[\\");
             sccount++;
           } else if (sccount==1) {
             send("],[");
             sccount++;
           }
          }
   [,]     {
           if (sccount==1) {
             send(",\\");
           } else {
             send(",");
           }
         }
   [\)]  {
           LLDBUG_PR1("[) in MAP]"); Pcount--; 
           if(Pcount==0) {
             BEGIN S_SKIP; 
           }
           /* you might need a ; in the string below */
           send("]%c;\n",yytext[0]);
           sccount=0;
         }
   }
   
 <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP>{  <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP>{
 "=="                { LLDBUG_PR1("[==]"); RETURN(EQ_op);  }  "=="                { LLDBUG_PR1("[==]"); send(yytext);  }
 "!="                { LLDBUG_PR1("[!=]"); RETURN(NE_op);  }  "!="                { LLDBUG_PR1("[!=]"); send(yytext);  }
 ">"                 { LLDBUG_PR1("[>]");  RETURN(GT_op);  }  ">"                 { LLDBUG_PR1("[>]");  send(yytext);  }
 ">="                { LLDBUG_PR1("[>=]"); RETURN(GE_op);  }  ">="                { LLDBUG_PR1("[>=]"); send(yytext);  }
 "<"                 { LLDBUG_PR1("[<]");  RETURN(LT_op);  }  "<"                 { LLDBUG_PR1("[<]");  send(yytext);  }
 "<="                { LLDBUG_PR1("[<=]"); RETURN(LE_op);  }  "<="                { LLDBUG_PR1("[<=]"); send(yytext);  }
 "&&"                { LLDBUG_PR1("[&&]"); RETURN(AND_op); }  "&&"                { LLDBUG_PR1("[&&]"); send(yytext);  }
 "||"                { LLDBUG_PR1("[||]"); RETURN(OR_op);  }  "||"                { LLDBUG_PR1("[||]"); send(yytext);  }
 "//"                { if(Pcount==0) BEGIN S_SKIP;         }  "//"                { if(Pcount==0) {
 {Operator}          { LLDBUG_PR2("[Op(%c) in VAR,TF_STMT,LET]",yytext[0]); return(yytext[0]); }   send("; #");
    BEGIN S_ECHO;
                         }
                       }
   [%]                 {send("%%");}
   {Operator}          { LLDBUG_PR2("[Op(%c) in VAR,TF_STMT,LET]",yytext[0]); send(yytext); }
 }  }
   
   
   
 <S_VARIABLE>{  <S_VARIABLE>{
 [\)]                     { LLDBUG_PR1("[)]"); Pcount--; if(Pcount == 0)  BEGIN S_TEXT; return(yytext[0]); }  [\)]                     { LLDBUG_PR1("[)]"); 
                              Pcount--; 
                              if(Pcount == 0) {
                                 BEGIN S_TEXT; 
                                 flush_delayed();
                              } else {
                                 send(yytext); 
                              }
                            }
 [\\]{Space}*{EndLine}    { LLDBUG_PR2("[\\EoL continue in S_VARIABLE (DIS?)](%s)",yytext); /* continuation on next line */ }                         [\\]{Space}*{EndLine}    { LLDBUG_PR2("[\\EoL continue in S_VARIABLE (DIS?)](%s)",yytext); /* continuation on next line */ }                       
 {EndLine}                { LLDBUG_PR1("[EoL within /dis()]\n"); RETURN(EoL); }  {EndLine}                { LLDBUG_PR1("[EoL within /dis()]\n"); }
 .                   { char warn_msg[WARN_MSG_LENGTH];   .                   { char warn_msg[WARN_MSG_LENGTH]; 
                       sprintf(warn_msg,"When use a VARIABLE, an unexpected char [%c] is encountered.\n",yytext[0]);                        sprintf(warn_msg,"When use a VARIABLE, an unexpected char [%c] is encountered.\n",yytext[0]);
                       capa_msg(MESSAGE_ERROR,warn_msg);                        capa_msg(MESSAGE_ERROR,warn_msg);
Line 851  EndLine    ([\r][\n]|[\n]) Line 1020  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;
      }
    }
   [\\]{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);
                     }                      }
 }  }
   
 <S_STRING>{  <S_STRING>{
 [\\][\\]            { char  *aptr = yytext;  [\\][\\]            { /*char  *aptr = yytext;
                       while( *aptr )   *Current_char_p++ = *aptr++;   while( *aptr )   *Current_char_p++ = *aptr++;*/
                         send(yytext);
                       }
   [\\][\"]            { /**Current_char_p++ = '"';*/ send("\\\"");  }
   [\\]{Space}*[\n]    { LLDBUG_PR2("[\\CR continue in S_STRING](%s)",yytext); /* continuation on next line */ }                       
   [\"]                { /* end of a string constant --   */
                         send("'");
         yy_pop_state();
       }
   [%]                 { /*Escape percent signs so that vasprintf doesn't choke */
                         send("%%");
                       }
   {EndLine}           { /* check for termination of string constant */
                         char warn_msg[WARN_MSG_LENGTH];
                         
                         sprintf(warn_msg,"STRING not terminated properly, an EoL encountered in the middle.\n%s\n",String_buf);
                         capa_msg(MESSAGE_ERROR,warn_msg);
                         yy_pop_state();
                       }
   .                   { /*char  *aptr = yytext;
    while( *aptr )   *Current_char_p++ = *aptr++;*/
                         send(yytext);
                       }
   }
   
   <S_STRINGINANS>{
   [\\][\\]            { /*char  *aptr = yytext;
    while( *aptr )   *Current_char_p++ = *aptr++;*/
                         if (dosend==1) send("%s",yytext);
         if (dosend==2) add_delayed("%s",yytext);
                       }
   [\\][\"]            { /**Current_char_p++ = '"';*/ 
                         if (dosend==1) send("%s",yytext);
         if (dosend==2) add_delayed("%s",yytext);
                     }                      }
 [\\][\"]            { *Current_char_p++ = '"';  }  
 [\\]{Space}*[\n]    { LLDBUG_PR2("[\\CR continue in S_STRING](%s)",yytext); /* continuation on next line */ }                         [\\]{Space}*[\n]    { LLDBUG_PR2("[\\CR continue in S_STRING](%s)",yytext); /* continuation on next line */ }                       
 [\"]                { /* end of a string constant --   */  [\"]                { /* end of a string constant --   */
                       yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));  
       *Current_char_p = '\0';  
               yylval->s_str = strsave(String_buf);  /* ****   */  
       yylval->s_type = S_CONSTANT;  
       /* printf("STRING:%s\n", String_buf); */  
       LLDBUG_PR2("[%s\"END str]",String_buf);  
       yy_pop_state();        yy_pop_state();
       RETURN(S_CONSTANT); }      }
 {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];
                                               
                       *Current_char_p = '\0';  
                       sprintf(warn_msg,"STRING not terminated properly, an EoL encountered in the middle.\n%s\n",String_buf);                        sprintf(warn_msg,"STRING not terminated properly, an EoL encountered in the middle.\n%s\n",String_buf);
                       capa_msg(MESSAGE_ERROR,warn_msg);                        capa_msg(MESSAGE_ERROR,warn_msg);
                       yy_pop_state();                        yy_pop_state();
                     }                      }
 .                   { char  *aptr = yytext;  .                   { /*char  *aptr = yytext;
                       while( *aptr )   *Current_char_p++ = *aptr++;   while( *aptr )   *Current_char_p++ = *aptr++;*/
                         if (dosend==1) send("%s",yytext);
         if (dosend==2) add_delayed("%s",yytext);
                     }                      }
 }  }
   
 <S_LET>[\)]                  { LLDBUG_PR1("[) in LET]"); Pcount--; return(yytext[0]); }  <S_LET>[\)]                  { LLDBUG_PR1("[) in LET]"); Pcount--;send(yytext); }
   
 <S_SKIP>{  <S_SKIP>{
 [^\n]+$                      {       }  [^\n]+$                      {       }
 {EndLine}                    { BEGIN S_TEXT; RETURN(EoL);  }  {EndLine}                    { BEGIN S_TEXT; }
 }  }
   
 <S_LET,S_ANSWER,S_MAP>{  <S_ECHO>{
 [\\]{Space}*{EndLine}        { LLDBUG_PR1("[\\EoL let ans map]"); /* continuation */ }  [^\n]+$                      { send(yytext); }
 {EndLine}                    { LLDBUG_PR1("[EoL END let ans map]\n"); if(Pcount == 0) BEGIN S_TEXT; RETURN(EoL); }  {EndLine}                    { send(yytext); BEGIN S_TEXT; }
 }  }
   
 <S_MAP>{  <S_LET,S_ANSWER,S_MAP>{
 [;,]                         { LLDBUG_PR2("[%c]",yytext[0]); return(yytext[0]);  }  [\\]{Space}*{EndLine}        { LLDBUG_PR1("[\\EoL let ans map]"); /* continuation */ }
 [\)]                         { LLDBUG_PR1("[) in MAP]"); Pcount--;   {EndLine}                    { LLDBUG_PR1("[EoL END let ans map]\n"); 
                                if(Pcount==0) {                                 if(Pcount == 0) BEGIN S_TEXT; 
                                    BEGIN S_SKIP;                                  send(";%s",yytext); 
                                }  
                                return(yytext[0]);   
                              }                               }
 }  }
   
Line 915  EndLine    ([\r][\n]|[\n]) Line 1123  EndLine    ([\r][\n]|[\n])
 [\\]{Space}*{EndLine}    { /* continuation */ }  [\\]{Space}*{EndLine}    { /* continuation */ }
 {EndLine}                { /* end of answer and/or other answers */ LLDBUG_PR1("[complete an answer<EoL>]");   {EndLine}                { /* end of answer and/or other answers */ LLDBUG_PR1("[complete an answer<EoL>]"); 
                            BEGIN S_TEXT; }                             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);  }  "/OR"                    { LLDBUG_PR1("[OR]");  RETURN(ANS_OR);  }
 }  }
   
 <S_IF_SKIP>{  
 ^{Spaces}"/IF"[^\n]*{EndLine}    { IFcount++; LLDBUG_PRL2("[Skip IF <IFcount=%d>]\n",IFcount);   
                                    IFstatus[IFcount] = IF_DONT_CARE;  
                                  }  
 ^{Spaces}"/ELSE"[^\n]*{EndLine}  {  LLDBUG_PRL2("[Skip ELSE <IFcount=%d>]",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 <IFcount=%d>]\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=%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 976  EndLine    ([\r][\n]|[\n]) Line 1153  EndLine    ([\r][\n]|[\n])
   
 <S_VERB>{  <S_VERB>{
 ^{Spaces}"/ENDVERB" { LLDBUG_PRL1("[END VERB]\n");   ^{Spaces}"/ENDVERB" { LLDBUG_PRL1("[END VERB]\n"); 
                       yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));        BEGIN S_TEXT;
       yylval->s_str = strsave(Dynamic_buf);  /* ****   */        puts("\n</PRE>\n");
       yylval->s_type = S_CONSTANT;          end_mode();
       capa_mfree(Dynamic_buf);  
       Dynamic_buf_cur=-1;  
       Dynamic_buf_max=0;  
       BEGIN S_TEXT;   RETURN(VERBATIM);     
     }      }
 .*|{EndLine}         { append_dynamic_buf(yytext); }  .*|{EndLine}         { send(yytext); }
 }  }
   
 %%  %%
   
 /* ========================================================================================== */  /* ========================================================================================== */
 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; }
Line 1596  int capa_eof() Line 1767  int capa_eof()
     LexiProblem_p=NULL;      LexiProblem_p=NULL;
     /* printf("\nCAPA EOF\n"); fflush(stdout); */      /* printf("\nCAPA EOF\n"); fflush(stdout); */
   }    }
     end_mode();
   return (0);    return (0);
 #endif /*AVOIDYYINPUT*/  #endif /*AVOIDYYINPUT*/
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.16


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>