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

View file

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

View file

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

View file

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

View file

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

View file

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