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); }