From a6d90aaeec1be4e61535e7f20313bf0568f8ce00 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 11 Feb 1987 14:29:27 +0000 Subject: [PATCH] many bug fixes --- lang/basic/src.old/basic.lex | 40 +++++++++++++++++++---------------- lang/basic/src.old/basic.yacc | 29 ++++++++++++++----------- lang/basic/src.old/gencode.c | 7 ++++-- lang/basic/src.old/graph.c | 2 +- lang/basic/src.old/parsepar.c | 10 +++++---- lang/basic/src.old/util.c | 20 ++++++++++++------ 6 files changed, 64 insertions(+), 44 deletions(-) diff --git a/lang/basic/src.old/basic.lex b/lang/basic/src.old/basic.lex index 526b37cf0..b901ca63f 100644 --- a/lang/basic/src.old/basic.lex +++ b/lang/basic/src.old/basic.lex @@ -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 MAXINT || i1': if( *(c+1)=='='){ c++;c++;cptr=c; yylval.integer= GESYM;return(RELOP); diff --git a/lang/basic/src.old/basic.yacc b/lang/basic/src.old/basic.yacc index 091956bc9..10c1d20c4 100644 --- a/lang/basic/src.old/basic.yacc +++ b/lang/basic/src.old/basic.yacc @@ -15,7 +15,6 @@ %token ERRSYM %token ERLSYM %token ERRORSYM -%token ELSESYM %token FIELDSYM %token FORSYM %token 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); diff --git a/lang/basic/src.old/gencode.c b/lang/basic/src.old/gencode.c index 8efd79f57..024fb451a 100644 --- a/lang/basic/src.old/gencode.c +++ b/lang/basic/src.old/gencode.c @@ -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"); diff --git a/lang/basic/src.old/graph.c b/lang/basic/src.old/graph.c index c09b65dbc..545d499db 100644 --- a/lang/basic/src.old/graph.c +++ b/lang/basic/src.old/graph.c @@ -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; diff --git a/lang/basic/src.old/parsepar.c b/lang/basic/src.old/parsepar.c index 15ef90b93..df016ff42 100644 --- a/lang/basic/src.old/parsepar.c +++ b/lang/basic/src.old/parsepar.c @@ -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 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"); } diff --git a/lang/basic/src.old/util.c b/lang/basic/src.old/util.c index 7ef314dc2..3a1d2acc7 100644 --- a/lang/basic/src.old/util.c +++ b/lang/basic/src.old/util.c @@ -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; -- 2.34.1