Ejemplo n.º 1
0
        private static void AnalyseProgram(Grammar g, Dictionary <string, Dictionary <string, Rule> > parseTable)
        {
            Console.Write("Give path to program: ");
            string path    = Console.ReadLine();
            string program = File.ReadAllText(path);

            SymbolTable         sti = new SymbolTable();
            SymbolTable         stc = new SymbolTable();
            ProgramInternalForm pif = new ProgramInternalForm();

            LexicalAnalyzer.Analyze(program, sti, stc, pif);

            Console.WriteLine(pif);

            List <int> result = ParsingAlgorithm.LL1(parseTable, g, pif);

            if (result != null)
            {
                Console.WriteLine("Sequence accepted!\n");
                foreach (int index in result)
                {
                    Console.Write(index + " ");
                }
                Console.WriteLine("\n");
            }
            else
            {
                Console.WriteLine("Sequence NOT accepted!\n");
            }
        }
Ejemplo n.º 2
0
        private static void AnalyseSequence(Grammar g, Dictionary <string, Dictionary <string, Rule> > parseTable)
        {
            Console.Write("Give sequence: ");
            string     sequence = Console.ReadLine();
            List <int> result   = ParsingAlgorithm.LL1(parseTable, g, sequence);

            if (result != null)
            {
                Console.WriteLine("Sequence accepted!\n");
                foreach (int index in result)
                {
                    Console.Write(index + " ");
                }
                Console.WriteLine("\n");
            }
            else
            {
                Console.WriteLine("Sequence NOT accepted!\n");
            }
        }