Example #1
0
        public static string Evaluate(string expression, int var)
        {
            MNRProgram Prog  = new MNRProgram(var);
            var        lexer = new Combined1Lexer(new AntlrInputStream(expression));

            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new ThrowExceptionErrorListener());
            var tokens  = new CommonTokenStream(lexer);
            var parser  = new Combined1Parser(tokens);
            var tree    = parser.compileUnit();
            var visitor = new Combined1Visitor(Prog, var);

            visitor.Visit(tree);
            return(Prog.GetProgram());
        }
Example #2
0
        static void Main(string[] args)
        {
            string text = "";

            // to type the EOF character and end the input: use CTRL+D, then press <enter>
            text = File.ReadAllText("input.txt");
            AntlrInputStream  inputStream       = new AntlrInputStream(text.ToString());
            Combined1Lexer    speakLexer        = new Combined1Lexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(speakLexer);
            Combined1Parser   speakParser       = new Combined1Parser(commonTokenStream);
            IParseTree        tree = speakParser.compileUnit();

            AstNodePrinter.Print(tree);
            //Console.WriteLine(tree.ToStringTree());
            //ParseTreeWalker walker = new ParseTreeWalker();
            //walker.Walk(new TestWalker(), tree);
        }