Diff for /capa/capa51/pProj/capaGrammarDef.y between versions 1.3 and 1.16

version 1.3, 1999/10/13 20:05:00 version 1.16, 2000/09/20 17:21:01
Line 1 Line 1
   /* main CAPA parser
      Copyright (C) 1992-2000 Michigan State University
   
      The CAPA system 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.
   
      The CAPA system 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 the CAPA system; see the file COPYING.  If not,
      write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      Boston, MA 02111-1307, USA.
   
      As a special exception, you have permission to link this program
      with the TtH/TtM library and distribute executables, as long as you
      follow the requirements of the GNU GPL in regard to all of the
      software in the executable aside from TtH/TtM.
   */
   
 /* ========================================================================== */  /* ========================================================================== */
 /*            capaGrammarDef.y    created by Isaac Tsai                       */  /*            capaGrammarDef.y    created by Isaac Tsai                       */
 /*                                1998, 1999 copyrighted by Isaac Tsai        */  /*                                1998, 1999 by Isaac Tsai        */
 /* no longer there is a length constrain on string concatenation July 13 1998 */  /* no longer there is a length constrain on string concatenation July 13 1998 */
 /* /RMAP() function */  /* /RMAP() function */
 /* TODO: new mechanism to collect answer informations */  /* TODO: new mechanism to collect answer informations */
Line 36 Line 60
                                      case S_VAR:  case S_CONSTANT: \                                       case S_VAR:  case S_CONSTANT: \
                                               printf("STR(%s)\n",(xx)->s_str); break; \                                                printf("STR(%s)\n",(xx)->s_str); break; \
                                } }                                 } }
 #else  #else  /* YACC_DBUG */
 #define  YYDBUG_PR1(xx)        { }  #define  YYDBUG_PR1(xx)        { }
 #define  YYDBUG_PR2(xx,yy)     { }  #define  YYDBUG_PR2(xx,yy)     { }
 #define  YYDBUG_PR3(xx,yy,zz)  { }  #define  YYDBUG_PR3(xx,yy,zz)  { }
 #define  YYDBUG_PR4(xx,yy,zz,aa)  { }  #define  YYDBUG_PR4(xx,yy,zz,aa)  { }
 #define  YYDBUG_SYM(xx)        { }  #define  YYDBUG_SYM(xx)        { }
 #endif  #endif /* YACC_DBUG */
   
 int   yylex();  int   yylex();
 void  yyerror(char*);  void  yyerror(char*);
 void  free_calc_expr(Symbol*);  void  free_calc_expr(Symbol*);
   void assign_pts (Symbol *, Symbol *, Symbol *);
 /******************************************************************************/  /******************************************************************************/
 /* GLOBAL VARIABLES                                                           */  /* GLOBAL VARIABLES                                                           */
 /******************************************************************************/  /******************************************************************************/
Line 117  PointsList_t      *LastPtsList; Line 142  PointsList_t      *LastPtsList;
 %token       ANS_OFF         ANS_ON          ANS_OR          ANS_ORDERED  %token       ANS_OFF         ANS_ON          ANS_OR          ANS_ORDERED
 %token       ANS_PATH        ANS_PCREDIT     ANS_PLUS        ANS_RANGE         %token       ANS_PATH        ANS_PCREDIT     ANS_PLUS        ANS_RANGE       
 %token       ANS_SHOW_BR     ANS_SIG         ANS_TOLERANCE   ANS_TRY         ANS_TYPE  %token       ANS_SHOW_BR     ANS_SIG         ANS_TOLERANCE   ANS_TRY         ANS_TYPE
 %token       ANS_UNFMT       ANS_UNIT        ANS_WEIGHT   %token       ANS_UNFMT       ANS_UNIT        ANS_VERBATIM    ANS_WEIGHT 
 %token       VAR_RANGE       VERBATIM  %token       VAR_RANGE       VERBATIM
 %token       SLASH           FORMAT  %token       SLASH           FORMAT
 %token       EQ_op  NE_op  GT_op  GE_op  LT_op  LE_op  AND_op  OR_op   EoL      %token       EQ_op  NE_op  GT_op  GE_op  LT_op  LE_op  AND_op  OR_op   EoL    
Line 225  statement    :  IDENTIFIER '=' calc_expr Line 250  statement    :  IDENTIFIER '=' calc_expr
                                              case IDENTIFIER:                                               case IDENTIFIER:
                                              case I_VAR: case I_CONSTANT:                                               case I_VAR: case I_CONSTANT:
                                              case R_VAR: case R_CONSTANT: break;                                               case R_VAR: case R_CONSTANT: break;
                                              case S_VAR: case S_CONSTANT:                                                case S_VAR: case S_CONSTANT: /* free up original used spaces */
                                                     capa_mfree($1->s_str); $1->s_str = NULL; break;                                                      capa_mfree($1->s_str); $1->s_str = NULL; break;
                                              default:    break;                                               default:    break;
                                           }                                            }
Line 287  statement    :  IDENTIFIER '=' calc_expr Line 312  statement    :  IDENTIFIER '=' calc_expr
              ;               ;
   
 rqo_def      :  rqo_speca             { rqo_1spec(); }  rqo_def      :  rqo_speca             { rqo_1spec(); }
              |  rqo_speca "," rqo_def { rqo_2spec(); }               |  rqo_speca ',' rqo_def { rqo_2spec(); }
              ;               ;
   
 rqo_speca    : an_integer                 {start_rqo_type(SINGLE);append_rqo($1);}  rqo_speca    : an_integer                 {start_rqo_type(SINGLE);append_rqo($1);}
              | an_integer "!"             {start_rqo_type(IMMOBILE);append_rqo($1);}               | an_integer '!'             {start_rqo_type(IMMOBILE);append_rqo($1);}
              | an_integer "-" an_integer  {start_rqo_type(RANGE);append_rqo($1);               | an_integer '-' an_integer  {start_rqo_type(RANGE);append_rqo($1);
                                            append_rqo($3);                                             append_rqo($3);
                                           }                                            }
              | an_integer "~" rqo_specb   {prefix_rqo($1);}               | an_integer '~' rqo_specb   {prefix_rqo($1);}
              | an_integer "+" rqo_specc   {prefix_rqo($1);}               | an_integer '+' rqo_specc   {prefix_rqo($1);}
              ;               ;
   
 rqo_specb    : an_integer                 {start_rqo_type(ALL_MIX);append_rqo($1);}  rqo_specb    : an_integer                 {start_rqo_type(ALL_MIX);append_rqo($1);}
              | an_integer "~" rqo_specb   {prefix_rqo($1);}               | an_integer '~' rqo_specb   {prefix_rqo($1);}
              | an_integer "+" an_integer  {start_rqo_type(LAST_FIXED);append_rqo($1);               | an_integer '+' an_integer  {start_rqo_type(LAST_FIXED);append_rqo($1);
                                            append_rqo($3);}                                             append_rqo($3);}
              ;               ;
   
 rqo_specc    : an_integer                 {start_rqo_type(ALL_FIXED);append_rqo($1);}  rqo_specc    : an_integer                 {start_rqo_type(ALL_FIXED);append_rqo($1);}
              | an_integer "+" rqo_specd   {prefix_rqo($1);}               | an_integer '+' rqo_specd   {prefix_rqo($1);}
              | an_integer "~" rqo_spece   {prefix_rqo($1);}               | an_integer '~' rqo_spece   {prefix_rqo($1);}
              ;               ;
   
 rqo_specd    : an_integer                 {start_rqo_type(ALL_FIXED);append_rqo($1);}  rqo_specd    : an_integer                 {start_rqo_type(ALL_FIXED);append_rqo($1);}
              | an_integer "+" rqo_specd   {prefix_rqo($1);}               | an_integer '+' rqo_specd   {prefix_rqo($1);}
              ;               ;
   
 rqo_spece    : an_integer                 {start_rqo_type(FIRST_FIXED);append_rqo($1);}  rqo_spece    : an_integer                 {start_rqo_type(FIRST_FIXED);append_rqo($1);}
              | an_integer "~" rqo_spece   {prefix_rqo($1);}               | an_integer '~' rqo_spece   {prefix_rqo($1);}
              | an_integer "+" an_integer  {start_rqo_type(BOTH_FIXED);append_rqo($1);               | an_integer '+' an_integer  {start_rqo_type(BOTH_FIXED);append_rqo($1);
                                            append_rqo($3);}                                             append_rqo($3);}
              ;               ;
   
Line 332  q_text       :  TEXT_LINE Line 357  q_text       :  TEXT_LINE
              ;               ;
                             
 if_expr      :  CAPA_IF '(' calc_expr  ')'  if_expr      :  CAPA_IF '(' calc_expr  ')'
                                         { int leng; /* begin_next_line(); no use, can be get rid of */                                          { int leng=0; /* begin_next_line(); no use, can be get rid of */
                                           YYDBUG_PR2("(IF expr <IFcount=%d>)\n",IFcount);                                            YYDBUG_PR2("(IF expr <IFcount=%d>)\n",IFcount);
                                           switch($3->s_type) {                                            switch($3->s_type) {
                                             case IDENTIFIER:                                               case IDENTIFIER: 
Line 358  if_expr      :  CAPA_IF '(' calc_expr  ' Line 383  if_expr      :  CAPA_IF '(' calc_expr  '
                                                    }                                                     }
                                                    break;                                                     break;
                                             case S_CONSTANT:                                               case S_CONSTANT: 
                                                    leng = strlen($3->s_str);             if ( $3->s_str) {
                                                    capa_mfree($3->s_str);        leng = strlen($3->s_str);
                                                         capa_mfree($3->s_str);
                                                      } 
                                                    if(leng == 0) {                                                     if(leng == 0) {
                                                       IFstatus[IFcount] = IF_FALSE;                                                        IFstatus[IFcount] = IF_FALSE;
                                                       begin_if_skip();                                                        begin_if_skip();
Line 369  if_expr      :  CAPA_IF '(' calc_expr  ' Line 396  if_expr      :  CAPA_IF '(' calc_expr  '
                                                    }                                                     }
                                                    break;                                                     break;
                                             case S_VAR:                                              case S_VAR:
                                                    leng = strlen($3->s_str);             if ( $3->s_str) {
                                                    if(leng == 0) {        leng = strlen($3->s_str);
                                                         capa_mfree($3->s_str);
                                                      }
      if(leng == 0) {
                                                       IFstatus[IFcount] = IF_FALSE;                                                        IFstatus[IFcount] = IF_FALSE;
                                                       begin_if_skip();                                                        begin_if_skip();
                                                    }else{                                                     }else{
Line 500  ans_infospec : ANS_TOLERANCE '=' a_numbe Line 530  ans_infospec : ANS_TOLERANCE '=' a_numbe
                                }                                 }
      | ANS_SHOW_BR '=' ANS_OFF {  LexiProblem_p->show_br = DONOT_SHOW;       | ANS_SHOW_BR '=' ANS_OFF {  LexiProblem_p->show_br = DONOT_SHOW;
                                }                                 }
        | ANS_VERBATIM '=' ANS_ON  {  LexiProblem_p->verbatim = DO_VERBATIM;
                                   }
        | ANS_VERBATIM '=' ANS_OFF {  LexiProblem_p->verbatim = DONOT_VERBATIM;
                                   }
      | ANS_BOX_SHOW '=' ANS_ON {  LexiProblem_p->show_ans_box  = DO_SHOW;       | ANS_BOX_SHOW '=' ANS_ON {  LexiProblem_p->show_ans_box  = DO_SHOW;
                                }                                 }
      | ANS_BOX_SHOW '=' ANS_OFF {  LexiProblem_p->show_ans_box = DONOT_SHOW;       | ANS_BOX_SHOW '=' ANS_OFF {  LexiProblem_p->show_ans_box = DONOT_SHOW;
Line 549  pt_list      :   pt_list  ','  point_coo Line 583  pt_list      :   pt_list  ','  point_coo
              |   pt_range                           { }               |   pt_range                           { }
              ;               ;
   
 pt_range     :   point_coord   ':'  point_coord  '#'  IDENTIFIER   { PointsList_t *pt;  pt_range     :   point_coord   ':'  point_coord  '#'  IDENTIFIER   
                                 { 
                                                                      if( LastPtsList != NULL ) {   assign_pts($1,$3,$5);
                                                                         LastPtsList->pts_next = gen_ptslist( $1, $3, $5 );   /*PointsList_t *pt;
                                                                         pt = LastPtsList->pts_next;          if( LastPtsList != NULL ) {
                                                                         while( pt->pts_next != NULL ) {    LastPtsList->pts_next = gen_ptslist( $1, $3, $5 );
                                                                            pt = pt->pts_next;    pt = LastPtsList->pts_next;
                                                                         }    while( pt->pts_next != NULL ) {
                                                                         LastPtsList = pt;      pt = pt->pts_next;
                                                                      } else {    }
                                                                         CurrPtsList = gen_ptslist( $1, $3, $5 );    LastPtsList = pt;
                                                                         LastPtsList = CurrPtsList;   } else {
                                                                      }    CurrPtsList = gen_ptslist( $1, $3, $5 );
                                                                      if( $1->s_type == S_CONSTANT ) {    LastPtsList = CurrPtsList;
                                                                          capa_mfree($1->s_str); capa_mfree((char *)$1);   }
                                                                      }   if( $1->s_type == S_CONSTANT ) {
                                                                      if( $3->s_type == S_CONSTANT ) {    capa_mfree($1->s_str); capa_mfree((char *)$1);
                                                                          capa_mfree($3->s_str); capa_mfree((char *)$3);   }
                                                                      }   if( $3->s_type == S_CONSTANT ) {
                                                                    }    capa_mfree($3->s_str); capa_mfree((char *)$3);
              |   point_coord   ':'  point_coord  '#'  a_number     { PointsList_t *pt;   }
    */
                                                                      if( LastPtsList != NULL ) {        }
                                                                         LastPtsList->pts_next = gen_ptslist( $1, $3, $5 );               |   point_coord   ':'  point_coord  '#'  ARRAY_ID '[' calc_expr ']'
                                                                         pt = LastPtsList->pts_next;                                { assign_pts($1,$3,get_array_symbol($5,$7,1)); }
                                                                         while( pt->pts_next != NULL ) {               |   point_coord   ':'  point_coord  '#'  a_number     
                                                                            pt = pt->pts_next;                                { 
                                                                         }   assign_pts($1,$3,$5);
                                                                         LastPtsList = pt;   /*PointsList_t *pt;
                                                                      } else {        
                                                                         CurrPtsList = gen_ptslist( $1, $3, $5 );   if( LastPtsList != NULL ) {
                                                                         LastPtsList = CurrPtsList;     LastPtsList->pts_next = gen_ptslist( $1, $3, $5 );
                                                                      }     pt = LastPtsList->pts_next;
                                                                      if( $1->s_type == S_CONSTANT ) {     while( pt->pts_next != NULL ) {
                                                                          capa_mfree($1->s_str); capa_mfree((char *)$1);       pt = pt->pts_next;
                                                                      }     }
                                                                      if( $3->s_type == S_CONSTANT ) {     LastPtsList = pt;
                                                                          capa_mfree($3->s_str); capa_mfree((char *)$3);   } else {
                                                                      }     CurrPtsList = gen_ptslist( $1, $3, $5 );
                                                                      if( $5->s_type == I_CONSTANT || $5->s_type == R_CONSTANT) {     LastPtsList = CurrPtsList;
                                                                          capa_mfree((char *)$5);   }
                                                                      }   if( $1->s_type == S_CONSTANT ) {
                                                                    }     capa_mfree($1->s_str); capa_mfree((char *)$1);
    }
    if( $3->s_type == S_CONSTANT ) {
      capa_mfree($3->s_str); capa_mfree((char *)$3);
    }
    if( $5->s_type == I_CONSTANT || $5->s_type == R_CONSTANT) {
      capa_mfree((char *)$5);
    }
    */
         }
              ;               ;
   
   
 point_coord  :   IDENTIFIER            { $$ = $1;  }  point_coord  :   IDENTIFIER                 { $$ = $1;  }
              |   S_CONSTANT            { $$ = $1;  }               |   ARRAY_ID '[' calc_expr ']' { $$ = get_array_symbol($1,$3,1); }
                |   S_CONSTANT                 { $$ = $1;  }
              ;               ;
   
   
Line 660  map_expr     : startM '(' basic_constr ' Line 704  map_expr     : startM '(' basic_constr '
     a_sp=build_array_list($5,$7->s_argc);      a_sp=build_array_list($5,$7->s_argc);
     result=do_map(key, a_sp->s_argp, $7->s_argp, a_sp->s_argc, FORWARD_MAP);      result=do_map(key, a_sp->s_argp, $7->s_argp, a_sp->s_argc, FORWARD_MAP);
     free_arglist(a_sp->s_argp);      free_arglist(a_sp->s_argp);
       a_sp->s_argp=NULL;
   } else {    } else {
     sprintf(warn_msg,"/MAP arg. counts are not matched.\n");      sprintf(warn_msg,"/MAP arg. counts are not matched.\n");
     capa_msg(MESSAGE_ERROR,warn_msg);      capa_msg(MESSAGE_ERROR,warn_msg);
Line 671  map_expr     : startM '(' basic_constr ' Line 716  map_expr     : startM '(' basic_constr '
     capa_msg(MESSAGE_ERROR,warn_msg);      capa_msg(MESSAGE_ERROR,warn_msg);
  }   }
                                         free_arglist($5->s_argp);                                          free_arglist($5->s_argp);
                                         free_arglist($7->s_argp);   $5->s_argp=NULL;
    free_arglist($7->s_argp);
    $7->s_argp=NULL;
                                       }                                        }
              | startR '(' basic_constr ';' var_list ';' arg_list ')'               | startR '(' basic_constr ';' var_list ';' arg_list ')'
                                       { char   key[SMALL_LINE_BUFFER];                                        { char   key[SMALL_LINE_BUFFER];
Line 689  map_expr     : startM '(' basic_constr ' Line 736  map_expr     : startM '(' basic_constr '
     a_sp=build_array_list($5,$7->s_argc);      a_sp=build_array_list($5,$7->s_argc);
     result=do_map(key, a_sp->s_argp, $7->s_argp, a_sp->s_argc, FORWARD_MAP);      result=do_map(key, a_sp->s_argp, $7->s_argp, a_sp->s_argc, FORWARD_MAP);
     free_arglist(a_sp->s_argp);      free_arglist(a_sp->s_argp);
       a_sp->s_argp=NULL;
   } else {    } else {
     sprintf(warn_msg,"/RMAP arg. counts are not matched.\n");      sprintf(warn_msg,"/RMAP arg. counts are not matched.\n");
     capa_msg(MESSAGE_ERROR,warn_msg);      capa_msg(MESSAGE_ERROR,warn_msg);
Line 700  map_expr     : startM '(' basic_constr ' Line 748  map_expr     : startM '(' basic_constr '
     capa_msg(MESSAGE_ERROR,warn_msg);      capa_msg(MESSAGE_ERROR,warn_msg);
  }   }
                                         free_arglist($5->s_argp);                                          free_arglist($5->s_argp);
    $5->s_argp=NULL;
                                         free_arglist($7->s_argp);                                          free_arglist($7->s_argp);
    $7->s_argp=NULL;
                                       }                                        }
              ;               ;
   
Line 752  basic_constr : FUNCTION_ID '('  ')'   { Line 802  basic_constr : FUNCTION_ID '('  ')'   {
    $$ = do_function(tmp, $3->s_argc, $3->s_argp);     $$ = do_function(tmp, $3->s_argc, $3->s_argp);
    capa_mfree(FuncStack[Func_idx].s_name);     capa_mfree(FuncStack[Func_idx].s_name);
    free_arglist($3->s_argp);     free_arglist($3->s_argp);
      $3->s_argp=NULL;
                                          }                                           }
                                          YYDBUG_PR1(" basic_constr <= RETURN FUNCT "); YYDBUG_SYM($$);                                           YYDBUG_PR1(" basic_constr <= RETURN FUNCT "); YYDBUG_SYM($$);
                                                                                     
Line 829  an_integer   : I_CONSTANT Line 880  an_integer   : I_CONSTANT
 a_real       : R_CONSTANT               { $$ = $1; }   a_real       : R_CONSTANT               { $$ = $1; } 
              ;               ;
   
 an_array     : ARRAY_ID '[' calc_expr ']'     {   $$=get_array_symbol($1,$3,1);   }   an_array     : ARRAY_ID '[' calc_expr ']'     {   
                                            YYDBUG_PR1(" an_array <= ARRAY_ID '['calc_expr ']' ");
                                            $$=get_array_symbol($1,$3,1);   
                                                  } 
              ;               ;
   
 startQ       :                  { /* first matching will occur before first line of input text */  startQ       :                  { /* first matching will occur before first line of input text */
Line 910  Symbol *name,*index;int free_symbols; Line 964  Symbol *name,*index;int free_symbols;
       
   key = (char *)capa_malloc(idx_len+leng,1);    key = (char *)capa_malloc(idx_len+leng,1);
   sprintf(key,"%s[%s]",name->s_name,tmp);    sprintf(key,"%s[%s]",name->s_name,tmp);
       a_p = (Symbol *)NULL;
   a_p = find_arrayid(name->s_name);   /* use the array name to search array tree */    a_p = find_arrayid(name->s_name); /* use the array name to search array tree */
                                       /* */    if( a_p == NULL ) {
       return NULL;
     }
                                         /* did not check for error! */
   s_p = find_array_by_index(a_p,key); /* use the index portion to search along array linked list */    s_p = find_array_by_index(a_p,key); /* use the index portion to search along array linked list */
   capa_mfree((char *)tmp); capa_mfree((char *)key);    capa_mfree((char *)tmp); capa_mfree((char *)key);
       
Line 1073  append_warn(type,str) int type;char *str Line 1130  append_warn(type,str) int type;char *str
 /*********** if *b is a constant symbol, destroy (free) b ********************/  /*********** if *b is a constant symbol, destroy (free) b ********************/
 /*********** if *a is a var symbol, create a new symbol **********************/  /*********** if *a is a var symbol, create a new symbol **********************/
 /*                 do not free(*a)     */  /*                 do not free(*a)     */
 /*           */  /*  If either a or b is invalid it propagates the error up the parse tree    */
 Symbol *  Symbol *
 symbols_op(a, b, op) Symbol *a; Symbol *b; int op;  symbols_op(a, b, op) Symbol *a; Symbol *b; int op;
 {  {
Line 1088  if( a->s_type == IDENTIFIER || b->s_type Line 1145  if( a->s_type == IDENTIFIER || b->s_type
    if(a->s_type == IDENTIFIER) { /* a is IDENTIFIER */     if(a->s_type == IDENTIFIER) { /* a is IDENTIFIER */
      sprintf(warn_msg,"var \"%s\" not defined before use.\n", a->s_name);       sprintf(warn_msg,"var \"%s\" not defined before use.\n", a->s_name);
      capa_msg(MESSAGE_ERROR,warn_msg);       capa_msg(MESSAGE_ERROR,warn_msg);
      return (b);       return (a);
    } else { /* b is IDENTIFIER */     } else { /* b is IDENTIFIER */
      sprintf(warn_msg,       sprintf(warn_msg,"var \"%s\" not defined before use.\n",b->s_name);
       "var \"%s\" not defined before use.\n",b->s_name);  
      capa_msg(MESSAGE_ERROR,warn_msg);       capa_msg(MESSAGE_ERROR,warn_msg);
      return (a);       return (b);
    }     }
  } else {  /* a and b are neither identifiers */   } else {  /* a and b are neither identifiers */
   if( (a->s_type == I_VAR) ||    if( (a->s_type == I_VAR) ||
Line 1138  if( a->s_type == IDENTIFIER || b->s_type Line 1194  if( a->s_type == IDENTIFIER || b->s_type
         (b->s_type == S_VAR) || (b->s_type == S_CONSTANT) ) { /* either a or b is a string */          (b->s_type == S_VAR) || (b->s_type == S_CONSTANT) ) { /* either a or b is a string */
       type = S_CONSTANT;  /* the return type is a string */        type = S_CONSTANT;  /* the return type is a string */
       if( (a->s_type == S_VAR) || (a->s_type == S_CONSTANT) ) { /* a is a string */        if( (a->s_type == S_VAR) || (a->s_type == S_CONSTANT) ) { /* a is a string */
         switch( b->s_type ) {   if (a->s_str == NULL || 
          case I_VAR:      (((b->s_type == S_VAR) || (b->s_type == S_CONSTANT)) && b->s_str == NULL)) {
          case I_CONSTANT:    if (a->s_str == NULL) {
                    leng = SMALL_LINE_BUFFER; /* assuming a long integer does not exceed 128 digits*/      sprintf(warn_msg,"variable %s has not yet been assigned a value.\n",a->s_name);
                    b_str= capa_malloc(sizeof(char), leng);      capa_msg(MESSAGE_ERROR,warn_msg);
                    sprintf(b_str,"%ld", b->s_int);    }
                    break;    if (((b->s_type == S_VAR) || (b->s_type == S_CONSTANT)) && b->s_str == NULL) {
          case R_VAR:      sprintf(warn_msg,"variable %s has not yet been assigned a value.\n",a->s_name);
          case R_CONSTANT:      capa_msg(MESSAGE_ERROR,warn_msg);
                    leng = SMALL_LINE_BUFFER;/*assuming a double does not exceed128chars*/    }
                    b_str= capa_malloc(sizeof(char), leng);   } else { /* a is a valid string */
                    sprintf(b_str,"%.15g", b->s_real);    switch( b->s_type ) {
                    break;    case I_VAR:
          case S_VAR:    case I_CONSTANT:
          case S_CONSTANT: /* DONE: get rid of limitations on b_str[] */      leng = SMALL_LINE_BUFFER; /* assuming a long integer does not exceed 128 digits*/
                    leng =  strlen( b->s_str ) +  1;      b_str= capa_malloc(sizeof(char), leng);
                    b_str= capa_malloc(sizeof(char), leng);      sprintf(b_str,"%ld", b->s_int);
                    sprintf(b_str,"%s",b->s_str);      break;
                    /*if(b->s_type == S_CONSTANT)  capa_mfree(b->s_str);*/    case R_VAR:
                    break;    case R_CONSTANT:
         }      leng = SMALL_LINE_BUFFER;/*assuming a double does not exceed128chars*/
         switch( op ) {      b_str= capa_malloc(sizeof(char), leng);
          case ADD_op:      sprintf(b_str,"%.15g", b->s_real);
                    leng =  strlen( a->s_str ) + strlen(b_str) + 1;      break;
                    r_strp = capa_malloc(sizeof(char), leng);    /* **** */    case S_VAR:
                    strcat(r_strp, a->s_str);    case S_CONSTANT: /* DONE: get rid of limitations on b_str[] */
                    strcat(r_strp, b_str);  /* concatenate two strings together */      leng =  strlen( b->s_str ) +  1;
                    if( !new )   capa_mfree(a->s_str);        b_str= capa_malloc(sizeof(char), leng);
    a_symp->s_str = r_strp;      sprintf(b_str,"%s",b->s_str);
                    break;      /*if(b->s_type == S_CONSTANT)  capa_mfree(b->s_str);*/
          case SUB_op:      break;
          case MUL_op:    }
          case DIV_op:    switch( op ) {
          case IDIV_op:    case ADD_op:
                    if( !new )   capa_mfree(a->s_str);      leng =  strlen( a->s_str ) + strlen(b_str) + 1;
                    a_symp->s_str = strsave("<<Op NOT DEFINED>>");      r_strp = capa_malloc(sizeof(char), leng);    /* **** */
                    sprintf(warn_msg,"integer division (%%) cannot accept string operand!\n");      strcat(r_strp, a->s_str);
                    capa_msg(MESSAGE_ERROR,warn_msg);      strcat(r_strp, b_str);  /* concatenate two strings together */
                    break;      if( !new )   capa_mfree(a->s_str);  
          case EQ_op: a_symp->s_int = (strcmp(a->s_str, b_str) == 0? 1: 0);      a_symp->s_str = r_strp;
                      type = I_CONSTANT;  break;      break;
          case NE_op: a_symp->s_int = (strcmp(a->s_str, b_str) == 0? 0: 1);    case SUB_op:
                      type = I_CONSTANT;  break;    case MUL_op:
          case GT_op: a_symp->s_int = (strcmp(a->s_str, b_str) > 0? 1: 0);    case DIV_op:
                      type = I_CONSTANT;  break;    case IDIV_op:
          case GE_op: a_symp->s_int = (strcmp(a->s_str, b_str) >= 0? 1: 0);      if( !new )   capa_mfree(a->s_str);
                      type = I_CONSTANT;  break;      a_symp->s_str = strsave("<<Op NOT DEFINED>>");
          case LT_op: a_symp->s_int = (strcmp(a->s_str, b_str) < 0? 1: 0);      sprintf(warn_msg,"integer division (%%) cannot accept string operand!\n");
                      type = I_CONSTANT;  break;      capa_msg(MESSAGE_ERROR,warn_msg);
          case LE_op: a_symp->s_int = (strcmp(a->s_str, b_str) <= 0? 1: 0);      break;
                      type = I_CONSTANT;  break;    case EQ_op: a_symp->s_int = (strcmp(a->s_str, b_str) == 0? 1: 0);
          case AND_op: if( (a->s_str[0] != 0) && (b_str[0] != 0)) {      type = I_CONSTANT;  break;
                        a_symp->s_int = 1;    case NE_op: a_symp->s_int = (strcmp(a->s_str, b_str) == 0? 0: 1);
                       } else {      type = I_CONSTANT;  break;
                        a_symp->s_int = 0;    case GT_op: a_symp->s_int = (strcmp(a->s_str, b_str) > 0? 1: 0);
                       }       type = I_CONSTANT;  break;
                      type = I_CONSTANT;  break;    case GE_op: a_symp->s_int = (strcmp(a->s_str, b_str) >= 0? 1: 0);
          case OR_op: if( (a->s_str[0] != 0) || (b_str[0] != 0)) {      type = I_CONSTANT;  break;
                        a_symp->s_int = 1;    case LT_op: a_symp->s_int = (strcmp(a->s_str, b_str) < 0? 1: 0);
                       } else {      type = I_CONSTANT;  break;
                        a_symp->s_int = 0;    case LE_op: a_symp->s_int = (strcmp(a->s_str, b_str) <= 0? 1: 0);
                       }       type = I_CONSTANT;  break;
                      type = I_CONSTANT;  break;    case AND_op: 
         }      if( (a->s_str[0] != 0) && (b_str[0] != 0)) {
         a_symp->s_int = 1;
       } else {
         a_symp->s_int = 0;
       } 
       type = I_CONSTANT;  break;
     case OR_op: 
       if( (a->s_str[0] != 0) || (b_str[0] != 0)) {
         a_symp->s_int = 1;
       } else {
         a_symp->s_int = 0;
       } 
       type = I_CONSTANT;  break;
     }
    }
  if (b_str!=NULL) capa_mfree(b_str);   if (b_str!=NULL) capa_mfree(b_str);
       } else {  /* b is string and a is either integer or real */        } else {  /* b is string and a is either integer or real */
         switch( a->s_type ) {          switch( a->s_type ) {
Line 1486  display_var( s )Symbol *s; Line 1556  display_var( s )Symbol *s;
               }                }
             }              }
            break;             break;
      case S_VAR:  case S_CONSTANT:       case S_VAR:  case S_CONSTANT:  
             aline = (char *)capa_malloc(strlen(s->s_str)+1,1);              if (s->s_str == NULL) {
             sprintf(aline,"%s",s->s_str);        sprintf(warn_msg,"variable %s has not yet been assigned a value.\n",
         s->s_name);
         capa_msg(MESSAGE_ERROR,warn_msg);
         aline=(char *)capa_malloc(9,1);
         sprintf(aline,"NO VALUE");
               } else {
         aline = (char *)capa_malloc(strlen(s->s_str)+1,1);
         sprintf(aline,"%s",s->s_str);
       }
            break;             break;
    }     }
    append_text(aline);     append_text(aline);
    capa_mfree((char *)aline);     capa_mfree((char *)aline);
    if(s->s_format) {      if(s->s_format) { capa_mfree((char *)s->s_format); }
       capa_mfree((char *)s->s_format);  
    }  
    s->s_format = NULL;     s->s_format = NULL;
    switch(s->s_type) { /* free up spaces taken by constants */     switch(s->s_type) { /* free up spaces taken by constants */
      case I_CONSTANT:       case I_CONSTANT:
Line 1764  assign_id_list( s ) Symbol *s; Line 1840  assign_id_list( s ) Symbol *s;
   }    }
 }  }
   
   /* void assign_pts ( Symbol* coord1, Symbol* coord2, Symbol* num) { */
   void assign_pts (coord1, coord2, num)Symbol *coord1;Symbol *coord2;Symbol *num;
   {
     PointsList_t *pt;
     if( LastPtsList != NULL ) {
       LastPtsList->pts_next = gen_ptslist( coord1, coord2, num );
       pt = LastPtsList->pts_next;
       while( pt->pts_next != NULL ) {
         pt = pt->pts_next;
       }
       LastPtsList = pt;
     } else {
       CurrPtsList = gen_ptslist( coord1, coord2, num );
       LastPtsList = CurrPtsList;
     }
     if(coord1->s_type == S_CONSTANT) {
       capa_mfree(coord1->s_str); capa_mfree((char *)coord1);
     }
     if(coord2->s_type == S_CONSTANT) {
       capa_mfree(coord2->s_str); capa_mfree((char *)coord2);
     }
     if(num->s_type == I_CONSTANT || num->s_type == R_CONSTANT) {
       capa_mfree((char *)num);
     }
   }
   
 /* =========================================================================== */  /* =========================================================================== */
   
   

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


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