Exemplo n.º 1
0
        public void CreateTableMatches(List <State> states)
        {
            var nonTerminals = _syntactic.GetNonTerminals();
            var terminals    = _syntactic.GetTerminals();
            var symbols      = new List <Symbol>();

            foreach (var nt in nonTerminals)
            {
                if (nt.Value != "Slinha")
                {
                    symbols.Add(nt);
                }
            }
            foreach (var t in terminals)
            {
                if (t.Type != SymbolType.Empty)
                {
                    symbols.Add(t);
                }
            }

            //Adiciona símbolo de Fim de Arquivo
            symbols.Add(new Symbol()
            {
                Type = SymbolType.EndOfFile, Value = "$"
            });
            //Colunas: Coluna de descrição, coluna para os Terminais e End of File

            //Linhas: Não Terminais
            _tableParser.ColumnsNumber = symbols.Count;
            _tableParser.RowsNumber    = states.Count();

            _tableParser.Symbols.AddRange(symbols);

            int termColumns = 0;
            int termRows    = 0;

            foreach (var s in states)
            {
                //pego as produções desse estado
                foreach (var VARIABLE in s.Productions)
                {
                    if (VARIABLE.Action == ActionType.Reduction)
                    {
                        Follow follow = _semantic.GetFollowList().Find(q => q.NonTerminal.Value == VARIABLE.Production.Producer.Value);
                        foreach (var f in follow.Terminals)
                        {
                            if (f.Type != SymbolType.Empty)
                            {
                                var match = new TableMatch();
                                match.StateNumber = s.Number;
                                match.CellValue   = " r" + VARIABLE.ActionNumber;
                                match.SymbolValue = f.Value;
                                if (_tableParser.Matches.Exists(m =>
                                                                m.StateNumber == match.StateNumber && m.SymbolValue == match.SymbolValue))
                                {
                                    var existingMatch = _tableParser.Matches.Find(m =>
                                                                                  m.StateNumber == match.StateNumber && m.SymbolValue == match.SymbolValue);
                                    //Cell já foi preenchida, verifica se é o mesmo valor
                                    if (existingMatch.CellValue != match.CellValue)
                                    {
                                        IsSLR = false;
                                    }
                                }
                                else
                                {
                                    _tableParser.Matches.Add(match);
                                }
                            }
                        }
                    }
                    else
                    {
                        var match = new TableMatch();
                        match.StateNumber = s.Number;
                        match.SymbolValue = VARIABLE.Marked.Symbol.Value;
                        match.CellValue   = VARIABLE.ActionNumber.ToString();
                        if (_tableParser.Matches.Exists(m =>
                                                        m.StateNumber == match.StateNumber && m.SymbolValue == match.SymbolValue))
                        {
                            var existingMatch = _tableParser.Matches.Find(m =>
                                                                          m.StateNumber == match.StateNumber && m.SymbolValue == match.SymbolValue);
                            //Cell já foi preenchida, verifica se é o mesmo valor
                            if (existingMatch.CellValue != match.CellValue)
                            {
                                IsSLR = false;
                            }
                        }
                        else
                        {
                            _tableParser.Matches.Add(match);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void btnFollow_Click(object sender, EventArgs e)
 {
     followForm = new FollowForm(_semantic.GetFollowList());
     followForm.ShowDialog();
 }