Skip to content

Commit 3de0601

Browse files
polgreenkroening
authored andcommitted
SMT parser: function sorts ->
This adds support for parsing the candidate SMT-LIB 3 function sorts. Meaningful usage requires lambda expressions, which will follow as separate PR.
1 parent 9a04436 commit 3de0601

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/solvers/smt2/smt2_parser.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,32 @@ void smt2_parsert::setup_expressions()
12361236
expressions["fp.neg"] = [this] { return unary(ID_unary_minus, operands()); };
12371237
}
12381238

1239+
typet smt2_parsert::function_sort()
1240+
{
1241+
std::vector<typet> sorts;
1242+
1243+
// (-> sort+ sort)
1244+
// The last sort is the co-domain.
1245+
1246+
while(smt2_tokenizer.peek() != smt2_tokenizert::CLOSE)
1247+
{
1248+
if(smt2_tokenizer.peek() == smt2_tokenizert::END_OF_FILE)
1249+
throw error() << "unexpected end-of-file in a function sort";
1250+
1251+
sorts.push_back(sort()); // recursive call
1252+
}
1253+
1254+
next_token(); // eat the ')'
1255+
1256+
if(sorts.size() < 2)
1257+
throw error() << "expected function sort to have at least 2 type arguments";
1258+
1259+
auto codomain = std::move(sorts.back());
1260+
sorts.pop_back();
1261+
1262+
return mathematical_function_typet(std::move(sorts), std::move(codomain));
1263+
}
1264+
12391265
typet smt2_parsert::sort()
12401266
{
12411267
// a sort is one of the following three cases:
@@ -1334,6 +1360,8 @@ void smt2_parsert::setup_sorts()
13341360
else
13351361
throw error("unsupported array sort");
13361362
};
1363+
1364+
sorts["->"] = [this] { return function_sort(); };
13371365
}
13381366

13391367
smt2_parsert::signature_with_parameter_idst

src/solvers/smt2/smt2_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class smt2_parsert
177177

178178
// sorts
179179
typet sort();
180+
typet function_sort();
180181
std::unordered_map<std::string, std::function<typet()>> sorts;
181182
void setup_sorts();
182183

0 commit comments

Comments
 (0)