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); }
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); }
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; } } } }
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); }
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); }
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); }
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); }
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 UniteFirstsets(MyArrayList FndHuellen, MyArrayList Huelle) { if (FndHuellen != null && Huelle != null) { for (int i = 0; i < FndHuellen.Count; i++) { int fndHuellenNr = (int)FndHuellen[i]; MyArrayList Huelle2 = (MyArrayList)m_Huellen[fndHuellenNr]; for (int j = 0; j < Huelle2.Count; j++) { LR1Element lrm1 = (LR1Element)Huelle2[j]; int Pos = GetRuleInsideHuelle(Huelle, lrm1); if (Pos >= 0) { LR1Element lrm2 = (LR1Element)Huelle[Pos]; lrm2.FirstSet = ParseHelper.UnionSet(lrm2.FirstSet, lrm1.FirstSet); } } } } }
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); }
protected override void Closure(MyArrayList Huelle) { bool bChanged = true; if (Huelle != null) { while (bChanged) { bChanged = false; for (int i = 0; i < Huelle.Count; i++) { LR1Element LrElm = (LR1Element)Huelle[i]; RuleElement re = GetRuleElement(LrElm); if (re != null && !re.IsTerminal() && re.GetToken().Length > 0) { RuleElement reLH = GetRuleElement(LrElm, m_LH); MyArrayList FrstSet = null; if (reLH == null) { FrstSet = LrElm.FirstSet; } else { FrstSet = BetaTotalRuleFirstSet(reLH); if (!BetaTotalRuleEpsFree(reLH)) { FrstSet = ParseHelper.UnionSet(FrstSet, LrElm.FirstSet); } } if (FirstClosureFromRule(Huelle, re.GetToken(), FrstSet)) { bChanged = true; } } } } } }