d_lexer->rec->state->tokSource->nextToken = &nextTokenStr;
}
-void AntlrInput::setParser(Parser *parser) {
+void AntlrInput::setParser(Parser& parser) {
// ANTLR isn't using super in the lexer or the parser, AFAICT.
// We could also use @lexer/parser::context to add a field to the generated
// objects, but then it would have to be declared separately in every
// language's grammar and we'd have to in the address of the field anyway.
- d_lexer->super = parser;
- d_parser->super = parser;
-
+ d_lexer->super = &parser;
+ d_parser->super = &parser;
}
void AntlrInput::setAntlr3Parser(pANTLR3_PARSER pParser) {
* for the given input language and attach it to an input source of the
* appropriate type.
*/
-class AntlrInput : public Input{
+class AntlrInput : public Input {
/** The token lookahead used to lex and parse the input. This should usually be equal to
* <code>K</code> for an LL(k) grammar. */
unsigned int d_lookahead;
void setAntlr3Parser(pANTLR3_PARSER pParser);
/** Set the Parser object for this input. */
- void setParser(Parser *parser);
+ virtual void setParser(Parser& parser);
};
inline std::string AntlrInput::tokenText(pANTLR3_COMMON_TOKEN token) {
virtual Expr parseExpr() throw(ParserException) = 0;
/** Set the Parser object for this input. */
- virtual void setParser(Parser *parser) = 0;
+ virtual void setParser(Parser& parser) = 0;
};
}/* CVC4::parser namespace */
namespace CVC4 {
namespace parser {
-Parser::Parser(ExprManager* exprManager, Input* input) :
+Parser::Parser(ExprManager* exprManager, Input* input, bool strictMode) :
d_exprManager(exprManager),
d_input(input),
d_done(false),
d_checksEnabled(true),
- d_strictMode(false) {
- d_input->setParser(this);
+ d_strictMode(strictMode) {
+ d_input->setParser(*this);
}
Expr Parser::getSymbol(const std::string& name, SymbolType type) {
void
Parser::defineVar(const std::string& name, const Expr& val) {
- Assert(!isDeclared(name));
d_declScope.bind(name,val);
Assert(isDeclared(name));
}
void
Parser::defineType(const std::string& name, const Type& type) {
- Assert( !isDeclared(name, SYM_SORT) );
d_declScope.bindType(name,type);
Assert( isDeclared(name, SYM_SORT) ) ;
}
* @param exprManager the expression manager to use when creating expressions
* @param input the parser input
*/
- Parser(ExprManager* exprManager, Input* input);
+ Parser(ExprManager* exprManager, Input* input, bool strictMode = false);
virtual ~Parser() { }
{ expr = PARSER_STATE->getVariable(name); }
/* constants */
- | TRUE_TOK { expr = MK_CONST(true); }
- | FALSE_TOK { expr = MK_CONST(false); }
+// | TRUE_TOK { expr = MK_CONST(true); }
+// | FALSE_TOK { expr = MK_CONST(false); }
| INTEGER_LITERAL
{ expr = MK_CONST( AntlrInput::tokenToInteger($INTEGER_LITERAL) ); }
| DECIMAL_LITERAL
DECLARE_FUN_TOK : 'declare-fun';
DECLARE_SORT_TOK : 'declare-sort';
EXIT_TOK : 'exit';
-FALSE_TOK : 'false';
+//FALSE_TOK : 'false';
ITE_TOK : 'ite';
LET_TOK : 'let';
LPAREN_TOK : '(';
//SMT_VERSION_TOK : ':smt-lib-version';
//SOURCE_TOK : ':source';
//STATUS_TOK : ':status';
-TRUE_TOK : 'true';
+//TRUE_TOK : 'true';
//UNKNOWN_TOK : 'unknown';
//UNSAT_TOK : 'unsat';
switch(theory) {
case THEORY_CORE:
parser.defineType("Bool", parser.getExprManager()->booleanType());
+ parser.defineVar("true", parser.getExprManager()->mkConst(true));
+ parser.defineVar("false", parser.getExprManager()->mkConst(false));
parser.addOperator(kind::AND);
parser.addOperator(kind::EQUAL);
parser.addOperator(kind::IFF);
#include "parser/input.h"
#include "parser/parser.h"
#include "parser/parser_exception.h"
+#include "parser/smt2/smt2.h"
#include "parser/smt2/generated/Smt2Lexer.h"
#include "parser/smt2/generated/Smt2Parser.h"
return d_pSmt2Parser->parseExpr(d_pSmt2Parser);
}
+void Smt2Input::setParser(Parser& parser) {
+ super::setParser(parser);
+ if( !parser.strictModeEnabled() ) {
+ Smt2::addTheory(parser,Smt2::THEORY_CORE);
+ }
+}
+
}/* CVC4::parser namespace */
}/* CVC4 namespace */
namespace parser {
class Smt2Input : public AntlrInput {
+ typedef AntlrInput super;
/** The ANTLR3 SMT2 lexer for the input. */
pSmt2Lexer d_pSmt2Lexer;
*/
Expr parseExpr() throw(ParserException);
+ /** Set the Parser object for this input. This implementation overrides the super-class
+ * implementation to add the core theory symbols to the parser state when strict
+ * mode is disabled. */
+ virtual void setParser(Parser& parser);
+
};/* class Smt2Input */
}/* CVC4::parser namespace */
}
}
- void tryBadInput(const string badInput) {
+ void tryBadInput(const string badInput, bool strictMode = false) {
// cerr << "Testing bad input: '" << badInput << "'\n";
// Debug.on("parser");
Input* input = Input::newStringInput(d_lang, badInput, "test");
- Parser parser(d_exprManager, input);
+ Parser parser(d_exprManager, input, strictMode);
TS_ASSERT_THROWS
( while(parser.nextCommand());
cout << "\nBad input succeeded:\n" << badInput << endl;,
// Debug.on("parser-extra");
// cout << "Testing bad expr: '" << badExpr << "'\n";
Input* input = Input::newStringInput(d_lang, badExpr, "test");
- Parser parser(d_exprManager, input);
- if( strictMode ) {
- parser.enableStrictMode();
- }
+ Parser parser(d_exprManager, input, strictMode);
setupContext(parser);
TS_ASSERT( !parser.done() );
TS_ASSERT_THROWS
tryGoodInput(""); // empty string is OK
tryGoodInput("(set-logic QF_UF)");
tryGoodInput("(set-info :notes |This is a note, take note!|)");
- tryGoodInput("(set-logic QF_UF)(assert true)");
+ tryGoodInput("(set-logic QF_UF) (assert true)");
tryGoodInput("(check-sat)");
tryGoodInput("(exit)");
- tryGoodInput("(assert false) (check-sat)");
+ tryGoodInput("(set-logic QF_UF) (assert false) (check-sat)");
tryGoodInput("(set-logic QF_UF) (declare-fun a () Bool) "
"(declare-fun b () Bool)");
tryGoodInput("(set-logic QF_UF) (declare-fun a () Bool) "
void testBadSmt2Inputs() {
tryBadInput("(assert)"); // no args
tryBadInput("(set-info :notes |Symbols can't contain the | character|)");
- tryBadInput("(check-sat true)"); // shouldn't have an arg
+ tryBadInput("(set-logic QF_UF) (check-sat true)"); // shouldn't have an arg
tryBadInput("(declare-sort a)"); // no arg
tryBadInput("(declare-sort a 0) (declare-sort a 0)"); // double decl
- tryBadInput("(declare-fun p Bool)"); // should be "p () Bool"
+ tryBadInput("(set-logic QF_UF) (declare-fun p Bool)"); // should be "p () Bool"
+ // strict mode
+ tryBadInput("(assert true)", true); // no set-logic, core theory symbol "true" undefined
+ tryBadInput("(declare-fun p Bool)", true); // core theory symbol "Bool" undefined
}
void testGoodSmt2Exprs() {