Пример #1
0
        static void Main(string[] args)
        {
            bool showAST = true;

            if (args.Length == 1)
            {
                // prepare
                string filename   = args[0];
                string outputName = Path.ChangeExtension(filename, ".vxa");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // parse source file
                StreamReader sr    = new StreamReader(filename);
                Lexer        l     = new Lexer(sr);
                Parser       p     = new Parser(l);
                Start        start = p.Parse();

                RuntimeEnvironment env = new RuntimeEnvironment();
                try
                {
                    // Apply compiler phases
                    Weeding weeder = new Weeding();
                    weeder.Env = env;
                    start.Apply(weeder);

                    Environments envs = new Environments();
                    envs.mEnv = env;
                    start.Apply(envs);

                    //TypeChecking buildTEnv = new TypeChecking();
                    //start.Apply(buildTEnv);

                    //EnvironmentBuilding buildEnv = new EnvironmentBuilding();
                    //start.Apply(buildEnv);

                    CodeEmissionPhase emission = new CodeEmissionPhase();
                    emission.mEnv = env;
                    start.Apply(emission);
                    string code = emission.Emit(outputName);

                    if (showAST)
                    {
                        ASTDisplay disp = new ASTDisplay();
                        start.Apply(disp);
                        ASTDisplayForm form = new ASTDisplayForm();
                        form.env = env;
                        form.treeView1.Nodes.Add(disp.result);
                        form.showCode(code);
                        Application.Run(form);
                    }
                }
                catch (OutOfMemoryException e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
Пример #2
0
    public static void Main(String[] args)
    {
        Lexer  l = new Lexer(new StreamReader(args[0]));
        Parser p = new Parser(l);
        Start  s = p.Parse();

        TextPrinter printer = new TextPrinter();

        if (args.Length > 0 && args[0] == "-ansi")
        {
            printer.SetColor(true);
        }

        //s.Apply(printer);

        int indexOfLastDot  = args[0].LastIndexOf('.');
        int extensionLength = args[0].Length - indexOfLastDot;

        string output = args[0].Remove(indexOfLastDot, extensionLength);

        CodeGenerator cg = new CodeGenerator(new StreamWriter(output + ".il"));

        //CodeGenerator cg = new CodeGenerator(Console.Out);
        s.Apply(cg);

        //comment out later
        // Console.ReadLine();
    }
Пример #3
0
    public static void Main(String[] args)
    {
        Lexer  l = new Lexer(new StreamReader(args[0]));
        Parser p = new Parser(l);

        Start s = p.Parse();

        TextPrinter printer = new TextPrinter();

        if (args.Length > 0 && args[0] == "-ansi")
        {
            printer.SetColor(true);
        }

        s.Apply(printer);

        SemanticAnalyzer sa = new SemanticAnalyzer();

        s.Apply(sa);
        //Console.WriteLine("Press anykey to close...");
        //Console.ReadKey();
    }
Пример #4
0
    public static void Main(String[] args)
    {
        Lexer  l = new Lexer(Console.In);
        Parser p = new Parser(l);
        Start  s = p.Parse();

        TextPrinter printer = new TextPrinter();

        if (args.Length > 0 && args[0] == "-ansi")
        {
            printer.SetColor(true);
        }

        s.Apply(printer);
    }