Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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");
            }
        }
Ejemplo n.º 3
0
 public CloV(Environment env, ExprC body, List <string> parms)
 {
     this.env   = env;
     this.body  = body;
     this.parms = parms;
 }
Ejemplo n.º 4
0
 public NegC(ExprC num)
 {
     this.num = num;
 }
Ejemplo n.º 5
0
 public IfC(ExprC check, ExprC t, ExprC f)
 {
     this.check = check;
     this.t     = t;
     this.f     = f;
 }
Ejemplo n.º 6
0
 public BindC(ExprC lexpr, ExprC rexpr)
 {
     this.lexpr = lexpr;
     this.rexpr = rexpr;
 }
Ejemplo n.º 7
0
 public IndexC(ExprC arr, List <ExprC> indices)
 {
     this.arr     = arr;
     this.indices = indices;
 }
Ejemplo n.º 8
0
 public FuncC(ExprC func, List <ExprC> args)
 {
     this.func = func;
     this.args = args;
 }