summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher L. Conway <christopherleeconway@gmail.com>2010-04-05 20:04:45 +0000
committerChristopher L. Conway <christopherleeconway@gmail.com>2010-04-05 20:04:45 +0000
commit31921b60ec820d6c5873a43f3b88dada6b861f45 (patch)
tree513e9d739b5da6b37a9cee2d840dba3ade90473f
parentf55a79b565151772bbf67ae2517a025c8999bca0 (diff)
Simplifying ANTLR3 overrides
-rw-r--r--src/parser/antlr_input.cpp7
-rw-r--r--src/parser/antlr_input.h7
-rw-r--r--src/parser/antlr_input_imports.cpp155
3 files changed, 6 insertions, 163 deletions
diff --git a/src/parser/antlr_input.cpp b/src/parser/antlr_input.cpp
index b46e22853..b8caf5ded 100644
--- a/src/parser/antlr_input.cpp
+++ b/src/parser/antlr_input.cpp
@@ -134,8 +134,13 @@ void AntlrInput::setParser(pANTLR3_PARSER pParser) {
// it would have to be declared separately in every input's grammar and we'd have to
// pass it in as an address anyway.
d_parser->super = getParserState();
+// d_parser->rec->match = &match;
d_parser->rec->reportError = &reportError;
- d_parser->rec->recoverFromMismatchedToken = &recoverFromMismatchedToken;
+ /* Don't try to recover from a parse error. */
+ // [chris 4/5/2010] Not clear on why this cast is necessary, but I get an error if I remove it.
+ d_parser->rec->recoverFromMismatchedToken =
+ (void* (*)(ANTLR3_BASE_RECOGNIZER_struct*, ANTLR3_UINT32, ANTLR3_BITSET_LIST_struct*))
+ d_parser->rec->mismatch;
}
diff --git a/src/parser/antlr_input.h b/src/parser/antlr_input.h
index c338c528a..dee7c1491 100644
--- a/src/parser/antlr_input.h
+++ b/src/parser/antlr_input.h
@@ -67,13 +67,6 @@ class AntlrInput : public Input {
/** Turns an ANTLR3 exception into a message for the user and calls <code>parseError</code>. */
static void reportError(pANTLR3_BASE_RECOGNIZER recognizer);
- /** Collects information from a parse error and calls reportError. Replaces the default
- * implementation, which tries to recover from the error.
- */
- static void *
- recoverFromMismatchedToken(pANTLR3_BASE_RECOGNIZER recognizer,
- ANTLR3_UINT32 ttype, pANTLR3_BITSET_LIST follow);
-
public:
/** Create a file input.
diff --git a/src/parser/antlr_input_imports.cpp b/src/parser/antlr_input_imports.cpp
index 3476507ab..3555ed06b 100644
--- a/src/parser/antlr_input_imports.cpp
+++ b/src/parser/antlr_input_imports.cpp
@@ -44,161 +44,6 @@ using namespace std;
namespace CVC4 {
namespace parser {
-/// Match current input symbol against ttype. Upon error, do one token
-/// insertion or deletion if possible.
-/// To turn off single token insertion or deletion error
-/// recovery, override mismatchRecover() and have it call
-/// plain mismatch(), which does not recover. Then any error
-/// in a rule will cause an exception and immediate exit from
-/// rule. Rule would recover by resynchronizing to the set of
-/// symbols that can follow rule ref.
-///
-/* *** CVC4 NOTE ***
- * This function is unchanged from its libantlr3c version. It is included
- * here to avoid an exception-handling bug caused by libantlr3c being compiled
- * without support for C++ exceptions by default.
- */
-void *
-AntlrInput::match(pANTLR3_BASE_RECOGNIZER recognizer, ANTLR3_UINT32 ttype,
- pANTLR3_BITSET_LIST follow) {
- pANTLR3_PARSER parser;
- pANTLR3_TREE_PARSER tparser;
- pANTLR3_INT_STREAM is;
- void * matchedSymbol;
-
- switch(recognizer->type) {
- case ANTLR3_TYPE_PARSER:
-
- parser = (pANTLR3_PARSER)(recognizer->super);
- tparser = NULL;
- is = parser->tstream->istream;
-
- break;
-
- case ANTLR3_TYPE_TREE_PARSER:
-
- tparser = (pANTLR3_TREE_PARSER)(recognizer->super);
- parser = NULL;
- is = tparser->ctnstream->tnstream->istream;
-
- break;
-
- default:
-
- ANTLR3_FPRINTF(
- stderr,
- "Base recognizer function 'match' called by unknown parser type - provide override for this function\n");
- return ANTLR3_FALSE;
-
- break;
- }
-
- // Pick up the current input token/node for assignment to labels
- //
- matchedSymbol = recognizer->getCurrentInputSymbol(recognizer, is);
-
- if(is->_LA(is, 1) == ttype) {
- // The token was the one we were told to expect
- //
- is->consume(is); // Consume that token from the stream
- recognizer->state->errorRecovery = ANTLR3_FALSE; // Not in error recovery now (if we were)
- recognizer->state->failed = ANTLR3_FALSE; // The match was a success
- return matchedSymbol; // We are done
- }
-
- // We did not find the expected token type, if we are backtracking then
- // we just set the failed flag and return.
- //
- if(recognizer->state->backtracking > 0) {
- // Backtracking is going on
- //
- recognizer->state->failed = ANTLR3_TRUE;
- return matchedSymbol;
- }
-
- // We did not find the expected token and there is no backtracking
- // going on, so we mismatch, which creates an exception in the recognizer exception
- // stack.
- //
- matchedSymbol = recognizer->recoverFromMismatchedToken(recognizer, ttype,
- follow);
- return matchedSymbol;
-}
-
-/// Attempt to recover from a single missing or extra token.
-///
-/// EXTRA TOKEN
-///
-/// LA(1) is not what we are looking for. If LA(2) has the right token,
-/// however, then assume LA(1) is some extra spurious token. Delete it
-/// and LA(2) as if we were doing a normal match(), which advances the
-/// input.
-///
-/// MISSING TOKEN
-///
-/// If current token is consistent with what could come after
-/// ttype then it is ok to "insert" the missing token, else throw
-/// exception For example, Input "i=(3;" is clearly missing the
-/// ')'. When the parser returns from the nested call to expr, it
-/// will have call chain:
-///
-/// stat -> expr -> atom
-///
-/// and it will be trying to match the ')' at this point in the
-/// derivation:
-///
-/// => ID '=' '(' INT ')' ('+' atom)* ';'
-/// ^
-/// match() will see that ';' doesn't match ')' and report a
-/// mismatched token error. To recover, it sees that LA(1)==';'
-/// is in the set of tokens that can follow the ')' token
-/// reference in rule atom. It can assume that you forgot the ')'.
-///
-/// The exception that was passed in, in the java implementation is
-/// sorted in the recognizer exception stack in the C version. To 'throw' it we set the
-/// error flag and rules cascade back when this is set.
-///
-/* *** CVC4 NOTE ***
- * This function has been basically gutted to remove any attempts to recover
- * from a syntax error.
- */
-void *
-AntlrInput::recoverFromMismatchedToken(pANTLR3_BASE_RECOGNIZER recognizer,
- ANTLR3_UINT32 ttype,
- pANTLR3_BITSET_LIST follow) {
-
- pANTLR3_PARSER parser = (pANTLR3_PARSER) (recognizer->super);
- pANTLR3_INT_STREAM is = parser->tstream->istream;
- void *matchedSymbol;
-
-
- // Create an exception if we need one
- //
- if(recognizer->state->exception == NULL) {
- antlr3RecognitionExceptionNew(recognizer);
- }
-
- if(recognizer->mismatchIsUnwantedToken(recognizer, is, ttype) == ANTLR3_TRUE) {
- recognizer->state->exception->type = ANTLR3_UNWANTED_TOKEN_EXCEPTION;
- recognizer->state->exception->message
- = (void*)ANTLR3_UNWANTED_TOKEN_EXCEPTION_NAME;
- }
-
- if(recognizer->mismatchIsMissingToken(recognizer, is, follow)) {
- matchedSymbol = recognizer->getMissingSymbol(recognizer, is,
- recognizer->state->exception,
- ttype, follow);
- recognizer->state->exception->type = ANTLR3_MISSING_TOKEN_EXCEPTION;
- recognizer->state->exception->message = (void*)ANTLR3_MISSING_TOKEN_EXCEPTION_NAME;
- recognizer->state->exception->token = matchedSymbol;
- recognizer->state->exception->expecting = ttype;
- }
-
- reportError(recognizer);
- Unreachable("reportError should have thrown exception in AntlrInput::recoverFromMismatchedToken");
-}
-
-
/// Report a recognition problem.
///
/// This method sets errorRecovery to indicate the parser is recovering
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback