Exemple #1
0
    internal void DoFollow()     // NB: this is for the LR(0) parser construction
    {
        // Rule 1:
        m_symbols.m_startSymbol.m_follow.CheckIn(m_symbols.EOFSymbol);
        // Rule 2 & 3:
        bool donesome = true;

        while (donesome)
        {
            donesome = false;
            for (int k = 1; k < prods.Count; k++)
            {
                Production p = (Production)prods[k];
                int        n = p.m_rhs.Count;
                for (int j = 0; j < n; j++)
                {
                    CSymbol b = (CSymbol)p.m_rhs[j];
                    // Rule 2
                    p.AddFirst(b, j + 1);
                    // Rule 3
                    if (p.CouldBeEmpty(j + 1))
                    {
                        donesome |= b.AddFollow(p.m_lhs.m_follow);
                    }
                }
            }
        }
    }