many bug fixes

This commit is contained in:
ceriel 1987-02-11 14:29:27 +00:00
parent f18da9078c
commit a6d90aaeec
6 changed files with 64 additions and 44 deletions

View file

@ -44,12 +44,11 @@ Key keywords [] ={
"else", ELSESYM, 0, 0,
"end", ENDSYM, 0, 0,
"eof", FUNCTION, EOFSYM, 0,
"eqv", BOOLOP, EQVSYM, 0,
"erase", ILLEGAL, 0, 0,
"error", ERRORSYM, 0, 0,
"err", ERRSYM, 0, 0,
"erl", ERLSYM, 0, 0,
"else", ELSESYM, 0, 0,
"eqv", BOOLOP, EQVSYM, 0,
"exp", FUNCTION, EXPSYM, 0,
"field", FIELDSYM, 0, 0,
"fix", FUNCTION, FIXSYM, 0,
@ -309,23 +308,29 @@ readconstant()
number()
{
long i1;
double f,dec;
int minflag;
double atof();
register char *c;
int overflow = 0;
char cx;
i1=0;
c=cptr;
while(isdigit(*c)){
i1= i1*10 + *c-'0';
if (i1 < 0) overflow = 1;
c++;
}
cptr=c;
if( *c != '.'){
if( i1> MAXINT || i1<MININT) {
/*NOSTRICT*/ dval= i1;
if( i1> MAXINT || i1<MININT || overflow) {
cx = *c;
*c = 0;
/*NOSTRICT*/ dval= atof(cptr);
cptr=c;
*c = cx;
return(FLTVALUE);
}
/*NOSTRICT*/ ival= i1;
cptr = c;
#ifdef YYDEBUG
if(yydebug) printf("number:INTVALUE %d",i1);
#endif
@ -333,28 +338,22 @@ number()
}
/* handle floats */
/*NOSTRICT*/
f= i1; dec=0.1;
c++;
while( isdigit(*c)){
f= f + dec * (*c - '0');
dec /= 10.0;
c++;
}
/* handle exponential part */
if( *c =='e' || *c == 'E'){
c++;
minflag= (*c== '-')? -1: 1;
if( *c=='-' || *c=='+') c++;
while(isdigit(*c)){
f *= 10.0;
c++;
}
if(minflag== -1) f= 1.0/f;
}
dval= f;
cptr=c;
cx = *c; *c = 0;
dval = atof(cptr);
*c = cx; cptr=c;
#ifdef YYDEBUG
if(yydebug) printf("number:FLTVALUE %f",f);
if(yydebug) printf("number:FLTVALUE %f",dval);
#endif
return(FLTVALUE);
}
@ -384,6 +383,9 @@ scanstring()
if( firstchar == '"')
error("non-terminated string");
return(STRVALUE);
case '\'':
case '\\':
putc('\\', emfile);
default:
fputc(*cptr,emfile);
}
@ -445,7 +447,9 @@ yylex()
return(yylex());
case '&':
return(readconstant());
case '?': return(PRINTSYM);
case '?':
cptr++;
return(PRINTSYM);
case '>':
if( *(c+1)=='='){
c++;c++;cptr=c; yylval.integer= GESYM;return(RELOP);

View file

@ -15,7 +15,6 @@
%token ERRSYM
%token ERLSYM
%token ERRORSYM
%token ELSESYM
%token FIELDSYM
%token FORSYM
%token <integer> FUNCTION
@ -353,8 +352,8 @@ format : USINGSYM STRVALUE ';' { loadstr($2);}
| /* empty */ {formatstring=0;}
printlist: expression { printstmt($1); $$=1;}
| ',' { zone(0); $$=0;}
| ';' { zone(1); $$=0;}
| ',' { zone(1); $$=0;}
| ';' { zone(0); $$=0;}
| printlist expression { printstmt($2); $$=1;}
| printlist ',' { zone(1);$$=0;}
| printlist ';' { zone(0);$$=0;}
@ -405,25 +404,31 @@ indexed : identifier '(' {newarrayload($1);}
;
expression: negation
| negation BOOLOP expression {$$=boolop($1,$3,$2);}
expression:
negation
| expression BOOLOP expression {$$=boolop($1,$3,$2);}
;
negation: NOTSYM compare {$$=boolop($2,0,NOTSYM);}
| compare
;
compare : sum
| sum RELOP sum {$$=relop($1,$3,$2);}
| sum '=' sum {$$=relop($1,$3,'=');}
;
sum : term
| term '-' sum {$$=plusmin($1,$3,'-');}
| term '+' sum {$$=plusmin($1,$3,'+');}
| sum '-' sum {$$=plusmin($1,$3,'-');}
| sum '+' sum {$$=plusmin($1,$3,'+');}
;
term : factor
| factor '^' factor {$$=power($1,$3);}
| factor '*' term {$$=muldiv($1,$3,'*');}
| factor '\\' term {$$=muldiv($1,$3,'\\');}
| factor '/' term {$$=muldiv($1,$3,'/');}
| factor MODSYM term {$$=muldiv($1,$3,MODSYM);}
| term '*' term {$$=muldiv($1,$3,'*');}
| term '\\' term {$$=muldiv($1,$3,'\\');}
| term '/' term {$$=muldiv($1,$3,'/');}
| term MODSYM term {$$=muldiv($1,$3,MODSYM);}
;
factor : INTVALUE {$$=loadint(ival);}
| '(' expression ')' {$$=$2;}
| '-' factor { $$=negate($2);}
@ -440,7 +445,7 @@ factor : INTVALUE {$$=loadint(ival);}
| funcname { $$=fcnend(0);}
| funcname funccall ')' { $$=fcnend($2);}
| MIDSYM '$' midparms
{ warning("Unsupported function call");
{
emcode("cal","$_mid");
emcode("asp",EMINTSIZE);
emcode("asp",EMINTSIZE);

View file

@ -50,8 +50,11 @@ int nr;
/* save location on tmpfile */
currline->offset= ftell(tmpfile);
fprintf(tmpfile,"%d\n",currline->emlabel);
fprintf(tmpfile," lin %d\n",nr);
emlinecount += 2;
emlinecount++;
if (! nolins) {
fprintf(tmpfile," lin %d\n",nr);
emlinecount++;
}
if( tronoff || traceflag) {
emcode("loc",itoa(nr));
emcode("cal","$_trace");

View file

@ -45,7 +45,7 @@ linewarnings()
{
if( !srchline(l->linenr))
{
printf("ERROR: line %d not defined\n",l->linenr);
fprintf(stderr,"ERROR: line %d not defined\n",l->linenr);
errorcnt++;
}
l=l->nextlist;

View file

@ -4,12 +4,12 @@
static char rcs_id[] = "$Header$" ;
#endif
int listing; /* -l listing required */
int listing; /* -E listing required */
int debug; /* -d compiler debugging */
int wflag=1; /* -w no warnings */
int wflag=0; /* -w no warnings */
int hflag=0; /* -h<number> to split EM program */
int traceflag=0; /* generate line tracing code */
int nolins=0; /* generate no LIN statements */
int nolins=0; /* -l: generate no LIN statements */
parseparams(argc,argv)
int argc;
@ -37,8 +37,9 @@ char **argv;
threshold= THRESHOLD;
break;
case 'd': debug++; break;
case 'l': nolins++; break; /* no EM lin statements */
case 'L': nolins++; break; /* no EM lin statements */
case 'E': listing++; break; /* generate full listing */
case 'w': wflag++; break;
} else {
/* new input file */
switch ( files++ ) {
@ -49,4 +50,5 @@ char **argv;
default:fatal("Too many file arguments") ;
}
}
if (files < 3) fatal("Too few file arguments");
}

View file

@ -12,29 +12,35 @@ int errorcnt;
warning(str)
char *str;
{
printf("WARNING:%s\n",str);
if (! wflag) Xerror("WARNING",str);
}
error(str)
char *str;
{
extern int listing,yylineno;
if( !listing) printf("LINE %d:",yylineno);
printf("ERROR:%s\n",str);
Xerror("ERROR",str);
errorcnt++;
}
Xerror(type,str)
char *str;
char *type;
{
extern int listing,yylineno;
if( !listing) fprintf(stderr,"LINE %d:",yylineno);
fprintf(stderr,"%s:%s\n",type,str);
}
fatal(str)
char *str;
{
printf("FATAL:%s\n",str);
Xerror("FATAL",str);
exit(-1);
}
notyetimpl()
{
printf("WARNING: not yet implemented\n");
warning("not yet implemented");
}
illegalcmd()
{
printf("WARNING: illegal command\n");
warning("illegal command");
}
char *itoa(i)
int i;