class Exp { Tokens tokens; public Exp parse(Tokens tokens) throws SyntaxError { this.tokens = tokens; return parseExp(null); } public Exp parseExp(Exp left) throws SyntaxError { if (tokens.atEnd()) if (left == null) throw new SyntaxError ("expression"); else return left; else if (tokens.nextIs("+")) { tokens.eat("+"); Exp right = parseExp(null); return parseExp(new Plus(left, right)); } else { if (tokens.nextIs("*")) { tokens.eat ("*"); Exp right = parseExp(null); return parseExp(new Times(left, right)); } else { if (tokens.nextIs("(")) { tokens.eat("("); Exp subexp = parseExp(null); tokens.eat(")"); return parseExp(subexp); } else { if (tokens.nextIs(")")) { return left; } else { try { String s = tokens.next(); int i = Integer.parseInt(s); return parseExp(new Constant(i)); } catch (NumberFormatException e) { throw new SyntaxError ("integer"); } } } } } } public void compile() {} }