summaryrefslogtreecommitdiff
path: root/src/parser/parser.h
blob: dbdca4af84a14996f3ffa79a7e52e14622003494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*********************                                           -*- C++ -*-  */
/** parser.h
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009 The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.
 **
 ** Parser abstraction.
 **/

#ifndef __CVC4__PARSER__PARSER_H
#define __CVC4__PARSER__PARSER_H

#include <string>
#include <iostream>
#include <fstream>
#include "cvc4_config.h"
#include "parser_exception.h"

namespace CVC4 {

// Forward declarations
class Expr;
class Command;
class ExprManager;

namespace parser {

class AntlrSmtLexer;
class AntlrSmtParser;
class AntlrCvcLexer;
class AntlrCvcParser;

/**
 * The parser.
 */
class CVC4_PUBLIC Parser {

public:

  /**
   * Construct the parser that uses the given expression manager.
   * @param em the expression manager.
   */
  Parser(ExprManager* em);

  /**
   * Destructor.
   */
  virtual ~Parser() {
  }

  /**
   * Parse the next command of the input
   */
  virtual Command* parseNextCommand() throw (ParserException) = 0;

  /**
   * Parse the next expression of the stream
   */
  virtual Expr parseNextExpression() throw (ParserException) = 0;

  /**
   * Check if we are done -- either the end of input has been reached.
   */
  bool done() const;

protected:

  /** Sets the done flag */
  void setDone(bool done = true);

  /** Expression manager the parser will be using */
  ExprManager* d_expr_manager;

  /** Are we done */
  bool d_done;

}; // end of class Parser

class CVC4_PUBLIC SmtParser : public Parser {

public:

  /**
   * Construct the parser that uses the given expression manager and parses
   * from the given input stream.
   * @param em the expression manager to use
   * @param input the input stream to parse
   */
  SmtParser(ExprManager* em, std::istream& input);

  /**
   * Construct the parser that uses the given expression manager and parses
   * from the file.
   * @param em the expression manager to use
   * @param file_name the file to parse
   */
  SmtParser(ExprManager* em, const char* file_name);

  /**
   * Destructor.
   */
  ~SmtParser();

  /**
   * Parses the next command. By default, the SMTLIB parser produces one
   * CommandSequence command. If parsing is successful, we should be done
   * after the first call to this command.
   * @return the CommandSequence command that includes the whole benchmark
   */
  Command* parseNextCommand() throw (ParserException);

  /**
   * Parses the next complete expression of the stream.
   * @return the expression parsed
   */
  Expr parseNextExpression() throw (ParserException);

protected:

  /** The ANTLR smt lexer */
  AntlrSmtLexer* d_antlr_lexer;

  /** The ANTLR smt parser */
  AntlrSmtParser* d_antlr_parser;

  /** The file stream we might be using */
  std::ifstream d_input;
};

class CVC4_PUBLIC CvcParser : public Parser {

public:

  /**
   * Construct the parser that uses the given expression manager and parses
   * from the given input stream.
   * @param em the expression manager to use
   * @param input the input stream to parse
   */
  CvcParser(ExprManager* em, std::istream& input);

  /**
   * Construct the parser that uses the given expression manager and parses
   * from the file.
   * @param em the expression manager to use
   * @param file_name the file to parse
   */
  CvcParser(ExprManager* em, const char* file_name);

  /**
   * Destructor.
   */
  ~CvcParser();

  /**
   * Parses the next command. By default, the SMTLIB parser produces one
   * CommandSequence command. If parsing is successful, we should be done
   * after the first call to this command.
   * @return the CommandSequence command that includes the whole benchmark
   */
  Command* parseNextCommand() throw (ParserException);

  /**
   * Parses the next complete expression of the stream.
   * @return the expression parsed
   */
  Expr parseNextExpression() throw (ParserException);

protected:

  /** The ANTLR smt lexer */
  AntlrCvcLexer* d_antlr_lexer;

  /** The ANTLR smt parser */
  AntlrCvcParser* d_antlr_parser;

  /** The file stream we might be using */
  std::ifstream d_input;
};


}/* CVC4::parser namespace */
}/* CVC4 namespace */

#endif /* __CVC4__PARSER__PARSER_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback