Beispiel #1
0
        public void FirstAndFollow_Test()
        {
            //Buscar alguns terminais quaisquer

            /*
             * S:B c|D B
             * B:a b|c S
             * D:d|#
             */

            string grammarIdentifier = Symbol.GrammarIdentifier;

            Symbol.GrammarIdentifier = "3";

            //Gerar os firsts and follows
            NonRecursiveDealer nonRecursive = new NonRecursiveDealer();

            NonTerminal s = Symbol.NonTerminalHash["S"];

            //Testa todos os firsts de S
            Assert.IsTrue(s.FirstContains("a"));
            Assert.IsTrue(s.FirstContains("c"));
            Assert.IsTrue(s.FirstContains("d"));
            Assert.IsTrue(s.FirstContainsEmpty());
            //Testa todos os follows de S
            Assert.IsTrue(s.FollowContains("c"));
            Assert.IsTrue(s.FollowContainsInitial());

            s = Symbol.NonTerminalHash["B"];
            //Testa todos os firsts de B
            Assert.IsTrue(s.FirstContains("a"));
            Assert.IsTrue(s.FirstContains("c"));
            //Testa todos os follows de C
            Assert.IsTrue(s.FollowContains("c"));
            Assert.IsTrue(s.FollowContainsInitial());

            s = Symbol.NonTerminalHash["D"];
            //Testa todos os firsts de D
            Assert.IsTrue(s.FirstContains("d"));
            Assert.IsTrue(s.FirstContainsEmpty());
            ////Testa todos os follows de D
            Assert.IsTrue(s.FollowContains("a"));
            Assert.IsTrue(s.FollowContains("c"));

            Symbol.GrammarIdentifier = grammarIdentifier;
        }
        public FirstAndFollowForm()
        {
            InitializeComponent();

            //Carregar combobox
            NonRecursiveDealer nonRecursive = new NonRecursiveDealer();

            _nonTerminalHash = nonRecursive.NonTerminalHash;
            _nonTerminalList = nonRecursive.NonTerminals;

            comboBoxNonTerminals.Items.Clear();
            foreach (NonTerminal nonTerminal in _nonTerminalList)
            {
                comboBoxNonTerminals.Items.Add(nonTerminal);
            }

            comboBoxNonTerminals.SelectedIndexChanged += new System.EventHandler(this.comboBoxNonTerminals_SelectedIndexChanged);
        }