using static System.Console; interface Expr { int eval(); } record Const(int i) : Expr { public int eval() => i; } record BinOp(Expr e, string op, Expr f) : Expr { public int eval() { int x = e.eval(), y = f.eval(); return op switch { "+" => x + y, "-" => x - y, "*" => x * y, "/" => x / y, "%" => x % y, _ => throw new Exception("bad operation") }; } } class Top { static void Main(string[] args) { if (args.Length < 1) { WriteLine("usage: p2 "); return; } Parser p = new(File.ReadAllText(args[0])); WriteLine(p.parse_expr().eval()); } }