cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
smt2irep.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
#include "
smt2irep.h
"
10
11
#include <
util/message.h
>
12
13
#include <stack>
14
15
#include "
smt2_tokenizer.h
"
16
17
class
smt2irept
:
public
smt2_tokenizert
18
{
19
public
:
20
smt2irept
(std::istream &_in,
message_handlert
&message_handler)
21
:
smt2_tokenizert
(_in),
log
(message_handler)
22
{
23
}
24
25
std::optional<irept>
operator()
();
26
27
protected
:
28
messaget
log
;
29
};
30
31
std::optional<irept>
smt2irept::operator()
()
32
{
33
try
34
{
35
std::stack<irept> stack;
36
37
while
(
true
)
38
{
39
auto
token =
next_token
();
40
41
switch
(token)
42
{
43
case
END_OF_FILE:
44
if
(stack.empty())
45
return
{};
46
else
47
throw
error
(
"unexpected end of file"
);
48
49
case
STRING_LITERAL:
50
case
NUMERAL:
51
case
SYMBOL:
52
if
(stack.empty())
53
return
irept
{token.text};
// all done!
54
else
55
stack.top().get_sub().push_back(
irept
{token.text});
56
break
;
57
58
case
OPEN:
// '('
59
// produce sub-irep
60
stack.push(
irept
());
61
break
;
62
63
case
CLOSE:
// ')'
64
// done with sub-irep
65
if
(stack.empty())
66
throw
error
(
"unexpected ')'"
);
67
else
68
{
69
irept
tmp = stack.top();
70
stack.pop();
71
72
if
(stack.empty())
73
return
tmp;
// all done!
74
75
stack.top().get_sub().push_back(tmp);
76
break
;
77
}
78
79
case
NONE
:
80
case
KEYWORD:
81
throw
error
(
"unexpected token"
);
82
}
83
}
84
}
85
catch
(
const
smt2_errort
&e)
86
{
87
log
.error().source_location.set_line(e.
get_line_no
());
88
log
.error() << e.
what
() <<
messaget::eom
;
89
return
{};
90
}
91
}
92
93
std::optional<irept>
94
smt2irep
(std::istream &in,
message_handlert
&message_handler)
95
{
96
return
smt2irept
(in, message_handler)();
97
}
irept
There are a large number of kinds of tree structured or tree-like data in CPROVER.
Definition
irep.h:364
message_handlert
Definition
message.h:27
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition
message.h:154
messaget::eom
static eomt eom
Definition
message.h:289
smt2_tokenizert::smt2_errort
Exception thrown by the tokenizer (and the parser built on top of it) to report a syntactic error at ...
Definition
smt2_tokenizer.h:34
smt2_tokenizert::smt2_errort::get_line_no
unsigned get_line_no() const
Definition
smt2_tokenizer.h:60
smt2_tokenizert::smt2_errort::what
std::string what() const
Definition
smt2_tokenizer.h:55
smt2_tokenizert::next_token
tokent next_token()
Consume and return the next token.
Definition
smt2_tokenizer.cpp:204
smt2_tokenizert::smt2_tokenizert
smt2_tokenizert(std::istream &_in)
Definition
smt2_tokenizer.h:25
smt2_tokenizert::error
smt2_errort error() const
generate an error exception
Definition
smt2_tokenizer.h:142
smt2irept
Definition
smt2irep.cpp:18
smt2irept::log
messaget log
Definition
smt2irep.cpp:28
smt2irept::operator()
std::optional< irept > operator()()
Definition
smt2irep.cpp:31
smt2irept::smt2irept
smt2irept(std::istream &_in, message_handlert &message_handler)
Definition
smt2irep.cpp:20
complexity_violationt::NONE
@ NONE
Definition
complexity_violation.h:19
smt2_tokenizer.h
Tokenizer for the SMT-LIB v2.6 syntax.
smt2irep
std::optional< irept > smt2irep(std::istream &in, message_handlert &message_handler)
returns an irep for an SMT-LIB2 expression read from a given stream returns {} when EOF is encountere...
Definition
smt2irep.cpp:94
smt2irep.h
message.h
solvers
smt2
smt2irep.cpp
Generated by
1.17.0