return d_tokenStream;
}
+void AntlrInput::lexerError(pANTLR3_BASE_RECOGNIZER recognizer) {
+ pANTLR3_LEXER lexer = (pANTLR3_LEXER)(recognizer->super);
+ AlwaysAssert(lexer!=NULL);
+ ParserState *parserState = (ParserState*)(lexer->super);
+ AlwaysAssert(parserState!=NULL);
+
+ // Call the error display routine
+ parserState->parseError("Error finding next token.");
+}
+
void AntlrInput::parseError(const std::string& message)
throw (ParserException) {
Debug("parser") << "Throwing exception: "
}
d_tokenStream = buffer->commonTstream;
+
+ // ANTLR isn't using super, AFAICT.
+ d_lexer->super = getParserState();
+ // Override default lexer error reporting
+ d_lexer->rec->reportError = &lexerError;
}
void AntlrInput::setParser(pANTLR3_PARSER pParser) {
/** Turns an ANTLR3 exception into a message for the user and calls <code>parseError</code>. */
static void reportError(pANTLR3_BASE_RECOGNIZER recognizer);
+ /** Builds a message for a lexer error and calls <code>parseError</code>. */
+ static void lexerError(pANTLR3_BASE_RECOGNIZER recognizer);
+
public:
/** Create a file input.
Assert(isDeclared(name));
}
-/*
-void
-ParserState::undefineVar(const std::string& name) {
- Assert(isDeclared(name));
- d_declScope.unbind(name);
- Assert(!isDeclared(name));
-}
-*/
-
Type
ParserState::mkSort(const std::string& name) {
Debug("parser") << "newSort(" << name << ")" << std::endl;
#include "expr/type.h"
#include "parser/antlr_input.h"
#include "parser/parser_state.h"
+#include "util/integer.h"
#include "util/output.h"
+#include "util/rational.h"
#include <vector>
using namespace CVC4;
/* constants */
| TRUE_TOK { expr = MK_CONST(true); }
| FALSE_TOK { expr = MK_CONST(false); }
+ | NUMERAL_TOK
+ { Integer num( AntlrInput::tokenText($NUMERAL_TOK) );
+ expr = MK_CONST(num); }
+ | RATIONAL_TOK
+ { // FIXME: This doesn't work because an SMT rational is not a valid GMP rational string
+ Rational rat( AntlrInput::tokenText($RATIONAL_TOK) );
+ expr = MK_CONST(rat); }
// NOTE: Theory constants go here
/* TODO: let, flet, quantifiers, arithmetic constants */
;
* Matches a numeral from the input (non-empty sequence of digits).
*/
NUMERAL_TOK
- : (DIGIT)+
+ : DIGIT+
+ ;
+
+RATIONAL_TOK
+ : DIGIT+ '.' DIGIT+
;
/**
* Matches the digits (0-9)
*/
fragment DIGIT : '0'..'9';
-
+// fragment NON_ZERO_DIGIT : '1'..'9';
+// fragment NUMERAL_SEQ : '0' | NON_ZERO_DIGIT DIGIT*;
/**
* Matches an allowed escaped character.
"(and (iff a b) (not a))",
"(iff (xor a b) (and (or a b) (not (and a b))))",
"(ite a (f x) y)",
- "(if_then_else a (f x) y)"
+ "(if_then_else a (f x) y)",
+ "1",
+ "0"// ,
+// "1.5"
};
const int numGoodSmtExprs = sizeof(goodSmtExprs) / sizeof(string);
"(not a b)", // wrong arity
"not a", // needs parens
"(ite a x)", // wrong arity
- "(a b)" // using non-function as function
+ "(a b)", // using non-function as function
+ ".5", // rational constants must have integer prefix
+ "1." // rational constants must have fractional suffix
};
const int numBadSmtExprs = sizeof(badSmtExprs) / sizeof(string);