Ejemplo n.º 1
0
 static void parse_build_write(string in_path, string out_path)
 {
     Console.WriteLine("parsing {0} into memory then writing it out to {1}", in_path, out_path);
     using (FileWriter writer = new FileWriter(out_path)) {
         object[] top = build(in_path);
         if (top != null) DynamicVisitor.accept(top, GetTopLevelWriter.create(writer));
     }
     Console.WriteLine();
 }
Ejemplo n.º 2
0
        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
        }
Ejemplo n.º 3
0
 static void parse_and_write(string in_path, string out_path)
 {
     Console.WriteLine("parsing {0} and writing it out to {1}", in_path, out_path);
     using (Reader file = new Reader(in_path)) {
         using (FileWriter writer = new FileWriter(out_path)) {
             VectVisitor visitor = GetTopLevelWriter.create(writer);
             Parser parser = new Parser(file, visitor);
             Console.WriteLine(parser.SafeRead() ? "OK" : "FAILED");
             //Console.WriteLine("{0} error{1}", parser.errors, parser.errors!=1?"s":"");
             //Console.WriteLine(parser.errors == 0 ? "OK" : "FAILED!");
         }
     }
     Console.WriteLine();
 }