version 1.3, 1999/10/13 20:05:00
|
version 1.5, 1999/10/20 19:57:37
|
Line 332 q_text : TEXT_LINE
|
Line 332 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 358 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 371 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 1138 if( a->s_type == IDENTIFIER || b->s_type
|
Line 1143 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 1505 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: |