Exemplo n.º 1
0
 //This method is used to add elements between follow sets
 public void addSet(FollowSet source, FollowSet target)
 {
     foreach (Symbol terminal in source.Terminals)
     {
         target.Terminals.Add(terminal);
     }
 }
Exemplo n.º 2
0
    // This method is used to define follow set algorithm.
    public FollowSet FOLLOW(Symbol symbol)
    {
        FollowSet followSetBNonTerminal = new FollowSet();

        foreach (Production production in this.grammar.productions)
        {
            foreach (Symbol nonTerminal in this.grammar.nonTerminals)
            {
                foreach (Tuple <Symbol, Symbol> terminals in this.grammar.getTerminalPairs())
                {
                    string TNTRHS = this.grammar.getForm(terminals, nonTerminal, "TNT");
                    string TNRHS  = this.grammar.getForm(terminals.Item1, nonTerminal, "TN");

                    if (nonTerminal.ToString().Equals(TNTRHS))
                    {
                        followSetBNonTerminal.NonTerminal = nonTerminal;
                        followSetBNonTerminal.Terminals   = this.FIRST(terminals.Item2);
                    }

                    if (nonTerminal.ToString().Equals(TNRHS) || (nonTerminal.ToString().Equals(TNTRHS) && this.FIRST(terminals.Item2).Contains(Symbol.getEmptyWord())))
                    {
                        this.addSet(this.FOLLOW(terminals.Item2), this.FOLLOW(production.getSymbolicLHS()));
                    }
                }
            }
        }

        return(followSetBNonTerminal);
    }
 public override TokenSet Init_FollowSet(ParseNode_Root parser, TokenSet succ)
 {
     if (FollowSet == null)
     {
         followChanged = true;
         FollowSet     = new TokenSet(succ);
     }
     else if (FollowSet.Add(succ))
     {
         followChanged = true;
     }
     return(FirstSet);
 }
    public string ToString(ParseNode_Root parser)
    {
        var result = new StringBuilder(m_sNtName + " : " + rhs + " .");

        if (FirstSet != null)
        {
            result.Append("\n  lookahead " + FirstSet.ToString(parser));
        }
        if (FollowSet != null)
        {
            result.Append("\n  follow " + FollowSet.ToString(parser));
        }
        return(result.ToString());
    }