Esempio n. 1
0
        public static string ParseVerlaufArray2String(MyArrayList parseList)
        {
            string parseverlaufStr = "";

            if (parseList != null)
            {
                for (int i = 0; i < parseList.Count; i++)
                {
                    MyArrayList actStack = (MyArrayList)parseList[i];
                    if (actStack != null)
                    {
                        for (int j = 0; j < actStack.Count; j++)
                        {
                            RuleElement rl = (RuleElement)actStack[j];
                            if (rl.IsTerminal())
                            {
                                parseverlaufStr += "'" + rl.GetToken() + "'";
                            }
                            else
                            {
                                parseverlaufStr += rl.GetToken();
                            }
                            parseverlaufStr += " ";
                        }
                    }
                    parseverlaufStr += "\n";
                }
            }
            return(parseverlaufStr);
        }
Esempio n. 2
0
        private bool FirstClosureFromRule(MyArrayList Huelle, string Token, MyArrayList FirstSet)
        {
            bool        bChanged = false;
            MyArrayList TkRules  = base.GetStartRulesOneToken(Token);

            if (TkRules != null && Huelle != null)
            {
                for (int i = 0; i < TkRules.Count; i++)
                {
                    RuleStart rs      = (RuleStart)TkRules[i];
                    int       RuleNr  = rs.GetRuleConnect().Index;
                    int       HuelPos = RuleInsideHuelle(Huelle, RuleNr, 1);
                    if (HuelPos < 0)
                    {
                        LR1Element LrElm = new LR1Element(rs.GetRuleConnect().Index, m_HuellenCounter, m_LRMECnter++);
                        LrElm.FirstSet = FirstSet;
                        Huelle.Add(LrElm);
                        bChanged = true;
                    }
                    else
                    {
                        LR1Element LrElm    = (LR1Element)Huelle[HuelPos];
                        int        FrstSize = LrElm.FirstSet.Count;
                        LrElm.FirstSet = ParseHelper.UnionSet(LrElm.FirstSet, FirstSet);
                        if (FrstSize != LrElm.FirstSet.Count)
                        {
                            bChanged = true;
                        }
                    }
                }
            }
            return(bChanged);
        }
Esempio n. 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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 public TopDownParser(TopDownParseTabelle pt, RuleStart rs, string EOFSign)
 {
     m_pt = pt;
     m_rs = rs;
     m_ParseVerlaufArray = new MyArrayList();
     m_EofSign           = EOFSign;
 }
Esempio n. 6
0
        protected void GenerateAllFirstSets()
        {
            bool bChanged = true;

            while (bChanged)
            {
                bChanged = false;
                for (int i = 0; i < m_Rules.Count; i++)
                {
                    MyArrayList FirstSet = new MyArrayList();
                    BNFRule     bnfRl    = (BNFRule)m_Rules[i];
                    RuleStart   strt     = bnfRl.GetStart();
                    if (strt != null)
                    {
                        RuleElement re = strt.GetNext();
                        FirstSet = BetaTotalRuleFirstSet(re);
                    }
                    int FrstSize = 0;
                    if (strt.GetRuleConnect().FirstSet != null)
                    {
                        FrstSize = strt.GetRuleConnect().FirstSet.Count;
                    }
                    strt.GetRuleConnect().FirstSet = ParseHelper.UnionSet(strt.GetRuleConnect().FirstSet, FirstSet);
                    FrstSize = strt.GetRuleConnect().FirstSet.Count - FrstSize;
                    if (FrstSize != 0)
                    {
                        bChanged = true;
                    }
                }
            }
        }
Esempio n. 7
0
 protected int GetHuellenNr(MyArrayList Huelle)
 {
     if (Huelle != null && Huelle.Count > 0)
     {
         LRElement lrm = (LRElement)Huelle[0];
         return(lrm.HuellenNr);
     }
     return(-1);
 }
Esempio n. 8
0
        public SLR1ParseTable(MyArrayList Rules, string StartSign) : base(Rules, StartSign)
        {
            m_StartSign = FindUnusedToken(m_StartSign);
            BNFRule bnfRl = new BNFRule(m_Rules.Count);

            bnfRl.SetStart(m_StartSign);
            bnfRl.GetStart().SetNext(new RuleToken(StartSign, bnfRl.GetStart()));
            m_Rules.Add(bnfRl);
        }
Esempio n. 9
0
 public void AddCol()
 {
     for (int i = 0; i < m_rows; i++)
     {
         MyArrayList colArr = (MyArrayList)m_Tabelle[i];
         colArr.Add(new object());
     }
     m_cols++;
 }
Esempio n. 10
0
 public void AddArray(MyArrayList ArrCont)
 {
     if (ArrCont != null)
     {
         for (int i = 0; i < ArrCont.Count; i++)
         {
             Add(ArrCont[i]);
         }
     }
 }
Esempio n. 11
0
        private MyArrayList GetAllFollows()
        {
            MyArrayList Terminals = new MyArrayList();

            for (int i = 0; i < m_Rules.Count; i++)
            {
                BNFRule rl = (BNFRule)m_Rules[i];
                Terminals = ParseHelper.UnionSet(Terminals, rl.FollowSet);
            }
            return(Terminals);
        }
Esempio n. 12
0
 public bool Init()
 {
     if (m_pt != null)
     {
         m_ParseVarlauf      = "";
         m_ps                = new ButtomUpParseStack();
         m_ParseVerlaufArray = new MyArrayList();
         return(true);
     }
     return(false);
 }
Esempio n. 13
0
        public void AddRow()
        {
            MyArrayList OneRow = new MyArrayList();

            for (int j = 0; j < m_cols; j++)
            {
                OneRow.Add(new object());
            }
            m_Tabelle.Add(OneRow);
            m_rows++;
        }
Esempio n. 14
0
        protected void ConnectAlternateStartRules()
        {
            MyArrayList StartTokens = GetDifStartTokens();

            for (int i = 0; i < StartTokens.Count; i++)
            {
                RuleStart   strt          = (RuleStart)StartTokens[i];
                MyArrayList OneTokenRules = GetStartRulesOneToken(strt.GetToken());
                ConnectAlternateStartRules(OneTokenRules);
            }
        }
Esempio n. 15
0
        protected MyArrayList GetAllTerminals()
        {
            MyArrayList Terminals = new MyArrayList();

            for (int i = 0; i < m_Rules.Count; i++)
            {
                BNFRule rl = (BNFRule)m_Rules[i];
                Terminals = ParseHelper.UnionSet(Terminals, rl.GetAllTerminals());
            }
            return(Terminals);
        }
Esempio n. 16
0
        private MyArrayList GetNonTermsFrom(string NonTerm)
        {
            MyArrayList AllNonTerms = null;

            for (int i = 0; i < m_Rules.Count; i++)
            {
                BNFRule     rule    = (BNFRule)m_Rules[i];
                MyArrayList NonTrms = rule.FindToken(NonTerm);
                AllNonTerms = ParseHelper.AddList(AllNonTerms, NonTrms);
            }
            return(AllNonTerms);
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
        protected void ConnectTokens()
        {
            MyArrayList StartTokens = GetDifStartTokens();

            for (int i = 0; i < m_Rules.Count; i++)
            {
                BNFRule     rule    = (BNFRule)m_Rules[i];
                RuleStart   strt    = rule.GetStart();
                MyArrayList AllTkns = strt.GetAllTokens();
                ConnectToken2Start(StartTokens, AllTkns);
            }
        }
Esempio n. 19
0
 public object Get(int col, int row)
 {
     if (row >= 0 && row < m_Tabelle.Count)
     {
         MyArrayList colArr = (MyArrayList)m_Tabelle[row];
         if (col >= 0 && col < colArr.Count)
         {
             return(colArr[col]);
         }
     }
     return(null);
 }
Esempio n. 20
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);
         }
     }
 }
Esempio n. 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="re"></param>
 /// <param name="Nodes"></param>
 public ASTElement(RuleElement re, MyArrayList Nodes)
 {
     m_re       = re;
     m_Root     = null;
     m_NodeList = new MyArrayList();
     if (Nodes != null)
     {
         for (int i = 0; i < Nodes.Count; i++)
         {
             m_NodeList.Add(Nodes[i]);
         }
     }
 }
Esempio n. 22
0
        public void Push(RuleStart Transition)
        {
            MyArrayList TransRules = Rules2Array(Transition);

            for (int i = 0; i < TransRules.Count; i++)
            {
                RuleElement re = (RuleElement)TransRules[TransRules.Count - i - 1];
                m_Stack.Push(re);
                re = (RuleElement)TransRules[i];
                ASTElement astElm = m_ActRoot.AddNode(re);
                m_TreeStack.Push(astElm);
            }
        }
Esempio n. 23
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);
        }
Esempio n. 24
0
        public static MyArrayList ConcatList(MyArrayList Lst1, MyArrayList Lst2)
        {
            MyArrayList ConcatList = new MyArrayList();

            for (int i = 0; i < Lst1.Count; i++)
            {
                ConcatList.Add(Lst1[i]);
            }
            for (int i = 0; i < Lst2.Count; i++)
            {
                ConcatList.Add(Lst2[i]);
            }
            return(ConcatList);
        }
Esempio n. 25
0
        private MyArrayList CopyHuellen(MyArrayList arrOld)
        {
            MyArrayList newHuellen = new MyArrayList();

            if (arrOld != null)
            {
                for (int i = 0; i < arrOld.Count; i++)
                {
                    MyArrayList Huelle = (MyArrayList)arrOld[i];
                    newHuellen.Add(CopyHuelle(Huelle));
                }
            }
            return(newHuellen);
        }
Esempio n. 26
0
        protected MyArrayList GetStartRulesOneToken(string Token)
        {
            MyArrayList StartRuleList = new MyArrayList();

            for (int i = 0; i < m_Rules.Count; i++)
            {
                BNFRule rule = (BNFRule)m_Rules[i];
                if (Token.Equals(rule.GetStart().GetToken()))
                {
                    StartRuleList.Add(rule.GetStart());
                }
            }
            return(StartRuleList);
        }
Esempio n. 27
0
 public static bool IsRuleInTokenList(MyArrayList RuleList, RuleElement re2)
 {
     if (RuleList != null)
     {
         for (int i = 0; i < RuleList.Count; i++)
         {
             RuleElement re1 = (RuleElement)RuleList[i];
             if (re1.GetToken().Equals(re2.GetToken()))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 28
0
 public static bool IsTokenInTokenList(MyArrayList TokenLst, RuleElement Token)
 {
     if (TokenLst != null)
     {
         for (int i = 0; i < TokenLst.Count; i++)
         {
             RuleElement re = (RuleElement)TokenLst[i];
             if (Token.GetToken().Equals(re.GetToken()))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 29
0
        public MyArrayList GetAllTokens()
        {
            MyArrayList tokens = new MyArrayList();
            RuleElement re     = m_Next;

            while (re != null)
            {
                if (!re.IsTerminal() && !re.GetToken().Equals(""))
                {
                    tokens.Add(re);
                }
                re = re.GetNext();
            }
            return(tokens);
        }
Esempio n. 30
0
        private string[] Rule2String(RuleStart rs)
        {
            MyArrayList elements = new MyArrayList();

            if (rs != null)
            {
                RuleElement re = rs.GetNext();
                while (re != null)
                {
                    elements.Add(re.GetToken());
                    re = re.GetNext();
                }
            }
            return((string[])elements.ToArray(typeof(string)));
        }