public bool addSubTree(int q_index, SSYaccStackElement q_ele) { if (q_index < 0 || q_index >= this.m_subTreeSize) { return(false); } this.m_subTree[q_index] = q_ele; return(true); }
public bool doReduce() { this.m_element = reduce(q_prod: this.m_production, q_length: this.m_productionSize); if (this.m_element == null) { return(true); } pop(q_pop: this.m_productionSize); return(goTo(q_goto: this.m_leftside)); }
public bool doShift() { this.m_element = shift(q_lexeme: this.m_lookahead); if (this.m_element == null) { return(true); } this.m_element.setLexeme(q_lexeme: this.m_lookahead); this.m_element.setState(q_state: this.m_state); push(); return(doGetLexeme(q_look: true)); }
public bool parse() { if (doGetLexeme(q_look: true)) { return(true); } while (!this.m_abort) { switch (this.m_action) { case 0: if (doShift()) { return(true); } continue; case 1: if (doError()) { return(true); } continue; case 2: if (doReduce()) { return(true); } continue; case 3: this.m_treeRoot = this.m_element; return(this.m_error); case 4: if (doConflict()) { return(true); } continue; default: return(true); } } return(true); }
public SSYacc(SSYaccTable q_table, SSLex q_lex) { this.m_cache = 0; this.m_lex = q_lex; this.m_abort = false; this.m_error = false; this.m_table = q_table; this.m_endOfInput = false; this.m_endLexeme = new SSLexLexeme(q_lexeme: "eof", q_token: -1); this.m_endLexeme.setToken(q_token: -1); this.m_stack = new SSYaccStack(q_size: 5, q_inc: 5); this.m_lexemeCache = new SSYaccCache(); this.m_element = stackElement(); push(); }
public bool push(SSYaccStackElement q_element) { this.m_stack.push(q_ele: q_element); return(true); }
public bool syncErr() { var ssYaccSet = new SSYaccSet(); for (var index = 0; index < this.m_stack.getSize(); ++index) { var ssYaccTableRow1 = this.m_table.lookupRow(q_state: ((SSYaccStackElement)this.m_stack.elementAt(index: index)).state()); if (ssYaccTableRow1.hasSync() || ssYaccTableRow1.hasSyncAll()) { for (var q_index = 0; q_index < ssYaccTableRow1.action(); ++q_index) { var yaccTableRowEntry = ssYaccTableRow1.lookupEntry(q_index: q_index); if (ssYaccTableRow1.hasSyncAll() || yaccTableRowEntry.hasSync()) { var num = yaccTableRowEntry.token(); ssYaccSet.add(q_object: num); } } } if (ssYaccTableRow1.hasError()) { var ssYaccTableRow2 = this.m_table.lookupRow(q_state: ssYaccTableRow1.lookupError().entry()); for (var q_index = 0; q_index < ssYaccTableRow2.action(); ++q_index) { var num = ssYaccTableRow2.lookupEntry(q_index: q_index).token(); ssYaccSet.add(q_object: num); } } } if (ssYaccSet.Count == 0) { return(true); } while (!ssYaccSet.locate(q_locate: this.m_lookahead.token())) { if (doGetLexeme(q_look: false)) { return(true); } } SSYaccTableRow ssYaccTableRow; while (true) { ssYaccTableRow = this.m_table.lookupRow(q_state: this.m_state); if (ssYaccTableRow.hasError()) { lookupAction(q_state: ssYaccTableRow.lookupError().entry(), q_token: this.m_lookahead.token()); if (this.m_action != 1) { break; } } if (ssYaccTableRow.hasSyncAll()) { lookupAction(q_state: this.m_state, q_token: this.m_lookahead.token()); if (this.m_action != 1) { goto label_26; } } else if (ssYaccTableRow.hasSync() && ssYaccTableRow.lookupAction(q_index: this.m_lookahead.token()) != null) { goto label_24; } pop(q_pop: 1); } var q_lexeme = new SSLexLexeme(q_lexeme: "%error", q_token: -2); this.m_element = stackElement(); this.m_element.setLexeme(q_lexeme: q_lexeme); this.m_element.setState(q_state: ssYaccTableRow.lookupError().entry()); push(); goto label_26; label_24: lookupAction(q_state: this.m_state, q_token: this.m_lookahead.token()); label_26: return(false); }