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 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 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))); }
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))); }
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; }
/** * Compiles a statement (or a block). * <code>recordParams()</code> must be called before invoking * this method. * * <p>Local variables that are not declared * in the compiled source text might not be accessible within that * source text. Fields and method parameters ($0, $1, ..) are available. */ public void compileStmnt(String src) throws CompileError { Parser p = new Parser(new Lex(src)); SymbolTable stb = new SymbolTable(stable); while (p.hasMore()) { Stmnt s = p.parseStatement(stb); if (s != null) s.accept(gen); } }
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 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); }
/** * Compiles a statement (or a block). * <code>recordParams()</code> must be called before invoking * this method. * * <p>Local variables that are not declared * in the compiled source text might not be accessible within that * source text. Fields and method parameters ($0, $1, ..) are available. */ public void compileStmnt(String src) throws CompileError { Parser p = new Parser(new Lex(src)); SymbolTable stb = new SymbolTable(stable); while (p.hasMore()) { Stmnt s = p.parseStatement(stb); if (s != null) s.accept(gen); } }
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 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 return body; }
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); }
Parser p = new Parser(new Lex(src)); SymbolTable stb = new SymbolTable(stable); Stmnt s = p.parseStatement(stb); if (p.hasMore()) throw new CompileError(
private Stmnt parseFor(SymbolTable tbl) throws CompileError { Stmnt expr1, expr3; ASTree expr2; int t = lex.get(); // FOR SymbolTable tbl2 = new SymbolTable(tbl); if (lex.get() != '(') throw new SyntaxError(lex); if (lex.lookAhead() == ';') { lex.get(); expr1 = null; } else expr1 = parseDeclarationOrExpression(tbl2, true); if (lex.lookAhead() == ';') expr2 = null; else expr2 = parseExpression(tbl2); if (lex.get() != ';') throw new CompileError("; is missing", lex); if (lex.lookAhead() == ')') expr3 = null; else expr3 = parseExprList(tbl2); if (lex.get() != ')') throw new CompileError(") is missing", lex); Stmnt body = parseStatement(tbl2); return new Stmnt(t, expr1, new ASTList(expr2, new ASTList(expr3, body))); }
return Stmnt.make(LABEL, new Symbol(label), parseStatement(tbl));
Parser p = new Parser(new Lex(src)); SymbolTable stb = new SymbolTable(stable); Stmnt s = p.parseStatement(stb); if (p.hasMore()) throw new CompileError(
private Stmnt parseFor(SymbolTable tbl) throws CompileError { Stmnt expr1, expr3; ASTree expr2; int t = lex.get(); // FOR SymbolTable tbl2 = new SymbolTable(tbl); if (lex.get() != '(') throw new SyntaxError(lex); if (lex.lookAhead() == ';') { lex.get(); expr1 = null; } else expr1 = parseDeclarationOrExpression(tbl2, true); if (lex.lookAhead() == ';') expr2 = null; else expr2 = parseExpression(tbl2); if (lex.get() != ';') throw new CompileError("; is missing", lex); if (lex.lookAhead() == ')') expr3 = null; else expr3 = parseExprList(tbl2); if (lex.get() != ')') throw new CompileError(") is missing", lex); Stmnt body = parseStatement(tbl2); return new Stmnt(t, expr1, new ASTList(expr2, new ASTList(expr3, body))); }
return Stmnt.make(LABEL, new Symbol(label), parseStatement(tbl));
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 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); }