int expr() { int mode; int id1; int ixarr; int ids; if (istoken(T_CONST)) {doconst(); return 1; } mode=typeName(); /*0=V,1=*,2=&*/ if (token=='(') {docall1(); goto e1; } if (isreg()) goto e1; id1=searchname(); gettypes(id1); ids=signi; ixarr=0; if (istoken('[')) { ixarr=searchname(); expect(T_NAME); expect(']'); gettypes(ixarr); if (widthi==0) error1("Arrayindex muss int sein"); } if (istoken(T_PLUSPLUS )) {if(mode)error1("Nur var erlaubt");doinc();goto e1;} if (istoken(T_MINUSMINUS)) {if(mode)error1("Nur var erlaubt");dodec();goto e1;} if (istoken(T_PLUSASS )) {compoundass("add", mode); goto e1;} if (istoken(T_MINUSASS )) {compoundass("sub", mode); goto e1;} if (istoken(T_ANDASS )) {compoundass("and", mode); goto e1;} if (istoken(T_ORASS )) {compoundass("or" , mode); goto e1;} if (istoken(T_MULASS )) {error1("nicht implementiert");} if (istoken(T_DIVASS )) {error1("nicht implementiert");} if (istoken('=')) { isconst=expr(); if (isconst) { if(mode==0) {prs("\n;++++ mov "); printName(id1); prs(", "); prnum(lexval); } } doassign(mode, id1, ixarr); goto e1;} dovar1(mode, "mov", ixarr, id1); e1: if (istoken('+')) rterm("add"); else if (istoken('-')) rterm("sub" ); else if (istoken('&')) rterm("and" ); else if (istoken('|')) rterm("or" ); else if (istoken(T_LESSLESS)) rterm("shl"); else if (istoken(T_GREATGREAT)) rterm("shr"); else if (istoken('*')) domul (ids); else if (istoken('/')) doidiv(ids); else if (istoken('%')) domod (ids); if (isrelational()) { rterm("cmp"); cmpneg(ids);} return 0; }
int main(int argc, char *argv[]) { int n; int i; char *p; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", buffer); p = buffer; while (*p >= '0' && *p <= '9') p++; if (*p == '+' || *p == '-') doaddsub(buffer, (int)(p - buffer), p + 1, strlen(p + 1), *p); else if (*p == '*') domul(buffer, (int)(p - buffer), p + 1, strlen(p + 1)); printf("\n"); } return 0; }