"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,
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
}
/* 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);
}
if( firstchar == '"')
error("non-terminated string");
return(STRVALUE);
+ case '\'':
+ case '\\':
+ putc('\\', emfile);
default:
fputc(*cptr,emfile);
}
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);
%token ERRSYM
%token ERLSYM
%token ERRORSYM
-%token ELSESYM
%token FIELDSYM
%token FORSYM
%token <integer> FUNCTION
| /* 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;}
;
-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);}
| funcname { $$=fcnend(0);}
| funcname funccall ')' { $$=fcnend($2);}
| MIDSYM '$' midparms
- { warning("Unsupported function call");
+ {
emcode("cal","$_mid");
emcode("asp",EMINTSIZE);
emcode("asp",EMINTSIZE);
/* 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");
{
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;
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;
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++ ) {
default:fatal("Too many file arguments") ;
}
}
+ if (files < 3) fatal("Too few file arguments");
}
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;