1 /********************* */
2 /*! \file parser_builder.cpp
4 ** Original author: cconway
5 ** Major contributors: mdeters
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
14 ** \brief A builder for parsers.
16 ** A builder for parsers.
21 #include "parser_builder.h"
25 #include "smt2/smt2.h"
27 #include "expr/expr_manager.h"
28 #include "util/options.h"
34 ParserBuilder::ParserBuilder(ExprManager
* exprManager
,
35 const std::string
& filename
) :
37 d_exprManager(exprManager
) {
38 init(exprManager
,filename
);
41 ParserBuilder::ParserBuilder(ExprManager
* exprManager
,
42 const std::string
& filename
,
43 const Options
& options
) :
45 d_exprManager(exprManager
) {
46 init(exprManager
,filename
);
50 void ParserBuilder::init(ExprManager
* exprManager
,
51 const std::string
& filename
) {
52 d_inputType
= FILE_INPUT
;
53 d_lang
= language::input::LANG_AUTO
;
54 d_filename
= filename
;
56 d_exprManager
= exprManager
;
57 d_checksEnabled
= true;
63 Parser
*ParserBuilder::build()
64 throw (InputStreamException
,AssertionException
) {
66 switch( d_inputType
) {
68 input
= Input::newFileInput(d_lang
,d_filename
,d_mmap
);
71 AlwaysAssert( d_streamInput
!= NULL
,
72 "Uninitialized stream input in ParserBuilder::build()" );
73 input
= Input::newStreamInput(d_lang
,*d_streamInput
,d_filename
);
76 input
= Input::newStringInput(d_lang
,d_stringInput
,d_filename
);
82 Parser
*parser
= NULL
;
84 case language::input::LANG_SMTLIB
:
85 parser
= new Smt(d_exprManager
, input
, d_strictMode
, d_parseOnly
);
87 case language::input::LANG_SMTLIB_V2
:
88 parser
= new Smt2(d_exprManager
, input
, d_strictMode
, d_parseOnly
);
91 parser
= new Parser(d_exprManager
, input
, d_strictMode
, d_parseOnly
);
94 if( d_checksEnabled
) {
95 parser
->enableChecks();
97 parser
->disableChecks();
103 ParserBuilder
& ParserBuilder::withChecks(bool flag
) {
104 d_checksEnabled
= flag
;
108 ParserBuilder
& ParserBuilder::withExprManager(ExprManager
* exprManager
) {
109 d_exprManager
= exprManager
;
113 ParserBuilder
& ParserBuilder::withFileInput() {
114 d_inputType
= FILE_INPUT
;
118 ParserBuilder
& ParserBuilder::withFilename(const std::string
& filename
) {
119 d_filename
= filename
;
123 ParserBuilder
& ParserBuilder::withInputLanguage(InputLanguage lang
) {
128 ParserBuilder
& ParserBuilder::withMmap(bool flag
) {
133 ParserBuilder
& ParserBuilder::withParseOnly(bool flag
) {
138 ParserBuilder
& ParserBuilder::withOptions(const Options
& options
) {
140 withInputLanguage(options
.inputLanguage
)
141 .withMmap(options
.memoryMap
)
142 .withChecks(options
.semanticChecks
)
143 .withStrictMode(options
.strictParsing
)
144 .withParseOnly(options
.parseOnly
);
147 ParserBuilder
& ParserBuilder::withStrictMode(bool flag
) {
152 ParserBuilder
& ParserBuilder::withStreamInput(std::istream
& input
) {
153 d_inputType
= STREAM_INPUT
;
154 d_streamInput
= &input
;
158 ParserBuilder
& ParserBuilder::withStringInput(const std::string
& input
) {
159 d_inputType
= STRING_INPUT
;
160 d_stringInput
= input
;
164 } /* namespace parser */
166 } /* namespace CVC4 */