Пример #1
0
        public static string GenerateMSIL(ITree programNode, Context context1)
        {
            MSILGenerator g = new MSILGenerator(programNode);
            //g.NumVariables();
            context = context1;

            g.Generate();
            return g.msil.ToString();
        }
Пример #2
0
        public static string GenerateMSIL(ITree programNode, Context context1)
        {
            MSILGenerator g = new MSILGenerator(programNode);

            //g.NumVariables();
            context = context1;

            g.Generate();
            return(g.msil.ToString());
        }
Пример #3
0
        public static void Main(string[] args)
        {
            try {
                // в зависимости от наличия параметров командной строки разбираем
                // либо файл с именем, переданным первым параметром, либо стандартный ввод
                Context context = new Context(null);
                string  src     = @"
            void printInt(int a) { }
            void printDouble(double a) { }
            double sqrt(double a) { }
            double sqr(double a) { }
            int readInt() { }
            double readDouble() { } 
        ";

                //Check(src, context);

                src = args.Length == 1 ? new StreamReader(args[0]).ReadToEnd()
                               : Console.In.ReadToEnd();
                ICharStream       input  = new ANTLRStringStream(src);
                MathExprLexer     lexer  = new MathExprLexer(input);
                CommonTokenStream tokens = new CommonTokenStream(lexer);
                MathExprParser    parser = new MathExprParser(tokens);
                parser.TreeAdaptor = new AstNodeTreeAdapter();
                ITree program = (ITree)parser.execute().Tree;
                AstNodePrinter.Print(program);
                Console.WriteLine();
                SemanticChecker.Check((AstNode)program, context);
                AstNodePrinter.Print(program);
                //Console.ReadLine();

                AstNodePrinter.Print(program);
                Console.WriteLine();
                string msil = MSILGenerator.GenerateMSIL(program, context);
                Console.WriteLine(msil);
                Console.WriteLine();
                Console.ReadLine();
            }
            catch (Exception e) {
                Console.WriteLine("Error: {0}", e);
                Console.ReadLine();
            }
        }