Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.photran.core/model/org/eclipse/photran/internal/core/f95modelparser/ErrorRecovery.java')
-rw-r--r--org.eclipse.photran.core/model/org/eclipse/photran/internal/core/f95modelparser/ErrorRecovery.java257
1 files changed, 257 insertions, 0 deletions
diff --git a/org.eclipse.photran.core/model/org/eclipse/photran/internal/core/f95modelparser/ErrorRecovery.java b/org.eclipse.photran.core/model/org/eclipse/photran/internal/core/f95modelparser/ErrorRecovery.java
new file mode 100644
index 00000000..16603f35
--- /dev/null
+++ b/org.eclipse.photran.core/model/org/eclipse/photran/internal/core/f95modelparser/ErrorRecovery.java
@@ -0,0 +1,257 @@
+// Generated by Rex version 1.0 alpha 5
+
+package org.eclipse.photran.internal.core.f95modelparser;
+
+import java.util.LinkedList;
+
+/**
+ * The methods in this class use the error productions specified
+ * in the grammar to attempt to recover from syntax errors.
+ */
+public class ErrorRecovery
+{
+
+ private abstract class AbstractErrorProduction
+ {
+ public abstract boolean applies(Parser parser);
+
+ public abstract boolean attemptRecovery(Parser parser, LinkedList recoveryList) throws Exception;
+ }
+ protected Parser parser;
+ protected ErrorRecovery.AbstractErrorProduction[] errorProductions;
+ protected LinkedList recoveryList;
+
+ public ErrorRecovery(Parser parserToRecover)
+ {
+ parser = parserToRecover;
+ errorProductions = new ErrorRecovery.AbstractErrorProduction[6];
+ errorProductions[0] = new ErrorRecovery.ErrorProduction0();
+ errorProductions[1] = new ErrorRecovery.ErrorProduction1();
+ errorProductions[2] = new ErrorRecovery.ErrorProduction2();
+ errorProductions[3] = new ErrorRecovery.ErrorProduction3();
+ errorProductions[4] = new ErrorRecovery.ErrorProduction4();
+ errorProductions[5] = new ErrorRecovery.ErrorProduction5();
+ }
+
+ boolean recover() throws Exception
+ {
+ recoveryList = new LinkedList();
+ while (!parser.getSymbolStack().isEmpty())
+ {
+ int errorProductionToUse = getRecoveryProductionForCurrentState();
+ if (errorProductionToUse > -1) return errorProductions[errorProductionToUse].attemptRecovery(parser, recoveryList);
+
+ // No error production applied, so pop the stacks and try again
+
+ // Determine how many values on the parser's valueStack correspond to
+ // the symbol on top of its symbolStack, and pop them off the valueStack, saving them
+ // in the recoveryList
+ TerminalOrNonterminal symOnTop = (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-1);
+ int symsToPop = symOnTop.getNumberOfSymbolsOnValueStack();
+ for (int i = 0; i < symsToPop; i++)
+ {
+ recoveryList.add(0, (Object)parser.getValueStack().get(parser.getValueStack().size()-1));
+ parser.getValueStack().remove(parser.getValueStack().size() - 1);
+ }
+
+ // Only one symbol needs to be popped from the state and symbol stacks
+ parser.getStateStack().remove(parser.getStateStack().size() - 1);
+ parser.getSymbolStack().remove(parser.getSymbolStack().size() - 1);
+ }
+ return false;
+ }
+
+ protected int getRecoveryProductionForCurrentState()
+ {
+ // Try each of the 6 error productions
+ for (int i = 0; i < 6; i++)
+ if (errorProductions[i].applies(parser)) return i;
+ return -1;
+ }
+
+ /**
+ * <xFormatStmt> ::= T_FORMAT %error T_EOS ;
+ */
+ private class ErrorProduction0 extends AbstractErrorProduction
+ {
+ public boolean applies(Parser parser)
+ {
+ return parser.getSymbolStack().size() >= 1 && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-1) == Terminal.TFormatTerminal.getInstance();
+ }
+
+ public boolean attemptRecovery(Parser parser, LinkedList recoveryList) throws Exception
+ {
+ // Discard tokens until we reach a token which successfully terminates this error production
+ while (parser.getLookaheadToken().getTerminal() != Terminal.T_EOS)
+ {
+ if (parser.getLookaheadToken().getTerminal() == Terminal.END_OF_INPUT) return false;
+ recoveryList.add(parser.getLookaheadToken());
+ parser.readNextToken();
+ }
+
+ // Now push a %stack token and associate it with the recoveryList and no particular state
+ parser.getSymbolStack().add(Terminal.ERROR);
+ parser.getValueStack().add(recoveryList);
+ parser.getStateStack().add(new Integer(-999));
+
+ // Finally, shift the resume token and go to a state where the parser will reduce by this error production
+ parser.shiftAndGoToState(1200);
+ return true;
+ }
+ }
+
+ /**
+ * <xFormatStmt> ::= <xLblDef> T_FORMAT %error T_EOS ;
+ */
+ private class ErrorProduction1 extends AbstractErrorProduction
+ {
+ public boolean applies(Parser parser)
+ {
+ return parser.getSymbolStack().size() >= 2 && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-1) == Terminal.TFormatTerminal.getInstance() && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-2) == Nonterminal.XlbldefNonterminal.getInstance();
+ }
+
+ public boolean attemptRecovery(Parser parser, LinkedList recoveryList) throws Exception
+ {
+ // Discard tokens until we reach a token which successfully terminates this error production
+ while (parser.getLookaheadToken().getTerminal() != Terminal.T_EOS)
+ {
+ if (parser.getLookaheadToken().getTerminal() == Terminal.END_OF_INPUT) return false;
+ recoveryList.add(parser.getLookaheadToken());
+ parser.readNextToken();
+ }
+
+ // Now push a %stack token and associate it with the recoveryList and no particular state
+ parser.getSymbolStack().add(Terminal.ERROR);
+ parser.getValueStack().add(recoveryList);
+ parser.getStateStack().add(new Integer(-999));
+
+ // Finally, shift the resume token and go to a state where the parser will reduce by this error production
+ parser.shiftAndGoToState(1586);
+ return true;
+ }
+ }
+
+ /**
+ * <xFunctionStmt> ::= <xFunctionPrefix> <xFunctionName> %error T_EOS ;
+ */
+ private class ErrorProduction2 extends AbstractErrorProduction
+ {
+ public boolean applies(Parser parser)
+ {
+ return parser.getSymbolStack().size() >= 2 && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-1) == Nonterminal.XfunctionnameNonterminal.getInstance() && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-2) == Nonterminal.XfunctionprefixNonterminal.getInstance();
+ }
+
+ public boolean attemptRecovery(Parser parser, LinkedList recoveryList) throws Exception
+ {
+ // Discard tokens until we reach a token which successfully terminates this error production
+ while (parser.getLookaheadToken().getTerminal() != Terminal.T_EOS)
+ {
+ if (parser.getLookaheadToken().getTerminal() == Terminal.END_OF_INPUT) return false;
+ recoveryList.add(parser.getLookaheadToken());
+ parser.readNextToken();
+ }
+
+ // Now push a %stack token and associate it with the recoveryList and no particular state
+ parser.getSymbolStack().add(Terminal.ERROR);
+ parser.getValueStack().add(recoveryList);
+ parser.getStateStack().add(new Integer(-999));
+
+ // Finally, shift the resume token and go to a state where the parser will reduce by this error production
+ parser.shiftAndGoToState(1488);
+ return true;
+ }
+ }
+
+ /**
+ * <xFunctionStmt> ::= <xLblDef> <xFunctionPrefix> <xFunctionName> %error T_EOS ;
+ */
+ private class ErrorProduction3 extends AbstractErrorProduction
+ {
+ public boolean applies(Parser parser)
+ {
+ return parser.getSymbolStack().size() >= 3 && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-1) == Nonterminal.XfunctionnameNonterminal.getInstance() && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-2) == Nonterminal.XfunctionprefixNonterminal.getInstance() && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-3) == Nonterminal.XlbldefNonterminal.getInstance();
+ }
+
+ public boolean attemptRecovery(Parser parser, LinkedList recoveryList) throws Exception
+ {
+ // Discard tokens until we reach a token which successfully terminates this error production
+ while (parser.getLookaheadToken().getTerminal() != Terminal.T_EOS)
+ {
+ if (parser.getLookaheadToken().getTerminal() == Terminal.END_OF_INPUT) return false;
+ recoveryList.add(parser.getLookaheadToken());
+ parser.readNextToken();
+ }
+
+ // Now push a %stack token and associate it with the recoveryList and no particular state
+ parser.getSymbolStack().add(Terminal.ERROR);
+ parser.getValueStack().add(recoveryList);
+ parser.getStateStack().add(new Integer(-999));
+
+ // Finally, shift the resume token and go to a state where the parser will reduce by this error production
+ parser.shiftAndGoToState(2062);
+ return true;
+ }
+ }
+
+ /**
+ * <xSubroutineStmt> ::= <xSubroutinePrefix> <xSubroutineName> %error T_EOS ;
+ */
+ private class ErrorProduction4 extends AbstractErrorProduction
+ {
+ public boolean applies(Parser parser)
+ {
+ return parser.getSymbolStack().size() >= 2 && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-1) == Nonterminal.XsubroutinenameNonterminal.getInstance() && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-2) == Nonterminal.XsubroutineprefixNonterminal.getInstance();
+ }
+
+ public boolean attemptRecovery(Parser parser, LinkedList recoveryList) throws Exception
+ {
+ // Discard tokens until we reach a token which successfully terminates this error production
+ while (parser.getLookaheadToken().getTerminal() != Terminal.T_EOS)
+ {
+ if (parser.getLookaheadToken().getTerminal() == Terminal.END_OF_INPUT) return false;
+ recoveryList.add(parser.getLookaheadToken());
+ parser.readNextToken();
+ }
+
+ // Now push a %stack token and associate it with the recoveryList and no particular state
+ parser.getSymbolStack().add(Terminal.ERROR);
+ parser.getValueStack().add(recoveryList);
+ parser.getStateStack().add(new Integer(-999));
+
+ // Finally, shift the resume token and go to a state where the parser will reduce by this error production
+ parser.shiftAndGoToState(1434);
+ return true;
+ }
+ }
+
+ /**
+ * <xSubroutineStmt> ::= <xLblDef> <xSubroutinePrefix> <xSubroutineName> %error T_EOS ;
+ */
+ private class ErrorProduction5 extends AbstractErrorProduction
+ {
+ public boolean applies(Parser parser)
+ {
+ return parser.getSymbolStack().size() >= 3 && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-1) == Nonterminal.XsubroutinenameNonterminal.getInstance() && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-2) == Nonterminal.XsubroutineprefixNonterminal.getInstance() && (TerminalOrNonterminal)parser.getSymbolStack().get(parser.getSymbolStack().size()-3) == Nonterminal.XlbldefNonterminal.getInstance();
+ }
+
+ public boolean attemptRecovery(Parser parser, LinkedList recoveryList) throws Exception
+ {
+ // Discard tokens until we reach a token which successfully terminates this error production
+ while (parser.getLookaheadToken().getTerminal() != Terminal.T_EOS)
+ {
+ if (parser.getLookaheadToken().getTerminal() == Terminal.END_OF_INPUT) return false;
+ recoveryList.add(parser.getLookaheadToken());
+ parser.readNextToken();
+ }
+
+ // Now push a %stack token and associate it with the recoveryList and no particular state
+ parser.getSymbolStack().add(Terminal.ERROR);
+ parser.getValueStack().add(recoveryList);
+ parser.getStateStack().add(new Integer(-999));
+
+ // Finally, shift the resume token and go to a state where the parser will reduce by this error production
+ parser.shiftAndGoToState(2060);
+ return true;
+ }
+ }
+}

Back to the top