public static Stmnt make(int op, ASTree oprand1, ASTree oprand2) { return new Stmnt(op, oprand1, new ASTList(oprand2)); }
private Stmnt parseWhile(SymbolTable tbl) throws CompileError { int t = lex.get(); // WHILE ASTree expr = parseParExpression(tbl); Stmnt body = parseStatement(tbl); return new Stmnt(t, expr, body); }
private Stmnt parseSwitch(SymbolTable tbl) throws CompileError { int t = lex.get(); // SWITCH ASTree expr = parseParExpression(tbl); Stmnt body = parseSwitchBlock(tbl); return new Stmnt(t, expr, body); }
private Stmnt parseStmntOrCase(SymbolTable tbl) throws CompileError { int t = lex.lookAhead(); if (t != CASE && t != DEFAULT) return parseStatement(tbl); lex.get(); Stmnt s; if (t == CASE) s = new Stmnt(t, parseExpression(tbl)); else s = new Stmnt(DEFAULT); if (lex.get() != ':') throw new CompileError(": is missing", lex); return s; }
private Stmnt parseThrow(SymbolTable tbl) throws CompileError { int t = lex.get(); // THROW ASTree expr = parseExpression(tbl); if (lex.get() != ';') throw new CompileError("; is missing", lex); return new Stmnt(t, expr); }
private Stmnt parseWhile(SymbolTable tbl) throws CompileError { int t = lex.get(); // WHILE ASTree expr = parseParExpression(tbl); Stmnt body = parseStatement(tbl); return new Stmnt(t, expr, body); }
private Stmnt parseBlock(SymbolTable tbl) throws CompileError { if (lex.get() != '{') throw new SyntaxError(lex); Stmnt body = null; SymbolTable tbl2 = new SymbolTable(tbl); while (lex.lookAhead() != '}') { Stmnt s = parseStatement(tbl2); if (s != null) body = (Stmnt)ASTList.concat(body, new Stmnt(BLOCK, s)); } lex.get(); // '}' if (body == null) return new Stmnt(BLOCK); // empty block else return body; }
private Stmnt parseSwitch(SymbolTable tbl) throws CompileError { int t = lex.get(); // SWITCH ASTree expr = parseParExpression(tbl); Stmnt body = parseSwitchBlock(tbl); return new Stmnt(t, expr, body); }
private Stmnt parseDeclarators(SymbolTable tbl, Declarator d) throws CompileError { Stmnt decl = null; for (;;) { decl = (Stmnt)ASTList.concat(decl, new Stmnt(DECL, parseDeclarator(tbl, d))); int t = lex.get(); if (t == ';') return decl; else if (t != ',') throw new CompileError("; is missing", lex); } }
public static Stmnt make(int op, ASTree op1, ASTree op2, ASTree op3) { return new Stmnt(op, op1, new ASTList(op2, new ASTList(op3))); }
private Stmnt parseThrow(SymbolTable tbl) throws CompileError { int t = lex.get(); // THROW ASTree expr = parseExpression(tbl); if (lex.get() != ';') throw new CompileError("; is missing", lex); return new Stmnt(t, expr); }
public MethodDecl parseMethod2(SymbolTable tbl, MethodDecl md) throws CompileError { Stmnt body = null; if (lex.lookAhead() == ';') lex.get(); else { body = parseBlock(tbl); if (body == null) body = new Stmnt(BLOCK); } md.sublist(4).setHead(body); return md; }
private Stmnt parseReturn(SymbolTable tbl) throws CompileError { int t = lex.get(); // RETURN Stmnt s = new Stmnt(t); if (lex.lookAhead() != ';') s.setLeft(parseExpression(tbl)); if (lex.get() != ';') throw new CompileError("; is missing", lex); return s; }
private Stmnt parseSynchronized(SymbolTable tbl) throws CompileError { int t = lex.get(); // SYNCHRONIZED if (lex.get() != '(') throw new SyntaxError(lex); ASTree expr = parseExpression(tbl); if (lex.get() != ')') throw new SyntaxError(lex); Stmnt body = parseBlock(tbl); return new Stmnt(t, expr, body); }
private Stmnt parseContinue(SymbolTable tbl) throws CompileError { int t = lex.get(); // CONTINUE Stmnt s = new Stmnt(t); int t2 = lex.get(); if (t2 == Identifier) { s.setLeft(new Symbol(lex.getString())); t2 = lex.get(); } if (t2 != ';') throw new CompileError("; is missing", lex); return s; }
private Stmnt parseDo(SymbolTable tbl) throws CompileError { int t = lex.get(); // DO Stmnt body = parseStatement(tbl); if (lex.get() != WHILE || lex.get() != '(') throw new SyntaxError(lex); ASTree expr = parseExpression(tbl); if (lex.get() != ')' || lex.get() != ';') throw new SyntaxError(lex); return new Stmnt(t, expr, body); }
private Stmnt parseSynchronized(SymbolTable tbl) throws CompileError { int t = lex.get(); // SYNCHRONIZED if (lex.get() != '(') throw new SyntaxError(lex); ASTree expr = parseExpression(tbl); if (lex.get() != ')') throw new SyntaxError(lex); Stmnt body = parseBlock(tbl); return new Stmnt(t, expr, body); }
private Stmnt parseIf(SymbolTable tbl) throws CompileError { int t = lex.get(); // IF ASTree expr = parseParExpression(tbl); Stmnt thenp = parseStatement(tbl); Stmnt elsep; if (lex.lookAhead() == ELSE) { lex.get(); elsep = parseStatement(tbl); } else elsep = null; return new Stmnt(t, expr, new ASTList(thenp, new ASTList(elsep))); }