예제 #1
0
        private void EleminateDirectLeftRecursion(RuleStart strt)
        {
            string ElemStartTkn = "";

            if (strt != null)
            {
                ElemStartTkn = FindUnusedToken(strt.GetToken());
            }
            while (strt != null)
            {
                if (IsRuleLeftRekursiv(strt))
                {
                    RuleElement re = strt.GetNext();
                    if (re != null)
                    {
                        strt.SetNext(re.GetNext());
                        re = GotoLastRule(strt);
                        re.SetNext(new RuleToken(ElemStartTkn, strt));
                        strt.SetToken(ElemStartTkn);
                    }
                    BNFRule bnfRl = new BNFRule(m_Rules.Count);
                    bnfRl.SetStart(ElemStartTkn);
                    bnfRl.GetStart().SetNext(new RuleEpsilon(bnfRl.GetStart()));
                    m_Rules.Add(bnfRl);
                }
                else
                {
                    RuleElement re = strt.GetNext();
                    if (re != null)
                    {
                        re = GotoLastRule(strt);
                        re.SetNext(new RuleToken(ElemStartTkn, strt));
                    }
                }
                strt = strt.GetAlternate();
            }
        }