-1

According to A pratyical method for constructing efficient LALR(K) Parsers with Automatic Error Recovery
in chapter 4.2 .

When the parser encounters a shift-reduce , it should pops |α| elements. But the parser in JDT ,it did't pops elements. I don't known why , does any can help me.

shift-reduce action in parser.java enter image description here

shift-reduce action in DiagnoseParser.java enter image description here

kuafuking
  • 89
  • 6
  • Please do not post pictures of code, post real code that can be copied and run. – AdrianHHH Oct 31 '15 at 15:34
  • this is a copy of A pratyical method for constructing efficient LALR(K) Parsers with Automatic Error Recovery https://drive.google.com/file/d/0BxcTRY0Zp6wndnNhMkYwcENVSUE/view?usp=sharing – kuafuking Nov 01 '15 at 09:52
  • I didn't post real code .Because it can't run without other packages in JDT CORE. – kuafuking Nov 01 '15 at 09:53

1 Answers1

0

Oh. The parser did pops element in Parser.java. In the block " else if (act > ERROR_ACTION) { /* shift-reduce */" it didn't pops elements,but it also didn't break, and then the reduce block execute. So it did pops elements.

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
kuafuking
  • 89
  • 6