Exemplo n.º 1
0
        void Main(string[] args)
        {
            var code             = "3 - (4)";
            var antlrInputStream = new AntlrInputStream(code);
            var lexer            = new Combined1Lexer(antlrInputStream);
            var cts    = new CommonTokenStream(lexer);
            var parser = new Combined1Parser(cts);



            var visitor = new MyVisitor();

            Console.WriteLine(visitor.Visit(parser.expression()));

            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var code             = "3 - (4)";
            var antlrInputStream = new AntlrInputStream(code);
            var lexer            = new Combined1Lexer(antlrInputStream);
            var cts    = new CommonTokenStream(lexer);
            var parser = new Combined1Parser(cts);


            var dynamicMethod = new DynamicMethod("test", typeof(int), Type.EmptyTypes);
            var il            = dynamicMethod.GetILGenerator();

            var visitor = new MyVisitor(il);

            visitor.Visit(parser.expression());
            il.Emit(OpCodes.Ret);

            var method = (Func <int>)dynamicMethod.CreateDelegate(typeof(Func <int>));

            Console.WriteLine(method());

            Console.ReadKey();
        }