Example #1
0
        static void test_scan(string path)
        {
            using (Reader file = new Reader(path)) {
                Scanner scanner = new Scanner(file);
                Attributes attrib;

                Console.WriteLine("scanning: {0}", path);
                do {
                    attrib = scanner.scan();

                    //if (attrib.token != Token.ERROR) {
                    //    if (Token.NUM == attrib.token) {
                    //        Console.WriteLine("{0} {1} {3} {4}", attrib.loc.PathPoint(), Enum.GetName(attrib.token.GetType(), attrib.token), (attrib.literal==null)?(""):("= "+attrib.literal), (attrib.error == null)?(""):("warning: "+attrib.error));
                    //    }
                    //} else {
                    Console.WriteLine("{0} error: {1} = {2}", attrib.loc.PathPoint(), attrib.error, attrib.literal);
                    //}

                } while (attrib.token != Token.EOF);
            }
        }
Example #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
        }
Example #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();
 }
Example #4
0
        static void test_safe_parse(string path)
        {
            using (Reader file = new Reader(path)) {
                //StringWriter writer = new StringWriter();
                //TopLevelWriter visitor = new TopLevelWriter(writer);
                VectVisitor visitor = new SafeVectorVisitor(null);
                Parser parser = new Parser(file, visitor);

                Console.WriteLine("parsing: {0}", path);
                parser.SafeRead();
                //Console.WriteLine(writer.ToString());
                //Console.WriteLine("{0} error{1}", parser.errors, parser.errors!=1?"s":"");
            }
        }
Example #5
0
        static void double_parse(string path)
        {
            using (Reader file = new Reader(path)) {
                StringWriter writer = new StringWriter();
                VectVisitor visitor = GetTopLevelWriter.create(writer);
                Parser parser = new Parser(file, visitor);

                parser.SafeRead();
                //Console.WriteLine("{0} error{1}", parser.errors, parser.errors!=1?"s":"");

                //if (parser.errors == 0) {
                using (System.IO.StreamWriter output1 = new System.IO.StreamWriter(path + ".parsed.txt", false)) {
                    output1.Write(writer.ToString());
                    //    }
                }
            }
        }
Example #6
0
 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();
 }
Example #7
0
        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();
        }
Example #8
0
 static void compare_files(string path1, string path2)
 {
     Console.WriteLine("comparing the token stream of {0} and {1}", path1, path2);
     using (Reader file1 = new Reader(path1)) {
         using (Reader file2 = new Reader(path2)) {
             Scanner s1 = new Scanner(file1);
             Scanner s2 = new Scanner(file2);
             Comparer comp = new Comparer(s1, s2);
             comp.run();
         }
     }
     Console.WriteLine();
 }
Example #9
0
        static object[] build(string path)
        {
            using (Reader file = new Reader(path)) {
                VectBox top = new VectBox();
                VectBuilder visitor = new VectBuilder(top);
                Parser parser = new Parser(file, visitor);

                Console.WriteLine("parsing: {0}", path);
                Console.WriteLine(parser.SafeRead() ? "OK" : "FAILED");
                //Console.WriteLine("{0} error{1}", parser.errors, parser.errors!=1?"s":"");
                //Console.WriteLine(parser.errors == 0 ? "OK" : "FAILED!");
                return top.value;
            }
        }