Skip to content

Commit ec43b05

Browse files
author
Daniel Kroening
committed
smt2_parser: implemented define-const
1 parent 4b91ee8 commit ec43b05

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
@@ -1089,6 +1089,38 @@ void smt2_parsert::command(const std::string &c)
10891089
entry.type = type;
10901090
entry.definition = nil_exprt();
10911091
}
1092+
else if(c == "define-const")
1093+
{
1094+
if(next_token() != SYMBOL)
1095+
throw error("expected a symbol after define-const");
1096+
1097+
const irep_idt id = buffer;
1098+
1099+
if(id_map.find(id) != id_map.end())
1100+
{
1101+
std::ostringstream msg;
1102+
msg << "identifier `" << id << "' defined twice";
1103+
throw error(msg.str());
1104+
}
1105+
1106+
const auto type = sort();
1107+
const auto value = expression();
1108+
1109+
// check type of value
1110+
if(value.type() != type)
1111+
{
1112+
std::ostringstream msg;
1113+
msg << "type mismatch in constant definition: expected `"
1114+
<< smt2_format(type) << "' but got `" << smt2_format(value.type())
1115+
<< '\'';
1116+
throw error(msg.str());
1117+
}
1118+
1119+
// create the entry
1120+
auto &entry = id_map[id];
1121+
entry.type = type;
1122+
entry.definition = value;
1123+
}
10921124
else if(c=="define-fun")
10931125
{
10941126
if(next_token()!=SYMBOL)

0 commit comments

Comments
 (0)