1 /********************* */
3 ** Original author: cconway
4 ** Major contributors: none
5 ** Minor contributors (to current version): mdeters
6 ** This file is part of the CVC4 prototype.
7 ** Copyright (c) 2009, 2010 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 abstraction.
16 #include "cvc4parser_public.h"
18 #ifndef __CVC4__PARSER__INPUT_H
19 #define __CVC4__PARSER__INPUT_H
23 #include "expr/expr.h"
24 #include "parser/parser_exception.h"
25 #include "parser/parser_options.h"
29 // Forward declarations
39 * An input to be parsed. This class serves two purposes: to the client, it provides
40 * the methods <code>parseNextCommand</code> and <code>parseNextExpression</code> to
41 * extract a stream of <code>Command</code>'s and <code>Expr</code>'s from the input;
42 * to the parser, it provides a repository for state data, like the variable symbol
43 * table, and a variety of convenience functions for updating and checking the state.
45 * An Input should be created using the static factory methods,
46 * e.g., <code>newFileParser</code> and <code>newStringInput</code>, and
47 * should be deleted when done.
49 class CVC4_PUBLIC Input
{
50 friend class ParserState
;
52 /** Whether to de-allocate the input */
53 // bool d_deleteInput;
55 ParserState
*d_parserState
;
60 * Create a new parser for the given file.
61 * @param exprManager the ExprManager to use
62 * @param filename the path of the file to parse
64 Input(ExprManager
* exprManager
, const std::string
& filename
);
71 /** Create an input for the given file.
73 * @param exprManager the ExprManager for creating expressions from the input
74 * @param lang the input language
75 * @param filename the input filename
77 static Input
* newFileInput(ExprManager
* exprManager
, InputLanguage lang
, const std::string
& filename
, bool useMmap
=false);
79 /** Create an input for the given stream.
81 * @param exprManager the ExprManager for creating expressions from the input
82 * @param lang the input language
83 * @param input the input stream
84 * @param name the name of the stream, for use in error messages
86 //static Parser* getNewParser(ExprManager* exprManager, InputLanguage lang, std::istream& input, const std::string& name);
88 /** Create an input for the given string
90 * @param exprManager the ExprManager for creating expressions from the input
91 * @param lang the input language
92 * @param input the input string
93 * @param name the name of the stream, for use in error messages
95 static Input
* newStringInput(ExprManager
* exprManager
, InputLanguage lang
, const std::string
& input
, const std::string
& name
);
98 * Check if we are done -- either the end of input has been reached, or some
99 * error has been encountered.
100 * @return true if parser is done
104 /** Enable semantic checks during parsing. */
107 /** Disable semantic checks during parsing. Disabling checks may lead to crashes on bad inputs. */
108 void disableChecks();
111 * Parse the next command of the input. If EOF is encountered a EmptyCommand
112 * is returned and done flag is set.
114 * @throws ParserException if an error is encountered during parsing.
116 Command
* parseNextCommand() throw(ParserException
);
119 * Parse the next expression of the stream. If EOF is encountered a null
120 * expression is returned and done flag is set.
121 * @return the parsed expression
122 * @throws ParserException if an error is encountered during parsing.
124 Expr
parseNextExpression() throw(ParserException
);
129 /** Called by <code>parseNextCommand</code> to actually parse a command from
130 * the input by invoking the implementation-specific parsing method. Returns
131 * <code>NULL</code> if there is no command there to parse.
133 * @throws ParserException if an error is encountered during parsing.
135 virtual Command
* doParseCommand() throw(ParserException
) = 0;
137 /** Called by <code>parseNextExpression</code> to actually parse an
138 * expression from the input by invoking the implementation-specific
139 * parsing method. Returns a null <code>Expr</code> if there is no
140 * expression there to parse.
142 * @throws ParserException if an error is encountered during parsing.
144 virtual Expr
doParseExpr() throw(ParserException
) = 0;
146 inline ParserState
* getParserState() const {
147 return d_parserState
;
152 /** Throws a <code>ParserException</code> with the given error message.
153 * Implementations should fill in the <code>ParserException</code> with
154 * line number information, etc. */
155 virtual void parseError(const std::string
& msg
) throw (ParserException
) = 0;
157 }; // end of class Input
159 }/* CVC4::parser namespace */
160 }/* CVC4 namespace */
162 #endif /* __CVC4__PARSER__INPUT_H */