Пример #1
0
        /// <summary>
        /// Prepare the lexer
        /// </summary>
        private static void PrepareLexer()
        {
            AntlrInputStream inputStream = new AntlrInputStream(streamReader);

            lexer = new GrammarLexer(inputStream);
            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new GrammarErrorListener(handler));
        }
Пример #2
0
        static void Main(string[] args)
        {
            StreamReader pom = new System.IO.StreamReader("../../../sourceCode.txt");

            AntlrInputStream inputStream = new AntlrInputStream(pom);
            GrammarLexer     lexer       = new GrammarLexer(inputStream);

            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new GrammarErrorListener());
            CommonTokenStream c           = new CommonTokenStream(lexer);
            GrammarParser     helloParser = new GrammarParser(c);

            //IParseTree tree = helloParser.start();
            // ParseTreeWalker walker = new ParseTreeWalker();
            //walker.Walk(new TreeWalkerListener(), tree);
            helloParser.RemoveErrorListeners();
            helloParser.AddErrorListener(new GrammarErrorListener());


            Console.WriteLine("START");

            try
            {
                IParseTree tree = helloParser.start();
                Console.WriteLine("----------------Lexical analyzation OK----------------------");

                Visitor visitor = new Visitor();
                visitor.DoInitialJmp(1);
                int t = visitor.Visit(tree);
                visitor.numberInstructions();

                Console.WriteLine(visitor.GetSymbolTable().VarConstToString());
                Console.WriteLine("-----------------------------------------");
                PrintInstructions(visitor.GetInstructions());
                WriteInstructions(visitor.GetInstructions());
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }



            Console.ReadLine();
            // skvelej napad, jednopruchod znamena dolu i nahoru, takze dolu udelam jen neco a smerem nahoru zbytek
        }