public static void Main(string[] args) { bool refreshEnv = false; bool showSexp = false; bool showExpr = false; List <string> files = new List <string>(); foreach (string arg in args) { if (arg.Substring(0, 1) == "-") { switch (arg) { case "-r": case "--refreshEnv": refreshEnv = true; break; case "-v": case "--verbose": showSexp = true; showExpr = true; break; default: Console.Error.WriteLine("Unrecognized commandline option: " + arg); break; } } else { files.Add(arg); } } Environment env = GetStartEnv(refreshEnv); Val result = new NumV(-1); foreach (string file in files) { SExpression sexp = new SExpOpenXML(file); if (showSexp) { Console.WriteLine("Lexical Analyzer Output:"); Console.WriteLine(sexp.ToString()); } ExprC prog = Parser.parse(sexp); if (showExpr) { Console.WriteLine("Parser Output:"); Console.WriteLine(prog.ToString()); } result = prog.interp(env); } Console.WriteLine(result.ToString()); }
public static Environment addArgsToEnv(List <String> parms, List <ExprC> args, Environment cloEnv, Environment outerEnv) { if (parms.Count == args.Count) { Environment newEnv = outerEnv.withLocals(cloEnv); // scope to know all calling vars for (int i = 0; i < parms.Count; i++) { String param = parms[i]; ExprC arg = args[i]; Val argVal = arg.interp(outerEnv); newEnv.SetLocal(param, argVal); // overwrite params if var name exists } return(newEnv); } else { throw new InterpException("Calling mismatched argument count"); } }
public CloV(Environment env, ExprC body, List <string> parms) { this.env = env; this.body = body; this.parms = parms; }
public NegC(ExprC num) { this.num = num; }
public IfC(ExprC check, ExprC t, ExprC f) { this.check = check; this.t = t; this.f = f; }
public BindC(ExprC lexpr, ExprC rexpr) { this.lexpr = lexpr; this.rexpr = rexpr; }
public IndexC(ExprC arr, List <ExprC> indices) { this.arr = arr; this.indices = indices; }
public FuncC(ExprC func, List <ExprC> args) { this.func = func; this.args = args; }