コード例 #1
0
        protected MyArrayList BetaTotalRuleFirstSet(RuleElement re)
        {
            MyArrayList BetaFirst = new MyArrayList();

            while (re != null)
            {
                if (re.IsTerminal())
                {
                    BetaFirst.Add(re);
                    return(BetaFirst);
                }
                else
                {
                    if (re.GetToken().Length > 0)
                    {
                        RuleToken rt = (RuleToken)re;
                        if (rt != null)
                        {
                            RuleStart   conStr   = GoToFirstStartRule(rt.GetConnected());
                            MyArrayList FirstSet = TotalRuleFirstSet(conStr);
                            BetaFirst = ParseHelper.UnionSet(BetaFirst, FirstSet);
                            if (TotalRuleEpsFree(rt.GetConnected()))
                            {
                                return(BetaFirst);
                            }
                        }
                    }
                }
                re = re.GetNext();
            }
            return(BetaFirst);
        }
コード例 #2
0
 protected bool BetaTotalRuleEpsFree(RuleElement re)
 {
     while (re != null)
     {
         if (re.IsTerminal())
         {
             return(true);
         }
         else
         {
             if (re.GetToken().Length > 0)
             {
                 RuleToken rt = (RuleToken)re;
                 if (TotalRuleEpsFree(rt.GetConnected()))
                 {
                     return(true);
                 }
             }
             else
             {
                 return(false);
             }
         }
         re = re.GetNext();
     }
     return(false);
 }
コード例 #3
0
        private MyArrayList GenerateFollowList(MyArrayList NonTerms)
        {
            MyArrayList Follows = new MyArrayList();

            for (int i = 0; i < NonTerms.Count; i++)
            {
                RuleElement re     = (RuleElement)NonTerms[i];
                RuleStart   rs     = re.GetBegin();
                BNFRule     rl     = rs.GetRuleConnect();
                RuleElement nextRe = re.GetNext();
                if (nextRe == null)
                {
                    Follows = ParseHelper.UnionSet(Follows, rl.FollowSet);
                }
                else
                {
                    if (nextRe.IsTerminal())
                    {
                        Follows.Add(nextRe);
                    }
                    else
                    {
                        RuleToken   rt          = (RuleToken)nextRe;
                        MyArrayList AllFirstSet = BetaTotalRuleFirstSet(rt);
                        Follows = ParseHelper.UnionSet(Follows, AllFirstSet);
                        if (!BetaTotalRuleEpsFree(rt))
                        {
                            Follows = ParseHelper.UnionSet(Follows, rl.FollowSet);
                        }
                    }
                }
            }
            return(Follows);
        }
コード例 #4
0
 private void ConnectToken2Start(MyArrayList StartTokens, MyArrayList AllRuleTokens)
 {
     for (int i = 0; i < AllRuleTokens.Count; i++)
     {
         RuleToken rlTkn      = (RuleToken)AllRuleTokens[i];
         RuleStart rlStartTkn = FindStartTokenList(StartTokens, rlTkn);
         if (rlStartTkn != null)
         {
             rlStartTkn = GoToFirstStartRule(rlStartTkn);
             rlTkn.SetConnected(rlStartTkn);
         }
     }
 }
コード例 #5
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);
        }
コード例 #6
0
        private RuleStart FindStartTokenList(MyArrayList StartTokens, RuleToken rlTkn)
        {
            RuleStart rlStrt = null;

            for (int i = 0; i < StartTokens.Count; i++)
            {
                RuleStart rlStartTkn = (RuleStart)StartTokens[i];
                if (rlTkn.GetToken().Equals(rlStartTkn.GetToken()))
                {
                    rlStrt = rlStartTkn;
                    break;
                }
            }
            return(rlStrt);
        }
コード例 #7
0
        protected virtual bool RuleIsEpsilonFree(RuleStart rs)
        {
            RuleElement re = null;

            if (rs != null)
            {
                re = rs.GetNext();
            }
            else
            {
                return(false);
            }
            while (re != null)
            {
                if (re.IsTerminal())
                {
                    rs.GetRuleConnect().EpsilonFree = true;
                    return(true);
                }
                else
                {
                    if (re.GetToken().Equals(""))
                    {
                        rs.GetRuleConnect().EpsilonFree = false;
                        return(false);
                    }
                    else
                    {
                        RuleToken rt  = (RuleToken)re;
                        bool      res = RuleIsEpsilonFree(rt.GetConnected());
                        if (res)
                        {
                            rs.GetRuleConnect().EpsilonFree = res;
                            return(res);
                        }
                        else
                        {
                            re = re.GetNext();
                        }
                    }
                }
            }
            rs.GetRuleConnect().EpsilonFree = false;
            return(false);
        }