コード例 #1
0
        private MyArrayList TotalRuleFollowSet(RuleStart rs)
        {
            MyArrayList res = new MyArrayList();

            rs = GoToFirstStartRule(rs);
            while (rs != null)
            {
                res = ParseHelper.UnionSet(res, rs.GetRuleConnect().FollowSet);
                rs  = rs.GetAlternate();
            }
            return(res);
        }
コード例 #2
0
 private bool IsLeftRecursionInStartToken(RuleStart rs)
 {
     while (rs != null)
     {
         if (IsRuleLeftRekursiv(rs))
         {
             return(true);
         }
         rs = rs.GetAlternate();
     }
     return(false);
 }
コード例 #3
0
//		protected virtual void GenerateAllFirstSets()
//		{
//			for(int i=0;i<m_Rules.Count;i++)
//			{
//				BNFRule bnfRl = (BNFRule)m_Rules[i];
//				RuleStart strt = bnfRl.GetStart();
//				strt.GetRuleConnect().FirstSet = GenerateFirstSet(strt);
//			}
//		}

//		protected virtual void CheckEpsilonInRules()
//		{
//			for(int i=0;i<m_Rules.Count;i++)
//			{
//				BNFRule bnfRl = (BNFRule)m_Rules[i];
//				RuleStart strt = bnfRl.GetStart();
//				RuleIsEpsilonFree(strt);
//			}
//		}

        protected bool TotalRuleEpsFree(RuleStart rs)
        {
            rs = GoToFirstStartRule(rs);
            while (rs != null)
            {
                if (!rs.GetRuleConnect().EpsilonFree)
                {
                    return(false);
                }
                rs = rs.GetAlternate();
            }
            return(true);
        }
コード例 #4
0
        protected virtual MyArrayList GenerateFirstSet(RuleStart rs)
        {
            MyArrayList res = new MyArrayList();
            RuleElement re  = null;

            if (rs != null)
            {
                re = rs.GetNext();
            }
            else
            {
                return(null);
            }

            while (re != null)
            {
                if (re.GetToken().Equals(""))
                {
                    re = re.GetNext();
                }
                else
                {
                    if (re.IsTerminal())
                    {
                        res.Add(re);
                        return(res);
                    }
                    else
                    {
                        RuleToken   rt     = (RuleToken)re;
                        RuleStart   conStr = GoToFirstStartRule(rt.GetConnected());
                        MyArrayList res2   = null;
                        while (conStr != null)
                        {
                            res2   = GenerateFirstSet(conStr);
                            res    = ParseHelper.UnionSet(res, res2);
                            conStr = conStr.GetAlternate();
                        }
                        if (TotalRuleEpsFree(rt.GetConnected()))
                        {
                            return(res);
                        }
                        else
                        {
                            re = re.GetNext();
                        }
                    }
                }
            }
            return(res);
        }
コード例 #5
0
        private void DeleteStartRule(RuleStart rs)
        {
            BNFRule   bnfRl   = rs.GetRuleConnect();
            RuleStart AltNext = rs.GetAlternate();
            RuleStart AltBack = rs.GetAlternateBack();

            if (AltBack != null)
            {
                AltBack.SetAlternate(AltNext);
            }
            if (AltNext != null)
            {
                AltNext.SetAlternateBack(AltBack);
            }
            int index = bnfRl.Index;

            m_Rules.RemoveAt(index);
        }
コード例 #6
0
        private bool SetAllFollows(RuleStart rs, MyArrayList Follows)
        {
            bool changed = false;

            rs = GoToFirstStartRule(rs);
            while (rs != null)
            {
                int FlwSize = 0;
                if (rs.GetRuleConnect().FollowSet != null)
                {
                    FlwSize = rs.GetRuleConnect().FollowSet.Count;
                }
                rs.GetRuleConnect().FollowSet = ParseHelper.UnionSet(rs.GetRuleConnect().FollowSet, Follows);
                FlwSize = rs.GetRuleConnect().FollowSet.Count - FlwSize;
                if (FlwSize != 0)
                {
                    changed = true;
                }
                rs = rs.GetAlternate();
            }
            return(changed);
        }
コード例 #7
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();
            }
        }