blob: 57d5e6c96aedb46f02fb69a2711f545f4cc6ad4b (
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
|
/********************* -*- C++ -*- */
/** cvc_parser.cpp
** Original author: mdeters
** Major contributors: none
** Minor contributors (to current version): dejan
** 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.
**
** CVC presentation language parser implementation.
**/
#include <iostream>
#include <fstream>
#include "parser/parser.h"
#include "util/command.h"
#include "util/Assert.h"
#include "parser/parser_exception.h"
#include "parser/antlr_parser.h"
#include "parser/cvc/cvc_parser.h"
#include "parser/cvc/generated/AntlrCvcParser.hpp"
#include "parser/cvc/generated/AntlrCvcLexer.hpp"
using namespace std;
namespace CVC4 {
namespace parser {
Command* CvcParser::parseNextCommand() throw(ParserException) {
Command* cmd = 0;
if(!done()) {
try {
cmd = d_antlr_parser->command();
if(cmd == 0) {
setDone();
cmd = new EmptyCommand("EOF");
}
} catch(antlr::ANTLRException& e) {
setDone();
throw ParserException(e.toString());
}
}
return cmd;
}
Expr CvcParser::parseNextExpression() throw(ParserException) {
Expr result;
if(!done()) {
try {
result = d_antlr_parser->formula();
} catch(antlr::ANTLRException& e) {
setDone();
throw ParserException(e.toString());
}
}
return result;
}
CvcParser::~CvcParser() {
delete d_antlr_parser;
delete d_antlr_lexer;
}
CvcParser::CvcParser(ExprManager*em, istream& input, const char* file_name) :
Parser(em), d_input(input) {
if(!d_input) {
throw ParserException(string("Read error") +
((file_name != NULL) ? (string(" on ") + file_name) : ""));
}
d_antlr_lexer = new AntlrCvcLexer(d_input);
d_antlr_lexer->setFilename(file_name);
d_antlr_parser = new AntlrCvcParser(*d_antlr_lexer);
d_antlr_parser->setExpressionManager(d_expr_manager);
d_antlr_parser->setFilename(file_name);
}
}/* CVC4::parser namespace */
}/* CVC4 namespace */
|