static void morestmts() { if(token ==';'){ next_token(); stmtlist(); } }
static void program() { switch(token){ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case '!': stmtlist(); break; default: ERROR("Invalid program\n"); } if (token != '.') { ERROR("Program error. Current input symbol is %c\n", token); exit(EXIT_FAILURE); }; }
static void morestmts() { if(token == ';'){ next_token(); stmtlist(); } /* YOUR CODE GOES HERE */ }
static void program() { stmtlist(); if (token != '.') { ERROR("Program error. Current input symbol is %c\n", token); exit(EXIT_FAILURE); }; }
/*(1) PGM ::= STMTLIST END */ int parse() { step(); step(); /* initialize this and next */ if(test&2) printf("Enter parse--this=%d, next=%d\n", this, next); if(!stmtlist()) return F; if(this!=END) return F; reduce(1); if(test&2) printf("Leave parse\n"); return T; }
/* (8) STMT ::= DOHEAD STMT WHILE ( EXP ) ; */ int stmt() { if(test&2) printf("Enter stmt--this=%d next=%d\n", this, next); if(next==EQUALS) { /* stmt (5) */ if(!target()) return F; step(); /* past EQUALS */ if(!exp()) return F; if(this!=SEMIC) return F; step(); /* past SEMIC */ reduce(5); if(test&2) printf("Leave stmt(5)\n"); return T; } else if(this==LBRACE) { /* stmt (6) */ step(); /* past LBRACE */ if(!stmtlist()) return F; if(this!=RBRACE) return F; step(); /* past RBRACE */ reduce(6); if(test&2) printf("Leave stmt(6)\n"); return T; } else if(this==WHILE) { /* stmt (7) added by D. Burger */ if (!while2()) return F; if (!stmt()) return F; reduce(7); if (test&2) printf("Leave stmt(7)\n"); return T; } else if(this==DO) { /* stmt (8) added by D. Burger */ if (!dohead()) return F; if (!stmt()) return F; if (this!=WHILE) return F; step(); /* past WHILE */ if (this!=LPAREN) return F; step(); /* past LPAREN */ if (!exp()) return F; if (this!=RPAREN) return F; step(); /* past RPAREN */ if (this!=SEMIC) return F; step(); /* past SEMIC */ if (test&2) printf("Leave stmt(8)\n"); reduce(8); return T; } else { /* stmt (4) */ if(!exp()) return F; if(this!=SEMIC) return F; step(); /* past SEMIC */ reduce(4); if(test&2) printf("Leave stmt(4)\n"); return T; } }
static void morestmts() { switch (token) { case ';': next_token(); stmtlist(); case ' ': case '.': return; } }
static void morestmts() { switch(token){ case ';': next_token(); stmtlist(); break; case '.': return; default: ERROR("Unexpected token %c\n", token); exit(EXIT_FAILURE); } }
static void program() { switch (token) { case '%': case '&': case '#': case 'a': case 'b': case 'c': case 'd': stmtlist(); break; default: ERROR("Syntax error: Expected stmtlist.\n"); } if (token != '.') { ERROR("Program error. Current input symbol is %c\n", token); exit(EXIT_FAILURE); } }