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); }
private bool IsTerminalPrefix(string Buf) { for (int i = 0; i < m_Terminals.Count; i++) { RuleTerminal rt = (RuleTerminal)m_Terminals[i]; if (IsPrefix(Buf, rt.GetToken())) { return(true); } } return(false); }
private RuleTerminal FindTerminal(string Buf) { for (int i = 0; i < m_Terminals.Count; i++) { RuleTerminal rt = (RuleTerminal)m_Terminals[i]; if (rt.GetToken().Equals(Buf)) { return(rt); } } return(null); }
private int GetColPos(string col) { for (int i = 0; i < m_Terminals.Count; i++) { RuleTerminal rt = (RuleTerminal)m_Terminals[i]; if (rt.GetToken().Equals(col)) { return(i); } } return(-1); }
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); }
public ASTElement Parse(string Input) { m_ParseVarlauf = ""; Input += m_EofSign; TerminalMatcher tm = new TerminalMatcher(Input, m_pt.Terminals); RuleTerminal ReadTerminal = tm.GetNextTerminal(); bool bAccept = false; while (!bAccept && ReadTerminal != null && !m_ps.IsEmpty && !ReadTerminal.Equals(m_EofSign)) { string tmpVerlauf = ReadTerminal.GetToken() + " ; " + m_ps.StackValues; m_ParseVerlaufArray.Add(m_ps.StackArray); ButtomUpParseStack.buStackElement stkElm = m_ps.Look(); if (stkElm != null) { if (stkElm.IsRuleElement) { tmpVerlauf += "err"; } else { int State = stkElm.GetState; ButtomUpParseTabelle.ActionEntry ae = m_pt.Get(ReadTerminal, State); if (ae != null) { if (ae.GetAction == ButtomUpParseTabelle.Actions.SHIFT) { tmpVerlauf += "; s " + ae.NextState.ToString(); m_ps.PushShift(ReadTerminal, ae.NextState); ReadTerminal = tm.GetNextTerminal(); } else if (ae.GetAction == ButtomUpParseTabelle.Actions.REDUCE) { int sm = ae.NextState; tmpVerlauf += "; r " + ae.NextState.ToString(); if (sm < m_ParseTable.AllRules.Count) { BNFRule rl = (BNFRule)m_ParseTable.AllRules[sm]; int RlLen = rl.RuleLength(); for (int i = 0; i < RlLen; i++) { m_ps.Pop2(); } ButtomUpParseStack.buStackElement stkLook = m_ps.Look(); if (stkLook != null) { int nxtState = m_ParseTable.GetGotoState(rl.GetStart(), stkLook.GetState); m_ps.PushReduce(rl.GetStart(), nxtState); tmpVerlauf += "; " + rl.GetRuleString(); } } } else if (ae.GetAction == ButtomUpParseTabelle.Actions.JUMP) { tmpVerlauf += "; err"; } else if (ae.GetAction == ButtomUpParseTabelle.Actions.ACCEPT) { tmpVerlauf += "; acc"; bAccept = true; } } } } m_ParseVarlauf += tmpVerlauf + "\n"; } return(m_ps.ASTRoot); }