Пример #1
0
 public void SetNextToken(String Token, bool Terminal)
 {
     if (Token == null || Token.Equals(""))
     {
         act.SetNext(new RuleEpsilon(Start));
     }
     else
     {
         if (Terminal)
         {
             act.SetNext(new RuleTerminal(Token, Start));
         }
         else
         {
             act.SetNext(new RuleToken(Token, Start));
         }
     }
     act = act.GetNext();
 }
Пример #2
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();
            }
        }