01: package expr.eval;
02:
03: import java.io.IOException;
04: import java.io.StringReader;
05: import beaver.Symbol;
06: import beaver.Parser;
07:
08: public class Calculator {
09: public static void main(String[] args) {
10: ExpressionScanner input = new ExpressionScanner(
11: new StringReader(args[0]));
12: try {
13: Expr result = (Expr) new ExpressionParser().parse(input);
14: System.out.println("= " + result.val);
15: } catch (IOException e) {
16: System.err.println("Failed to read expression: "
17: + e.getMessage());
18: } catch (Parser.Exception e) {
19: System.err.println("Invalid expression: " + e.getMessage());
20: }
21: }
22: }
|