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); }
private bool IsLeftRecursionInStartToken(RuleStart rs) { while (rs != null) { if (IsRuleLeftRekursiv(rs)) { return(true); } rs = rs.GetAlternate(); } return(false); }
// 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); }
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); }
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); }
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); }
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(); } }