Diff for /loncom/homework/CAPA-converter/capaLexerDef.flex between versions 1.2 and 1.3

version 1.2, 2000/05/03 15:35:11 version 1.3, 2000/05/15 20:33:33
Line 140  extern        Problem_t         *LexiPro Line 140  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;
 int           scriptopen=0;  
 #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 337  void newyy_input (char *buf,int *result, Line 336  void newyy_input (char *buf,int *result,
 #endif  #endif
   
 int capa_eof();  int capa_eof();
   
 %}  %}
   
 Alpha      [a-zA-Z_]  Alpha      [a-zA-Z_]
Line 379  EndLine    ([\r][\n]|[\n]) Line 379  EndLine    ([\r][\n]|[\n])
 }  }
   
 <S_COMMENT>{  <S_COMMENT>{
 {EndLine}{Spaces}"//"[^\n]*$ {LLDBUG_PRL2("[COMMENT<%s>]\n",yytext);  {EndLine}{Spaces}"//"[^\n]*$ {LLDBUG_PRL2("[COMMENT<%s>]\n",yytext); 
                               remove_delayed();   
       send("%s",yytext);        send("%s",yytext);
       send_delayed("\n</comment>\n");  
                              }                               }
 [^\n]*{EndLine}      BEGIN S_TEXT;  [^\n]*{EndLine}      {
                          send("\n"); BEGIN S_TEXT;
                        }
 }  }
   
   
 <S_TEXT>{  <S_TEXT>{
 ^{Spaces}"/LET" |  ^{Spaces}"/LET" |
    ^{Spaces}"/BEG"                  { LLDBUG_PRL1("[LET]"); Pcount = 0; BEGIN S_LET; if (!scriptopen){send("<script>\n");scriptopen=1;}     ^{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]");
Line 401  EndLine    ([\r][\n]|[\n]) Line 401  EndLine    ([\r][\n]|[\n])
                                    BEGIN S_VERB;                                      BEGIN S_VERB; 
                                  }                                   }
 ^{Spaces}"/HIN"{Alpha}*{Spaces}  { LLDBUG_PRL1("[HIN]");   ^{Spaces}"/HIN"{Alpha}*{Spaces}  { LLDBUG_PRL1("[HIN]"); 
                                    send("<block condition=\"&hinton\">\n");                                     start_mode(MODE_BLOCK,
         "condition=\"&hinton\"");
    BEGIN S_HINT;      BEGIN S_HINT; 
                                  }                                   }
 ^{Spaces}"/EXP"{Alpha}*{Spaces}  { LLDBUG_PRL1("[EXP]"); Current_char_p = String_buf;  BEGIN S_EXPLAIN; }  ^{Spaces}"/EXP"{Alpha}*{Spaces}  { start_mode(MODE_BLOCK,"condition=&explanation");
                                      LLDBUG_PRL1("[EXP]"); Current_char_p = String_buf;  BEGIN S_EXPLAIN; }
 ^{Spaces}"/IMP"{Alpha}*{Space}+  { LLDBUG_PRL1("[IMP]"); BEGIN S_IMPORT; }  ^{Spaces}"/IMP"{Alpha}*{Space}+  { LLDBUG_PRL1("[IMP]"); BEGIN S_IMPORT; }
 ^{Spaces}"/END"                  { LLDBUG_PRL1("[END]");    ^{Spaces}"/END"                  { LLDBUG_PRL1("[END]");  
                                     if ( (LexiProblem_p !=NULL) &&                                       if ( (LexiProblem_p !=NULL) && 
Line 486  EndLine    ([\r][\n]|[\n]) Line 488  EndLine    ([\r][\n]|[\n])
                                 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]*$      { LLDBUG_PRL2("[COMMENT<%s>]\n",yytext);  ^{Spaces}"//"[^\n]*$      { LLDBUG_PRL2("[COMMENT<%s>]\n",yytext);
                                         remove_delayed();                                           start_mode(MODE_COMMENT,NULL); 
                                         send("<comment>\n%s\n",yytext);                                          send("%s\n",yytext);
  send_delayed("</comment>\n");  
  BEGIN S_COMMENT;   BEGIN S_COMMENT;
                                       }                                        }
   
 [^/\n\\]+$  |  [^/\n\\]+$  |
 [/]         |   [/]         | 
 [\\]                          {  yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));  [\\]                          {  start_mode(MODE_OUTTEXT,NULL);
                                    yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));
                                 yylval->s_str = strsave(yytext);                                  yylval->s_str = strsave(yytext);
                                 LLDBUG_PR2("[TEXT_LINE<%s>]",yytext);                                  LLDBUG_PR2("[TEXT_LINE<%s>]",yytext);
         //RETURN(TEXT_LINE);           //RETURN(TEXT_LINE); 
       }        }
 ([^/\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 */
Line 531  EndLine    ([\r][\n]|[\n]) Line 534  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 629  EndLine    ([\r][\n]|[\n]) Line 632  EndLine    ([\r][\n]|[\n])
 }  }
 <S_HINT>{  <S_HINT>{
 {EndLine}                     {  LLDBUG_PR1("[CR hint]");  {EndLine}                     {  LLDBUG_PR1("[CR hint]");
                                  send("\n</block>\n");                                    send("\n"); 
                                  BEGIN S_TEXT;                                   BEGIN S_TEXT;
                               }                                }
 }  }
Line 686  EndLine    ([\r][\n]|[\n]) Line 689  EndLine    ([\r][\n]|[\n])
 }  }
   
 <S_IMPORT>{  <S_IMPORT>{
 {FileName}{Space}*             { send("<import>%s</import>\n",yytext); BEGIN S_SKIP; }  {FileName}{Space}*             { end_mode();send("<import>%s</import>\n",yytext); BEGIN S_SKIP; }
 {Identifier}{Space}*           { send("<import>$%s</import>\n",yytext);  BEGIN S_SKIP; }  {Identifier}{Space}*           { end_mode();send("<import>$%s</import>\n",yytext);  BEGIN S_SKIP; }
 }  }
   
 <S_ANSWER>{  <S_ANSWER>{
Line 777  send("$%s",yytext); Line 780  send("$%s",yytext);
                              LLDBUG_PR2("[INT<%s>]",yytext);                               LLDBUG_PR2("[INT<%s>]",yytext);
                              send(yytext);                               send(yytext);
   }    }
 [\(]                      { LLDBUG_PR1("[dis let ans map (]"); Pcount++; send(yytext); }  [\(]                      { LLDBUG_PR1("[dis let ans map (]"); Pcount++; if (Pcount > 1 ) {send(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 ']']");         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\" ]");   [\"]                      { LLDBUG_PR1("[TF,V,LET,ANS,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_VARIABLE,S_ANSWER>[:]{Number}+[EeFf]   { 
                              int   i;                               end_delayed();
                              LLDBUG_PR2("[FORMAT<%s>]",yytext);                               send("&format(");
                              for(i=0;i<yyleng-2;i++) {                               flush_delayed();
                                num[i] = yytext[i+1];                               send(",\"%s\")",yytext+1);
                              }  
                              num[yyleng-2] = 0; /* terminate the numerical string */  
                              yylval = (Symbol *) capa_malloc(1, sizeof(Symbol));  
                              i = strtol(num, (char **) 0, 0);  
                              yylval->s_type=FORMAT;  
                              switch( yytext[yyleng-1] ) {  
                                case 'e': sprintf(fmt,"%%.%de", i);  
                                          yylval->s_distype = E_FORMAT; break;  
                                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;  
                              }  
                              yylval->s_str = strsave(fmt);  
                              RETURN(FORMAT);  
                            }                             }
   
 <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP>{  <S_VARIABLE,S_TRUE_FALSE_STMT,S_LET,S_MAP>{
Line 826  send("$%s",yytext); Line 814  send("$%s",yytext);
   
   
 <S_VARIABLE>{  <S_VARIABLE>{
 [\)]                     { LLDBUG_PR1("[)]"); Pcount--; if(Pcount == 0)  BEGIN S_TEXT; send(yytext); }  [\)]                     { 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 846  send("$%s",yytext); Line 842  send("$%s",yytext);
 }  }
   
 <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++ = '"';  }  [\\][\"]            { /**Current_char_p++ = '"';*/ send("\\\"");  }
 [\\]{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));                        send("\"");
       *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++;*/
                         send(yytext);
                     }                      }
 }  }
   
Line 882  send("$%s",yytext); Line 874  send("$%s",yytext);
   
 <S_LET,S_ANSWER,S_MAP>{  <S_LET,S_ANSWER,S_MAP>{
 [\\]{Space}*{EndLine}        { LLDBUG_PR1("[\\EoL let ans map]"); /* continuation */ }  [\\]{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(yytext); send_delayed("</script>"); }  {EndLine}                    { LLDBUG_PR1("[EoL END let ans map]\n"); if(Pcount == 0) BEGIN S_TEXT; send(yytext); }
 }  }
   
 <S_MAP>{  <S_MAP>{

Removed from v.1.2  
changed lines
  Added in v.1.3


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