public void copy(TxtLocation loc) { m_path = loc.m_path; column = loc.column; line = loc.line; m_context = loc.m_context; }
public LexicalError(TxtLocation loc, char cin, char peek, string message) : base(loc, message) { Data.Add("cin", cin); Data.Add("peek", peek); Data.Add("is_eof", '\0' == cin); }
public object apply(TxtLocation loc, Closure fn, object[] args) { try { return fn.fn(args); } catch (Exception e) { throw new InterpreterException(loc, "exception occured in method: " + fn.fn.Method.Name, e); } }
public object lookup(TxtLocation loc, Symbol sym) { object def; if (definitions.TryGetValue(sym, out def)) { return def; } else if (m_parent != null) { return m_parent.lookup(loc, sym); } else if (m_trap(sym, out def)) { return def; } else { throw new InterpreterException(loc, sym.name + " is undefined"); } }
public TxtException(TxtLocation loc, string message, Exception innerException) : base(message, innerException) { }
public TxtException(TxtLocation loc, string message) : base(message) { Data.Add("loc", loc); }
public TypeExpected(TxtLocation loc, string type) : base(loc, "internal error! expected object of type <" + type + ">") { }
static string make_message(TxtLocation loc, Token lookahead, Token[] tokens) { return String.Format( "{0}: expected {1} got {2}\n{3}\n", loc.PathPoint(), token_string(tokens), fancy_token(lookahead), loc.FancyContext()); }
public SyntaxError(TxtLocation loc, Token lookahead, params Token[] expected) : base(loc, make_message(loc, lookahead, expected)) { Data.Add("lookahead", lookahead); Data.Add("expected", expected); }
public InterpreterException(TxtLocation loc, string message) : base(loc, message) { }
static void compare_logs2(string path1, string path2) { Console.WriteLine("testing the multivisitor with files {0} and {1}", path1, path2); using (Reader file1 = new Reader(path1)) { using (Reader file2 = new Reader(path2)) { Log log1 = new Log(); Log log2 = new Log(); Util.TxtLocation loc1 = new Util.TxtLocation(path1); Util.TxtLocation loc2 = new Util.TxtLocation(path2); VectorLogger logger1 = new VectorLogger(log1, loc1, new SafeVectorVisitor(null)); VectorLogger logger2 = new VectorLogger(log2, loc2, new SafeVectorVisitor(null)); VectorMultiVisitor mv = new VectorMultiVisitor(logger1, logger2); Parser p1 = new Parser(file1, mv, loc1); p1.SafeRead(); LogComparer.compare_logs(log1, log2); } } Console.WriteLine(); }
public VectInterpreter(Environment env, TxtLocation loc, IBox outbox) : base(outbox) { m_env = env; m_loc = loc; }
public TopLevelVectInterpreter(Environment env, TxtLocation loc, Print print, IBox outbox) : base(env, loc, outbox) { m_print = print; }
public ArgsInterpreter(Environment env, TxtLocation loc, ListBox args) { m_env = env; m_loc = loc; m_args = args; }
public InterpreterException(TxtLocation loc, string message, Exception innerException) : base(loc, message, innerException) { }
public object transform(TxtLocation loc, SpecialForm m, object source) { try { return m.m(source); } catch (Exception e) { throw new InterpreterException(loc, "exception occured in special form: " + m.m.Method.Name, e); } }
static void compare_logs(string path) { Console.WriteLine("comparing the visitation logs for the parser and dynamic visitor for file {0}", path); Log log1 = new Log(); using (Reader file = new Reader(path)) { Util.TxtLocation loc = new Util.TxtLocation(path); VectorLogger logger = new VectorLogger(log1, loc, new SafeVectorVisitor(null)); Parser p = new Parser(file, logger, loc); p.SafeRead(); } Log log2 = new Log(); using (Reader file = new Reader(path)) { VectBox top = new VectBox(); VectBuilder builder = new VectBuilder(top); Parser p = new Parser(file, builder); Util.TxtLocation loc = new Util.TxtLocation(path); p.SafeRead(); VectorLogger logger = new VectorLogger(log2, loc, new SafeVectorVisitor(null)); if (top.value != null) DynamicVisitor.accept(top.value, logger); } LogComparer.compare_logs(log1, log2); Console.WriteLine(); }
public Parser(Reader reader, VectVisitor visitor, TxtLocation loc) { m_scanner = new Scanner(reader); m_visitor = visitor; m_loc = loc; }
static void Main(string[] args) { #if false Parent p = new Parent("Karen"); p.children.Add(null); p.children.Add(new Son("Jason")); p.children.Add(new Daughter("April")); ParentVisitor pv = new ParentVisitor(); DynamicVisitor.accept(p, pv); #endif #if false Console.WriteLine(Example1()); //Console.WriteLine(Example2()); ////Console.WriteLine(Example3()); ////Console.WriteLine(Example4()); ////Console.WriteLine(Example5()); //Console.WriteLine(Example6()); //test_parse("test.txt"); //test_parse("test2.txt"); //test_safe_parse("test.txt"); //test_safe_parse("test2.txt"); #endif #if false parse_and_write("test.txt", "test-output1.txt"); parse_and_write("test-output1.txt", "test-output2.txt"); compare_files("test.txt", "test-output1.txt"); compare_files("test-output1.txt", "test-output2.txt"); compare_logs("test.txt", "test-output1.txt"); compare_logs("test-output1.txt", "test-output2.txt"); parse_build_write("test.txt", "test-output3.txt"); compare_files("test.txt", "test-output3.txt"); compare_logs("test.txt", "test-output3.txt"); compare_logs2("test.txt", "test-output3.txt"); compare_logs("test.txt"); compare_logs("test-output1.txt"); compare_logs("test-output2.txt"); compare_logs("test-output3.txt"); compare_logs("test.txt", "test2.txt"); code_builder_test(code_builder_test1()); code_builder_test(code_builder_test2()); #endif #if false using (FileWriter writer = new FileWriter("construct1.txt")) { Code c = code_builder_test2(); Dictionary<string, string> aliases = new Dictionary<string, string>(); //aliases.Add("Sexp.Cons", "cons"); //aliases.Add("System.Object[]", "vector"); List<string> ns = new List<string>(); // ns.Add("Sexp"); // object[] test1 = build("test.txt"); // object[] test1 = ConstructLang.tour(build("test.txt"), ns, aliases); ns.Add("Flat"); aliases.Add("Flat.Type", ".type"); aliases.Add("Flat.Prototype", ".prototype"); aliases.Add("Flat.Operator", ".operator"); aliases.Add("Flat.Relation", ".relation"); aliases.Add("Flat.Constant", ".constant"); aliases.Add("Flat.Global", ".global"); aliases.Add("Flat.Local", ".local"); aliases.Add("Flat.Parameter", ".param"); aliases.Add("Flat.Do", ".do"); aliases.Add("Flat.Move", ".move"); aliases.Add("Flat.Call", ".call"); aliases.Add("Flat.DoLambda", ".gosub"); aliases.Add("Flat.If", ".if"); aliases.Add("Flat.Lambda", ".lambda"); aliases.Add("Flat.Operands", "<-"); aliases.Add("Flat.Lvalues", "->"); aliases.Add("Flat.Types", "types:"); aliases.Add("Flat.Prototypes", "prototypes:"); aliases.Add("Flat.Constants", "constants:"); aliases.Add("Flat.Globals", "globals:"); aliases.Add("Flat.Operators", "operators:"); aliases.Add("Flat.Relations", "relations:"); aliases.Add("Flat.Lambdas", "lambdas:"); aliases.Add("Flat.Listing", "listing:"); object[] test1 = ConstructLang.tour(c, ns, aliases); //VectorLogger logger = new VectorLogger(new Log(), new TxtLocation(""), GetTopLevelWriter.create(writer)); Format fmt = new Format(); //fmt.format_vect = true; //fmt.format_data = false; //fmt.format_head = false; //fmt.format_appl = true; //fmt.do_abbrev = true; //fmt.do_abbrev = false; //fmt.do_debug = true; ConstructFormat.init(writer); DynamicVisitor.accept(test1, GetTopLevelWriter.create(writer, fmt, ConstructFormat.get_construct_lang_config)); } // int foo = 2+2; #endif #if true //System.IO.TextWriter my_out = new System.IO.StreamWriter("output.txt"); //Console.SetOut(my_out); Reader f = new Reader("test4.txt"); Util.TxtLocation loc = new Util.TxtLocation("test4.txt"); Parser p = new Parser(f, new SafeVectorVisitor(new Interpreter(new StandardEnvironment(null/*delegate(Symbol sym, out object def) { def = null; return true; }*/), loc)), loc); p.Read(); Console.WriteLine(); //object[] v = build("test.txt"); //DynamicVisitor.accept(v, new IntVisitor()); //DynamicVisitor.accept(v, new Interpreter(new TestEnvironment(), null)); #endif }
public Interpreter(Environment env, TxtLocation loc) { m_env = env; m_loc = loc; }