-1


章 4.2 の自動エラー回復を使用して効率的な LALR(K) パーサーを構築するための実用的な方法によると。

パーサーが shift-reduce に遭遇すると、|α| をポップする必要があります。要素。しかし、JDT のパーサーは要素をポップしませんでした。理由はわかりませんが、何か助けてくれますか。

parser.java の shift-reduce アクション ここに画像の説明を入力

DiagnoseParser.java の shift-reduce アクション ここに画像の説明を入力

4

1 に答える 1

0

おー。パーサーが Parser.java の要素を pop しました。ブロック "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
于 2015-11-01T13:48:52.800 に答える