2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
76 /* Those were originally %left */
82 /* Some contstant declared as tokens (?) */
108 int in_data = 0; /* set if processing DATA statement */
110 char *formatstring; /* formatstring used for printing */
111 Symbol *s; /* Symbol dummy */
119 %start LLparse,programline ;
123 { basicline = ival;newblock(ival); newemblock(ival); }
125 | '#' INTVALUE STRVALUE EOLN
131 [ %while ( LLsymb == ':' ) ':' singlestmt ]*
134 singlestmt { int d2 ; }
142 | ERRORSYM expression(&d2) { errorstmt(d2); }
156 | GOTOSYM INTVALUE { gotostmt(ival); }
166 | ENDSYM { C_loc((arith) 0 );
168 C_asp((arith) BEMINTSIZE);
170 | STOPSYM { C_cal("_stop"); }
172 | TRONOFFSYM { tronoff=yylval.integer; }
176 | /* EMPTY STATEMENT */
179 illegalstmt: ILLEGAL { illegalcmd(); }
182 callstmt { Symbol *id; int i; }
184 IDENTIFIER { id = yylval.Sptr; }
186 { C_cal(id->symname);
187 C_asp((arith) (i*BEMPTRSIZE));
190 { C_cal(id->symname); }
194 parmlist(int *ip;) { int var ; }
196 variable(&var) { *ip = 1; }
197 [ ',' variable(&var) { *ip = *ip + 1; } ]*
202 clearstmt { int exp; }
203 : CLEARSYM [ ',' expression(&exp) ]*2
204 { warning("statement ignored"); }
208 | /* empty */ { C_cal("_close"); }
211 filelist { int intv; }
214 { C_loc((arith) ival);
216 C_asp((arith) BEMINTSIZE);
221 { C_loc((arith) ival);
223 C_asp((arith) BEMINTSIZE);
227 datastmt: DATASYM { datastmt(); in_data = 1;}
228 datalist { fprint(datfile,"\n"); in_data = 0; }
231 dataelm : INTVALUE { fprint(datfile,"%d",ival); }
232 | '-' [ INTVALUE { fprint(datfile,"%d",-ival); }
233 | FLTVALUE { fprint(datfile,"-%s",dval); }
235 | FLTVALUE { fprint(datfile,dval); }
236 | STRVALUE { fprint(datfile,"\"%s\"",sval); }
237 | IDENTIFIER { fprint(datfile,"\"%s\"",sval); }
241 [ ',' { fprint(datfile,","); }
251 deffnstmt { int exp; }
252 : heading '=' expression(&exp)
256 heading : FUNCTID { newscope(yylval.Sptr); }
257 [ '(' idlist ')' ]? { heading(); }
260 idlist : IDENTIFIER { dclparm(yylval.Sptr); }
261 [ ',' IDENTIFIER { dclparm(yylval.Sptr); }
265 defvarstmt: DEFINTSYM { setdefaulttype( INTTYPE); }
266 | DEFSNGSYM { setdefaulttype( FLOATTYPE); }
267 | DEFDBLSYM { setdefaulttype( DOUBLETYPE); }
268 | DEFSTRSYM { setdefaulttype( STRINGTYPE); }
271 defusrstmt: USRSYM ':' { illegalcmd(); }
274 dimstmt { Symbol *symp; }
275 : DIMSYM arraydcl(&symp) ')' { dclarray(symp); }
276 [ ',' arraydcl(&symp) ')' { dclarray(symp); }
280 arraydcl(Symbol **sympp;)
281 : IDENTIFIER { *sympp = s = yylval.Sptr; }
285 s->dimlimit[s->dimensions]=ival;
291 if(s->dimensions<MAXDIMENSIONS) {
292 s->dimlimit[s->dimensions]=ival;
294 } else error("too many dimensions");
298 fieldstmt { int intv; }
299 : FIELDSYM cross intvalue(&intv)
300 { setchannel(ival); }
301 ',' fieldlist { notyetimpl(); }
304 fieldlist { int intv; int var; }
305 : intvalue(&intv) ASSYM variable(&var)
306 [ ',' intvalue(&intv) ASSYM variable(&var) ]*
310 : FORSYM IDENTIFIER { forinit(yylval.Sptr); }
311 '=' expression(&exp) { forexpr(exp); }
312 TOSYM expression(&exp) { forlimit(exp); }
317 : STEPSYM expression(&exp) { forstep(exp); }
324 nextstmt: [ IDENTIFIER { nextstmt(yylval.Sptr); }
325 | /* empty */ { nextstmt((Symbol *)0); }
327 [ ',' IDENTIFIER { nextstmt(yylval.Sptr); }
331 getstmt { char *cp; int intv; }
336 C_asp((arith) BEMINTSIZE);
338 | ',' intvalue(&intv)
339 { C_loc((arith) ival);
341 C_asp((arith) BEMINTSIZE);
346 getput(char **cpp;) { int intv; }
347 : GETSYM cross intvalue(&intv)
351 | PUTSYM cross intvalue(&intv)
357 gosubstmt: GOSUBSYM INTVALUE { gosubstmt(ival); }
360 returnstmt: RETURNSYM { returnstmt(); }
363 ifstmt { int exp; int d1; }
364 : IFSYM expression(&exp) { d1=ifstmt(exp); }
365 thenpart { d1=thenpart(d1); }
366 elsepart { elsepart(d1); }
369 thenpart: THENSYM [ INTVALUE { gotostmt(ival); }
372 | GOTOSYM INTVALUE { gotostmt(ival); }
375 elsepart: %prefer ELSESYM
376 [ INTVALUE { gotostmt(ival); }
382 inputstmt { int intv; }
383 : INPUTSYM [ semiprompt readlist
384 | '#' intvalue(&intv)
385 { setchannel(ival); }
390 semiprompt { int str; }
391 : semi STRVALUE { str = yylval.integer; }
392 [ ';' { loadstr(str);
395 | ',' { loadstr(str);
409 letstmt { int var; int exp; }
411 variable(&var) { save_address(); }
412 '=' expression(&exp) { assign(var,exp); }
414 variable(&var) { save_address(); }
415 '=' expression(&exp) { assign(var,exp); }
418 lineinputstmt { int var; int intv; }
421 semiprompt { setchannel(-1); }
422 variable(&var) { linestmt(var); }
424 intvalue(&intv) { setchannel(ival); }
426 variable(&var) { linestmt(var); }
435 : variable(&var) { readelm(var); }
438 lsetstmt { int var; int exp; }
439 : LSETSYM variable(&var) '=' expression(&exp)
444 : MIDSYM '$' midparms '=' expression(&exp)
446 C_asp((arith) (2*BEMINTSIZE + 2*BEMPTRSIZE));
450 midparms: '(' midfirst midsec midthird ')'
453 midfirst { int exp; }
454 : expression(&exp) { conversion(exp,STRINGTYPE); }
458 : ',' expression(&exp) { conversion(exp,INTTYPE); }
461 midthird { int exp; }
462 : ',' expression(&exp) { conversion(exp,INTTYPE); }
463 | /* empty */ { C_loc((arith) -1); }
472 exceptionstmt: ERRORSYM GOTOSYM INTVALUE { exceptstmt(ival); }
475 ongotostmt { int exp; }
477 [ GOSUBSYM constantlist { ongosubstmt(exp); }
478 | GOTOSYM constantlist { ongotostmt(exp); }
482 constantlist: INTVALUE { jumpelm(ival); }
483 [ ',' INTVALUE { jumpelm(ival); }
487 openstmt { int exp; }
488 : OPENSYM mode openchannel expression(&exp)
489 { conversion(exp,STRINGTYPE); }
490 [ /* empty */ { openstmt(0); }
491 | INTVALUE { openstmt(ival); }
495 openchannel: cross INTVALUE ',' { setchannel(ival); }
499 : expression(&exp) ',' { conversion(exp,STRINGTYPE); }
500 | ',' { C_lae_dnam("_iomode",(arith)0); }
503 optionstmt { int intv; }
504 : OPTIONSYM BASESYM intvalue(&intv) { optionbase(ival); }
507 printstmt { int plist; }
509 [ /* empty */ { setchannel(-1);
512 | file format printlist(&plist)
520 : '#' intvalue(&intv) ',' { setchannel(ival); }
521 | /* empty */ { setchannel(-1); }
526 [ STRVALUE { loadstr(yylval.integer); } ';'
528 { if(var!=STRINGTYPE)
529 error("string variable expected");
532 | /* empty */ { formatstring=0; }
535 printlist(int *ip;) { int exp; }
536 : [ expression(&exp) { printstmt(exp); *ip=1; }
537 | ',' { zone(1); *ip=0; }
538 | ';' { zone(0); *ip=0; }
542 pokestmt { int exp1; int exp2 ; }
546 expression(&exp2) { pokestmt(exp1,exp2); }
549 randomizestmt { int exp; }
551 [ /* empty */ { C_cal("_randomi"); }
553 { conversion(exp,INTTYPE);
555 C_asp((arith) BEMINTSIZE);
560 readstmt { int var; }
561 : READSYM { setchannel(0); }
562 variable(&var) { readelm(var); }
563 [ ',' variable(&var) { readelm(var); }
567 restorestmt : RESTORESYM
568 [ INTVALUE { restore(ival); }
569 | /* empty */ { restore(0); }
573 swapstmt { int var1; int var2; }
577 variable(&var2) { swapstmt(var1,var2); }
580 whilestmt { int exp; }
581 : WHILESYM { whilestart(); }
582 expression(&exp) { whiletst(exp); }
585 wendstmt : WENDSYM { wend(); }
589 [ /* empty */ { setchannel(-1);
592 | file writelist { C_cal("_wrnl"); }
596 writelist { int exp; }
597 : expression(&exp) { writestmt(exp,0); }
598 [ ',' expression(&exp) { writestmt(exp,1); }
602 cross: '#' | /* empty */ ;
605 : INTVALUE { *ip = yylval.integer; }
608 variable(int *ip;) { Symbol *symp; int exp; }
610 [ %avoid /* empty */ { *ip = loadaddr(symp); }
611 | '(' { newarrayload(symp); }
612 expression(&exp) { loadarray(exp); }
613 [ ',' expression(&exp) { loadarray(exp); } ]*
614 ')' { *ip = endarrayload(); }
616 | ERRSYM { C_lae_dnam("_errsym",(arith) 0);
619 | ERLSYM { C_lae_dnam("_erlsym",(arith) 0);
624 expression(int *ip;) { int neg; } /* NIEUW */
625 : expression1(&neg) { *ip = neg; }
628 expression(&neg) { *ip = boolop(*ip,neg,IMPSYM); }
633 expression1(int *ip;) { int neg; }
634 : expression2(&neg) { *ip = neg; }
636 expression2(&neg) { *ip = boolop(*ip,neg,EQVSYM); }
640 expression2(int *ip;) { int neg; }
641 : expression3(&neg) { *ip = neg; }
643 expression3(&neg) { *ip = boolop(*ip,neg,XORSYM); }
647 expression3(int *ip;) { int neg; }
648 : expression4(&neg) { *ip = neg; }
650 expression4(&neg) { *ip = boolop(*ip,neg,ORSYM); }
654 expression4(int *ip;) { int neg; }
655 : negation(&neg) { *ip = neg; }
657 negation(&neg) { *ip = boolop(*ip,neg,ANDSYM); }
661 negation(int *ip;) { int comp; }
662 : NOTSYM compare(&comp) { *ip=boolop(comp,0,NOTSYM); }
666 compare(int *ip;) { int sum1,sum2,rel; }
668 [ /* empty */ { *ip = sum1; }
669 | RELOP { rel=yylval.integer; }
670 sum(&sum2) { *ip=relop(sum1,sum2,rel); }
671 | '=' sum(&sum2) { *ip=relop(sum1,sum2,'='); }
675 sum(int *ip;) { int term1; }
676 : term(&term1) { *ip = term1; }
678 '-' term(&term1) { *ip=plusmin(*ip,term1,'-'); }
679 | '+' term(&term1) { *ip=plusmin(*ip,term1,'+'); }
683 term(int *ip;) { int fac1; }
684 : factor(&fac1) { *ip = fac1; }
685 [ '*' factor(&fac1) { *ip=muldiv(*ip,fac1,'*'); }
686 | '\\' factor(&fac1) { *ip=muldiv(*ip,fac1,'\\'); }
687 | '/' factor(&fac1) { *ip=muldiv(*ip,fac1,'/'); }
688 | MODSYM factor(&fac1) { *ip=muldiv(*ip,fac1,MODSYM); }
693 : '-' factor(ip) { *ip=negate(*ip); }
697 factor1(int *ip;) { int mant,exp; }
699 [ /* empty */ { *ip = mant; }
700 | '^' factor1(&exp) { *ip = power(mant,exp); }
705 { int var,func,expl,funcc,exp,intv,funcn,inpt; int typetable[10]; }
706 : INTVALUE { *ip=loadint(ival); }
707 | '(' expression(&exp) ')' { *ip=exp; }
708 | FLTVALUE { *ip=loaddbl(dval); }
711 loadstr(yylval.integer);
717 | INKEYSYM '$' { C_cal("_inkey");
718 C_lfr((arith) BEMPTRSIZE);
721 | VARPTR '(' '#' intvalue(&intv) ')'
722 { warning("Not supported");
725 | FUNCTION { func=yylval.integer; }
726 [ %avoid /* empty */ { *ip= callfcn(yylval.integer,0, typetable); }
727 | '(' cross exprlist(&expl, typetable) ')'
728 { *ip=callfcn(func,expl, typetable); }
731 [ %avoid /* empty */ { *ip=fcnend(0); }
732 | funccall(&funcc) ')' { *ip=fcnend(funcc); }
734 | MIDSYM '$' midparms
737 C_asp((arith) (2*BEMINTSIZE+BEMPTRSIZE));
738 C_lfr((arith) BEMPTRSIZE);
741 | INPUTSYM '$' '(' expression(&exp) inputtail(&inpt)
742 { /*waar worden inpt en exp gebruikt?*/
744 C_asp((arith) (2*BEMINTSIZE+BEMPTRSIZE));
749 inputtail(int *ip;) { int exp; }
750 : ',' cross expression(&exp) ')'
751 { conversion(exp,INTTYPE);
761 : FUNCTID { *ip=fcncall(yylval.Sptr); }
764 funccall(int *ip;) { int exp; }
765 : '(' expression(&exp) { callparm(0,exp);*ip=1; }
766 [ ',' expression(&exp) { callparm(*ip,exp);
772 identifier(Symbol **ident;)
773 : IDENTIFIER { dcltype(yylval.Sptr);
778 exprlist(int *ip; int *typetable;) { int exp; }
779 : expression(&exp) { typetable[0]=exp;
782 [ ',' expression(&exp) { typetable[*ip]=exp;
790 static char rcs_id[] = "$Id: basic.g,v 1.3 1994/06/24 11:30:24 ceriel Exp $" ;