根据
第 4.2 章中构建具有自动错误恢复功能的高效 LALR(K) 解析器的实用方法。
当解析器遇到 shift-reduce 时,它应该弹出 |α| 元素。但是 JDT 中的解析器并没有弹出元素。我不知道为什么,有没有人可以帮助我。
哦。解析器确实在 Parser.java 中弹出元素。在块“ else if (act > ERROR_ACTION) { /* shift-reduce */”中,它没有弹出元素,但也没有中断,然后执行reduce块。所以它确实弹出了元素。
enter } else if (act > ERROR_ACTION) { /* shift-reduce */
consumeToken(this.currentToken);
if (this.currentElement != null) {
boolean oldValue = this.recordStringLiterals;
this.recordStringLiterals = false;
recoveryTokenCheck();
this.recordStringLiterals = oldValue;
}
try {
this.currentToken = this.scanner.getNextToken();
} catch(InvalidInputException e){
if (!this.hasReportedError){
problemReporter().scannerError(this, e.getMessage());
this.hasReportedError = true;
}
this.lastCheckPoint = this.scanner.currentPosition;
this.currentToken = 0;
this.restartRecovery = true;
}
if(this.statementRecoveryActivated) {
jumpOverType();
}
act -= ERROR_ACTION;
if (DEBUG_AUTOMATON) {
System.out.print("Shift/Reduce - (" + name[terminal_index[this.currentToken]]+") "); //$NON-NLS-1$ //$NON-NLS-2$
}
// It din't break here ,so it go to reduce b
} else {
if (act < ACCEPT_ACTION) { /* shift */
consumeToken(this.currentToken);
if (this.currentElement != null) {
boolean oldValue = this.recordStringLiterals;
this.recordStringLiterals = false;
recoveryTokenCheck();
this.recordStringLiterals = oldValue;
}
try{
this.currentToken = this.scanner.getNextToken();
} catch(InvalidInputException e){
if (!this.hasReportedError){
problemReporter().scannerError(this, e.getMessage());
this.hasReportedError = true;
}
this.lastCheckPoint = this.scanner.currentPosition;
this.currentToken = 0;
this.restartRecovery = true;
}
if(this.statementRecoveryActivated) {
jumpOverType();
}
if (DEBUG_AUTOMATON) {
System.out.println("Shift - (" + name[terminal_index[this.currentToken]]+")"); //$NON-NLS-1$ //$NON-NLS-2$
}
continue ProcessTerminals;
}
break ProcessTerminals;
}
// ProcessNonTerminals :
do { /* reduce */
if (DEBUG_AUTOMATON) {
System.out.println(name[non_terminal_index[lhs[act]]]);
}
consumeRule(act);
this.stateStackTop -= (rhs[act] - 1);
act = ntAction(this.stack[this.stateStackTop], lhs[act]);
if (DEBUG_AUTOMATON) {
if (act <= NUM_RULES) {
System.out.print(" - "); //$NON-NLS-1$
}
}
} while (act <= NUM_RULES);here