Skip to content

Commit 5adf584

Browse files
author
Daniel Kroening
committed
smt2_parser: implemented define-const
1 parent 778fbdf commit 5adf584

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/solvers/smt2/smt2_parser.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,38 @@ void smt2_parsert::command(const std::string &c)
11031103
entry.type = type;
11041104
entry.definition = nil_exprt();
11051105
}
1106+
else if(c == "define-const")
1107+
{
1108+
if(next_token() != SYMBOL)
1109+
throw error("expected a symbol after define-const");
1110+
1111+
const irep_idt id = buffer;
1112+
1113+
if(id_map.find(id) != id_map.end())
1114+
{
1115+
std::ostringstream msg;
1116+
msg << "identifier `" << id << "' defined twice";
1117+
throw error(msg.str());
1118+
}
1119+
1120+
const auto type = sort();
1121+
const auto value = expression();
1122+
1123+
// check type of value
1124+
if(value.type() != type)
1125+
{
1126+
std::ostringstream msg;
1127+
msg << "type mismatch in constant definition: expected `"
1128+
<< smt2_format(type) << "' but got `" << smt2_format(value.type())
1129+
<< '\'';
1130+
throw error(msg.str());
1131+
}
1132+
1133+
// create the entry
1134+
auto &entry = id_map[id];
1135+
entry.type = type;
1136+
entry.definition = value;
1137+
}
11061138
else if(c=="define-fun")
11071139
{
11081140
if(next_token()!=SYMBOL)

0 commit comments

Comments
 (0)