public string Print() { string TableOut = ms_Seperator; for (int i = 0; i < m_Terminals.Count; i++) { RuleTerminal rt = (RuleTerminal)m_Terminals[i]; TableOut += rt.GetToken() + ms_Seperator; } TableOut += "\n"; for (int i = 0; i < m_StartTerms.Count; i++) { RuleElement re = (RuleElement)m_StartTerms[i]; TableOut += re.GetToken() + ms_Seperator; for (int j = 0; j < m_Terminals.Count; j++) { RuleTerminal rt = (RuleTerminal)m_Terminals[j]; RuleStart rs = Get(rt.GetToken(), re.GetToken()); if (rs == null) { TableOut += ms_Seperator; } else { TableOut += rs.GetAllElements() + ms_Seperator; } } TableOut += "\n"; } return(TableOut); }
public string GetRuleString(RuleElement Start, int PntPos) { string res = Start.GetToken() + "->"; RuleElement iterator = Start.GetNext(); int Pos = 1; while (iterator != null) { if (PntPos == Pos) { res += "."; } if (iterator.IsTerminal()) { res += "'" + iterator.GetToken() + "'"; } else { res += iterator.GetToken(); } iterator = iterator.GetNext(); if (iterator != null) { res += ","; } Pos++; } if (PntPos == Pos) { res += "."; } res += ";"; return(res); }
public string GetAllElements() { RuleElement re = m_Next; string Elements = ""; while (re != null) { if (re.GetToken().Length > 0) { if (re.IsTerminal()) { Elements += "\'" + re.GetToken() + "\',"; } else { Elements += re.GetToken() + ","; } } else { Elements += " ,"; } re = re.GetNext(); } return(Elements); }
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); }
internal bool IsSame(RuleElement ReElm, int ActState) { if (ReElm != null) { if (m_ReElm.GetToken().Equals(ReElm.GetToken()) && ActState == m_ActState) { return(true); } } return(false); }
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 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); }
public ASTElement Parse(string Input) { Input += m_EofSign; TerminalMatcher tm = new TerminalMatcher(Input, m_pt.Terminals); RuleTerminal ReadTerminal = tm.GetNextTerminal(); while (ReadTerminal != null && !m_ps.IsEmpty && !ReadTerminal.Equals(m_EofSign)) { string tmpVerlauf = ReadTerminal.GetToken() + " : " + m_ps.StackValues + "\n"; m_ParseVerlaufArray.Add(m_ps.StackArray); m_ParseVarlauf += tmpVerlauf; RuleElement re = m_ps.Pop(); if (re != null) { if (re.IsTerminal()) { if (ReadTerminal.GetToken().Equals(re.GetToken())) { } else { return(null); } ReadTerminal = tm.GetNextTerminal(); } else if (re.GetToken().Length > 0 && ReadTerminal != null && ReadTerminal.GetToken().Length > 0) { RuleStart rs = m_pt.Get(ReadTerminal.GetToken(), re.GetToken()); if (rs == null) { return(null); } m_ps.Push(rs); } } else { break; } } return(m_ps.ASTRoot); }
private int GetRowPos(string row) { for (int i = 0; i < m_StartTerms.Count; i++) { RuleElement re = (RuleElement)m_StartTerms[i]; if (re.GetToken().Equals(row)) { return(i); } } return(-1); }
public string Print() { string TableOut = ms_Seperator; for (int i = 0; i < m_Signs.Count; i++) { RuleElement re = (RuleElement)m_Signs[i]; TableOut += re.GetToken() + ms_Seperator; } TableOut += "\n"; for (int i = 0; i < m_rows; i++) { TableOut += i + ms_Seperator; for (int j = 0; j < m_Signs.Count; j++) { RuleElement re = (RuleElement)m_Signs[j]; ActionEntry ae = Get(re, i); if (ae == null) { TableOut += ms_Seperator; } else { if (ae.GetAction == Actions.SHIFT) { TableOut += "s " + ae.NextState + ms_Seperator; } else if (ae.GetAction == Actions.REDUCE) { TableOut += "r " + ae.NextState + ms_Seperator; } else if (ae.GetAction == Actions.JUMP) { TableOut += ae.NextState + ms_Seperator; } else if (ae.GetAction == Actions.ACCEPT) { TableOut += "acc" + ms_Seperator; } else { } } } TableOut += "\n"; } return(TableOut); }
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++) { ButtomUpParseStack.buStackElement stkElm = (ButtomUpParseStack.buStackElement)actStack[j]; if (stkElm.IsRuleElement) { RuleElement rl = stkElm.GetRule; if (rl.IsTerminal()) { parseverlaufStr += "'" + rl.GetToken() + "'"; } else { parseverlaufStr += rl.GetToken(); } parseverlaufStr += " "; } else { // parseverlaufStr += stkElm.GetState.ToString(); // parseverlaufStr+=" "; } } parseverlaufStr += "\n"; } } } return(parseverlaufStr); }
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); }
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; } } } } } }
private bool IsRuleLeftRekursiv(RuleStart rs) { RuleElement re = rs.GetNext(); if (re != null) { string StartToken = rs.GetToken(); string FirstToken = re.GetToken(); if (StartToken.Equals(FirstToken)) { return(true); } } return(false); }
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); }
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); }
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); }
private bool IsTokenInTokenList(MyArrayList RuleElementList, string Token) { if (RuleElementList != null && Token != null) { for (int i = 0; i < RuleElementList.Count; i++) { RuleElement re = (RuleElement)RuleElementList[i]; if (re != null && re.GetToken().Equals(Token)) { return(true); } } } return(false); }
public string GetRuleString() { string res = Start.GetToken() + "->"; RuleElement iterator = Start.GetNext(); while (iterator != null) { if (iterator.IsTerminal()) { res += "'" + iterator.GetToken() + "'"; } else { res += iterator.GetToken(); } iterator = iterator.GetNext(); if (iterator != null) { res += ","; } } res += "."; return(res); }
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))); }
protected virtual void Closure(MyArrayList Huelle) { bool bChanged = true; if (Huelle != null) { while (bChanged) { bChanged = false; for (int i = 0; i < Huelle.Count; i++) { LRElement LrElm = (LRElement)Huelle[i]; RuleElement re = GetRuleElement(LrElm); if (re != null && !re.IsTerminal() && re.GetToken().Length > 0) { if (FirstClosureFromRule(Huelle, re.GetToken())) { bChanged = true; } } } } } }
private string PrintFirst() { string res = "First={"; for (int i = 0; i < m_FirstSet.Count; i++) { RuleElement re = (RuleElement)m_FirstSet[i]; res += re.GetToken(); if (i + 1 != m_FirstSet.Count) { res += ","; } } res += "}"; return(res); }
private bool IsProdRuleInside(MyArrayList ProdTokens, RuleElement re) { if (ProdTokens != null && re != null) { for (int i = 0; i < ProdTokens.Count; i++) { RuleElement ProdRe = (RuleElement)ProdTokens[i]; if (ProdRe.GetToken().Equals(re.GetToken())) { return(true); } } } return(false); }
protected virtual bool GenerateParseTable() { MyArrayList Terminals = GetAllTerminals(); Terminals.Add(new RuleTerminal(m_EofTerminal, null)); MyArrayList StartTokens = GetDifStartTokens(); m_LL1ParseTabelle = new TopDownParseTabelle(Terminals, StartTokens); bool dblEntry = false; for (int i = 0; i < m_Rules.Count; i++) { BNFRule rl = (BNFRule)m_Rules[i]; RuleStart rs = rl.GetStart(); int len = rs.GetRuleConnect().FirstSet.Count; for (int j = 0; j < len; j++) { RuleElement re = (RuleElement)rs.GetRuleConnect().FirstSet[j]; string colSign = re.GetToken(); string rowSign = rs.GetToken(); if (!m_LL1ParseTabelle.Add(colSign, rowSign, rs)) { dblEntry = true; } } if (!rl.EpsilonFree) { len = rs.GetRuleConnect().FollowSet.Count; for (int j = 0; j < len; j++) { RuleElement re = (RuleElement)rs.GetRuleConnect().FollowSet[j]; string colSign = re.GetToken(); string rowSign = rs.GetToken(); if (!m_LL1ParseTabelle.Add(colSign, rowSign, rs)) { dblEntry = true; } } } } return(!dblEntry); }
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); }
public static string PrintRules(MyArrayList RuleList) { string retStr = "{"; if (RuleList != null) { for (int i = 0; i < RuleList.Count; i++) { RuleElement re = (RuleElement)RuleList[i]; retStr += re.GetToken(); if (i < RuleList.Count - 1) { retStr += ","; } } } return(retStr + "}"); }
private int GetColPos(string col) { if (col != null) { for (int i = 0; i < m_Signs.Count; i++) { RuleElement re = (RuleElement)m_Signs[i]; if (re != null) { if (re.GetToken().Equals(col) && re.IsTerminal()) { return(i); } } } } return(-1); }
/// <summary> /// Find all Tokens inside Rule /// </summary> /// <param name="Token">Token String to find</param> /// <returns></returns> public MyArrayList FindToken(string Token) { MyArrayList sr = new MyArrayList(); if (Start != null) { RuleElement pos = Start.GetNext(); while (pos != null) { if (pos.GetToken().Equals(Token)) { sr.Add(pos); } pos = pos.GetNext(); } } return(sr); }
private void TraverseTree(ASTElement Node) { if (Node != null) { RuleElement re = Node.rlElement; string Token = re.GetToken(); bool Terminal = re.IsTerminal(); ExecuteMethod(Token, Terminal); ASTElement tmpAst = null; int NodeNr = 0; do { tmpAst = Node.GetNextNode(NodeNr); TraverseTree(tmpAst); NodeNr++; }while(tmpAst != null); } }
protected virtual MyArrayList GetLrElm(MyArrayList Huelle, string Token) { MyArrayList LreElmLst = new MyArrayList(); if (Huelle != null) { for (int i = 0; i < Huelle.Count; i++) { LRElement LrElm = (LRElement)Huelle[i]; RuleElement re = GetRuleElement(LrElm); if (re != null) { if (re.GetToken().Equals(Token)) { LRElement nextLRElm = new LRElement(LrElm, m_HuellenCounter, m_LRMECnter++); LreElmLst.Add(nextLRElm); } } } } return(LreElmLst); }