Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Grammar filename needed as argument.");
                return;
            }

            var fileName = args[0];

            try
            {
                var grammar = GrammarReader.ReadGrammarFromFile(fileName);
                LR0AutomataCreator.TryCreateAutomata(grammar);

                Console.WriteLine("ANO");
            }
            catch (RedRedConflictException)
            {
                Console.WriteLine("NIE - konflikt REDUKCIA/REDUKCIA");
            }
            catch (PresunRedConflictException)
            {
                Console.WriteLine("NIE - konflikt PRESUN/REDUKCIA");
            }
        }
Ejemplo n.º 2
0
        public void SearchFor(string searchTerm)
        {
            LALRParser lalrParser = GrammarReader.CreateNewParser();

            _wiqlBuilder    = new WiqlBuilder();
            _fieldName      = "";
            _comparisonType = FieldComparison.Contains;

            lalrParser.OnTokenRead  += new LALRParser.TokenReadHandler(lalrParser_OnTokenRead);
            lalrParser.OnParseError += new LALRParser.ParseErrorHandler(lalrParser_OnParseError);
            lalrParser.OnTokenError += new LALRParser.TokenErrorHandler(lalrParser_OnTokenError);
            lalrParser.Parse(searchTerm);
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            Grammar grammar;

            while (true)
            {
                try
                {
                    grammar = GrammarReader.ReadGrammar();
                    break;
                }
                catch
                {
                    Console.WriteLine("Неверный формат ввода");
                }
            }

            Console.WriteLine("Грамматика G:");
            Console.Write("\nVn: { ");
            for (var i = 0; i < grammar.VN.Count - 1; ++i)
            {
                Console.Write($"{grammar.VN[i]}, ");
            }
            Console.Write($"{grammar.VN.Last()} }}");
            Console.Write("\nVt: { ");
            for (var i = 0; i < grammar.VT.Count - 1; ++i)
            {
                Console.Write($"{grammar.VT[i]}, ");
            }
            Console.Write($"{grammar.VT.Last()} }}");
            Console.WriteLine("\nПравила: ");
            foreach (var rule in grammar.Rules)
            {
                Console.WriteLine($"{rule.LeftSide} -> {rule.RightSide}");
            }

            var solver = new FirstFollowFinder(grammar);

            int k;

            while (true)
            {
                Console.Write("Введите k: ");
                var res = int.TryParse(Console.ReadLine(), out k);
                if (res && k > 0)
                {
                    break;
                }
            }

            Console.WriteLine("\nFIRSTk для нетерминалов:");
            var firsts = solver.FirstForNonterminal(k);

            foreach (var nt in firsts.Keys)
            {
                Console.Write($"FIRST({nt}): {{ ");
                foreach (var e in firsts[nt])
                {
                    if (e == "ε")
                    {
                        Console.Write("epsilon");
                    }
                    else
                    {
                        Console.Write($"{e}");
                    }


                    if (firsts[nt].IndexOf(e) != firsts[nt].Count - 1)
                    {
                        Console.Write($",");
                    }

                    Console.Write(" ");
                }
                Console.WriteLine("}");
            }

            Console.WriteLine("\nFOLLOWk для нетерминалов:");
            var follows = solver.FollowForNonterminal(k);

            foreach (var nt in follows.Keys)
            {
                Console.Write($"FOLLOW({nt}): {{ ");
                foreach (var e in follows[nt])
                {
                    if (e == "ε")
                    {
                        Console.Write("epsilon");
                    }
                    else
                    {
                        Console.Write($"{e}");
                    }

                    if (follows[nt].IndexOf(e) != follows[nt].Count - 1)
                    {
                        Console.Write($",");
                    }

                    Console.Write(" ");
                }
                Console.WriteLine("}");
            }
        }
Ejemplo n.º 4
0
        public static int Main(string[] args)
        {
            Console.WriteLine("Tenuto Verifier");

            if (args.Length == 0)
            {
                Console.WriteLine(
                    "Usage: Tenuto <schema> <document1> [<document2> ...]");
                return(-1);
            }

            string    grammarName = null;
            ArrayList documents   = new ArrayList();

            // parse command line
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i][0] != '-')
                {
                    if (grammarName == null)
                    {
                        grammarName = args[i];
                    }
                    else
                    {
                        documents.Add(args[i]);
                    }
                }
                else
                {
                    // options
                    if (args[i] == "-debug")
                    {
                        Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
                        continue;
                    }

                    Console.WriteLine("unrecognized option: " + args[i]);
                    return(-1);
                }
            }

            Console.WriteLine("loading " + grammarName);
            Grammar.Grammar grammar = new GrammarReader(
                new ConsoleController()).parse(grammarName);
            if (grammar == null)
            {
                Console.WriteLine("bailing out");
                return(-1);
            }
//		Console.WriteLine( Grammar.ExpPrinter.printGrammar(grammar) );

            bool noError = true;

            for (int i = 0; i < documents.Count; i++)
            {
                string url = (string)documents[i];
                Console.WriteLine("validating " + url);

                bool wasValid = Verifier.Verifier.Verify(
                    new XmlTextReader(url), grammar, new ConsoleErrorReporter());
                noError &= wasValid;

                if (wasValid)
                {
                    Console.WriteLine("document is valid");
                }
                else
                {
                    Console.WriteLine("document is not valid");
                }
            }

            return(noError?0:1);
        }