void selector(symset, item*, int); void call(symset, int, int); int resulttype(int a, int b, int level){ if((a > reals) || (b > reals)){ error(33); return notyp; } else if((a == notyp) || (b == notyp))return notyp; if(a == ints) if(b == ints) return ints; else{ emit1(26,1); return reals; } else { if(b == ints) emit1(26,0); return reals; } }// end resulttypes void expression(symset fsys, item *x, int level){ item y; int op, it; symset addsym; typset addtyp; void simpleexpression(symset fsys, item *x){ item y; int op, it; symset addsym; symset addsym2; if ( lnfeedback == 1 ) printf("\n\t\t\t\t\t\t\tENTERING simpleexpression - 29\n"); void term(symset fsys, item *x){ item y; int op, it; symset addsym, addsym2; if ( lnfeedback == 1 ) printf("\n\t\t\t\t\t\t\t\tENTERING term - 30\n"); void factor(symset fsys, item *x){ int i,f,it; symset addsym, addsym2; if ( lnfeedback == 1 ) printf("\n\t\t\t\t\t\t\t\t\tENTERING factor - 31\n"); void standfct(int n){ typset ts; int it; symset addsym; if ( lnfeedback == 1 ) printf("\n\t\t\t\t\t\t\t\t\t\tENTERING standfct - 32\n"); for(it=0; it<8; it++) ts[it] = 0; if(sy == lparent) insymbol(); else error(9); if(n < 17) { for(it=0; it<52 ; it++) addsym[it] = fsys[it]; if(!testsym(addsym, rparent)) addsym[findindex(addsym)] = rparent; expression(addsym, x, level); switch(n){ case 0: case 2: ts[1] = ints; ts[2] = reals; tab[i].typ = x->typ; if(x->typ == reals) n = n + 1; break; case 4: case 5: ts[1] = ints; break; case 6: ts[1] = ints; ts[2] = bools; ts[3] = chars; break; case 7: case 8: ts[1] = chars; break; default: ts[1] = ints; ts[2] = reals; if(x->typ == ints) emit1(26, 0); break; } if(testtyp(ts, x->typ)) emit1(8, n); else if (x->typ != notyp) error(48); } else { if (sy != ident) error(2); else if(strcmp(id, "input ")) error(0); else insymbol(); emit1(8, n); } x->typ = tab[i].typ; if(sy == rparent) insymbol(); else error(4); }//end standfct //begin factor x->typ = notyp; x->ref = 0; test(facbegsys, fsys, 58); while(testsym(facbegsys, sy)){ if(sy == ident){ i = loc(id, level);insymbol(); switch(tab[i].obj){ case 0: // konstant x->typ = tab[i].typ; x->ref = 0; if(x->typ == reals) emit1(25, tab[i].adr); else emit1(24, tab[i].adr); break; case 1: // variable x->typ = tab[i].typ; x->ref = tab[i].ref; if (sy == lbrack || sy == lparent || sy == period){ if(tab[i].normal) f = 0; else f = 1; emit2(f, tab[i].lev, tab[i].adr); /*emit no exact number*/ selector(fsys, x, level); if(testtyp(stantyps, x->typ)) emit(34); } else { if (testtyp(stantyps, x->typ)) if(tab[i].normal) f = 1; else f = 2; else if(tab[i].normal) f = 0; else f = 1; emit2(f, tab[i].lev, tab[i].adr); /*emit no exact number*/ } break; case 2: // typel case 3: // prozedure: error(44);break; case 4: // funktion: x->typ = tab[i].typ; if(tab[i].lev) call(fsys, i, level); else standfct(tab[i].adr); break; } } else if(sy == charcon || sy == intcon || sy == realcon) { if(sy == realcon) { x->typ = reals; enterreal(rnum); emit1(25, c1); } else { if(sy == charcon) x->typ = chars; else x->typ = ints; emit1(24, inum); } x->ref = 0;insymbol(); } else if (sy == lparent) { insymbol(); for(it=0; it<52; it++) addsym[it] = fsys[it]; if(!testsym(addsym, rparent)) addsym[findindex(addsym)] = rparent; expression(addsym, x, level); if (sy == rparent) insymbol(); else error(4); } else if( sy == notsy){insymbol(); factor(fsys, x); if(x->typ == bools) emit(35); else if (x->typ != notyp) error(32); } test(fsys, facbegsys, 6); } }// end factor // begin term for(it=0; it<52; it++)addsym[it] = fsys[it]; if(!testsym(addsym, times)) addsym[findindex(addsym)] = times; if(!testsym(addsym, rdiv)) addsym[findindex(addsym)] = rdiv; if(!testsym(addsym, idiv)) addsym[findindex(addsym)] = idiv; if(!testsym(addsym, imod)) addsym[findindex(addsym)] = imod; if(!testsym(addsym, andsy)) addsym[findindex(addsym)] = andsy; factor(addsym, x); for(it=0; it<52; it++)addsym2[it] = 0; if(!testsym(addsym2, times)) addsym2[findindex(addsym2)] = times; if(!testsym(addsym2, rdiv)) addsym2[findindex(addsym2)] = rdiv; if(!testsym(addsym2, idiv)) addsym2[findindex(addsym2)] = idiv; if(!testsym(addsym2, imod)) addsym2[findindex(addsym2)] = imod; if(!testsym(addsym2, andsy)) addsym2[findindex(addsym2)] = andsy; while(testsym(addsym2, sy)){ op = sy; insymbol(); for(it=0; it<52; it++)addsym[it] = fsys[it]; if(!testsym(addsym, times)) addsym[findindex(addsym)] = times; if(!testsym(addsym, rdiv)) addsym[findindex(addsym)] = rdiv; if(!testsym(addsym, idiv)) addsym[findindex(addsym)] = idiv; if(!testsym(addsym, imod)) addsym[findindex(addsym)] = imod; if(!testsym(addsym, andsy)) addsym[findindex(addsym)] = andsy; factor(addsym, &y); if(op == times){ x->typ = resulttype(x->typ, y.typ, level); switch(x->typ){ case 0: break;// no typ case 1: emit(57);break;// ints case 2: emit(60);break;// reals } } else if (op == rdiv){ if(x->typ == ints){ emit1(26, 1); x->typ = reals; } if(y.typ == ints) { emit1(26, 0); y.typ = reals; } if((x->typ == reals) && (y.typ == reals)) emit(61); else { if ((x->typ != notyp) && (y.typ != notyp)) error(32); x->typ = notyp; } } else if(op == andsy) { if(x->typ == bools && y.typ == bools) emit(56); else { if(x->typ != notyp && y.typ != notyp) error(32); x->typ = notyp; } } else {// op idiv or imod if((x->typ == ints) && (y.typ == ints)) if(op == idiv) emit(58); else emit(59); else { if((x->typ != notyp) && (y.typ != notyp)) error(34); x->typ = notyp; } } } }// end term //begin simple expression if(sy == plus || sy == minus){ op = sy; insymbol(); for(it=0; it<52; it++) addsym[it] = fsys[it]; if (!testsym(addsym, plus)) addsym[findindex(addsym)] = plus; if (!testsym(addsym, minus)) addsym[findindex(addsym)] = minus; term(addsym, x); if (x->typ > reals) error(33); else if (op == minus) emit1(36, x->typ); } else { for(it=0; it<52; it++) addsym[it] = fsys[it]; if (!testsym(addsym, plus)) addsym[findindex(addsym)] = plus; if (!testsym(addsym, minus)) addsym[findindex(addsym)] = minus; if (!testsym(addsym, orsy)) addsym[findindex(addsym)] = orsy; term(addsym, x); } while(sy == plus || sy == minus || sy == orsy){ op = sy; insymbol(); for(it=0; it<52; it++) addsym2[it] = fsys[it]; if (!testsym(addsym2, plus)) addsym2[findindex(addsym2)] = plus; if (!testsym(addsym2, minus)) addsym2[findindex(addsym2)] = minus; if (!testsym(addsym2, orsy)) addsym2[findindex(addsym2)] = orsy; term(addsym2, &y); if (op == orsy){ if((x->typ == bools) && (y.typ == bools)) emit(51); else { if((x->typ != notyp) && (y.typ != notyp)) error(32); x->typ = notyp; } } else{ x->typ = resulttype(x->typ, y.typ, level); switch (x->typ){ case 0: // notyp break; case 1: // ints if(op == plus) emit(52); else emit(53); break; case 2: // reals if(op == plus) emit(54); else emit(55); break; } } } }//end Simpleexpression //begin expression if ( lnfeedback == 1 ) printf("\n\t\t\t\t\t\tENTERING expression - 33\n"); for(it=0; it<52; it++) addsym[it] = fsys[it]; if(!testsym(addsym, egl)) addsym[findindex(addsym)] = egl; if(!testsym(addsym, neg)) addsym[findindex(addsym)] = neg; if(!testsym(addsym, lss)) addsym[findindex(addsym)] = lss; if(!testsym(addsym, leg)) addsym[findindex(addsym)] = leg; if(!testsym(addsym, gtr)) addsym[findindex(addsym)] = gtr; if(!testsym(addsym, geg)) addsym[findindex(addsym)] = geg; simpleexpression(addsym, x); if(sy == egl || sy == neg || sy == lss || sy == leg || sy == gtr || sy == geg){ op = sy; insymbol(); simpleexpression(fsys, &y); if((x->typ == notyp || x->typ == ints || x->typ == bools || x->typ == chars) && (x->typ == y.typ)){ switch(op){ case 14: emit(45);break; // egl case 15: emit(46);break; // neg case 18: emit(47);break; // lss case 19: emit(48);break; // leg case 16: emit(49);break; // gtr case 17: emit(50);break; // geg } } else{ if(x->typ == ints){ x->typ = reals; emit1(26, 1); } else if(y.typ == ints){ y.typ = reals; emit1(26, 0); } if((x->typ == reals) && (y.typ == reals)) switch(op){ case 14: emit(39);break; // egl case 15: emit(40);break; // neg case 18: emit(41);break; // lss case 19: emit(42);break; // leg case 16: emit(43);break; // gtr case 17: emit(44);break; // geg } else error(35); } x->typ = bools; } }//end expression