1 /********************* -*- C++ -*- */
3 ** Original author: mdeters
4 ** Major contributors: dejan
5 ** Minor contributors (to current version): none
6 ** This file is part of the CVC4 prototype.
7 ** Copyright (c) 2009 The Analysis of Computer Systems Group (ACSys)
8 ** Courant Institute of Mathematical Sciences
10 ** See the file COPYING in the top-level source directory for licensing
13 ** Parser implementation.
18 #include <antlr/CharScanner.hpp>
21 #include "util/command.h"
22 #include "util/Assert.h"
23 #include "parser_exception.h"
24 #include "parser/antlr_parser.h"
25 #include "parser/smt/generated/AntlrSmtParser.hpp"
26 #include "parser/smt/generated/AntlrSmtLexer.hpp"
27 #include "parser/cvc/generated/AntlrCvcParser.hpp"
28 #include "parser/cvc/generated/AntlrCvcLexer.hpp"
31 using namespace antlr
;
36 void Parser::setDone(bool done
) {
40 bool Parser::done() const {
44 Command
* Parser::parseNextCommand() throw(ParserException
, AssertionException
) {
48 cmd
= d_antlrParser
->parseCommand();
49 if (cmd
== NULL
) setDone();
50 } catch(antlr::ANTLRException
& e
) {
52 throw ParserException(e
.toString());
58 Expr
Parser::parseNextExpression() throw(ParserException
, AssertionException
) {
62 result
= d_antlrParser
->parseExpr();
65 } catch(antlr::ANTLRException
& e
) {
67 throw ParserException(e
.toString());
81 Parser::Parser(istream
* input
, AntlrParser
* antlrParser
, CharScanner
* antlrLexer
, bool deleteInput
) :
82 d_done(false), d_input(input
), d_antlrParser(antlrParser
), d_antlrLexer(antlrLexer
), d_deleteInput(deleteInput
) {
85 Parser
* Parser::getNewParser(ExprManager
* em
, InputLanguage lang
,
86 istream
* input
, string filename
, bool deleteInput
) {
88 AntlrParser
* antlrParser
= 0;
89 antlr::CharScanner
* antlrLexer
= 0;
93 antlrLexer
= new AntlrCvcLexer(*input
);
94 antlrLexer
->setFilename(filename
);
95 antlrParser
= new AntlrCvcParser(*antlrLexer
);
96 antlrParser
->setFilename(filename
);
97 antlrParser
->setExpressionManager(em
);
101 antlrLexer
= new AntlrSmtLexer(*input
);
102 antlrLexer
->setFilename(filename
);
103 antlrParser
= new AntlrSmtParser(*antlrLexer
);
104 antlrParser
->setFilename(filename
);
105 antlrParser
->setExpressionManager(em
);
109 Unhandled("Unknown Input language!");
112 return new Parser(input
, antlrParser
, antlrLexer
, deleteInput
);
115 Parser
* Parser::getNewParser(ExprManager
* em
, InputLanguage lang
,
117 istream
* input
= new ifstream(filename
.c_str());
118 return getNewParser(em
, lang
, input
, filename
, true);
121 Parser
* Parser::getNewParser(ExprManager
* em
, InputLanguage lang
,
123 return getNewParser(em
, lang
, &input
, "", false);
126 }/* CVC4::parser namespace */
127 }/* CVC4 namespace */