Skip to content

Commit 439d38c

Browse files
author
Daniel Kroening
committed
smt2 parser: term attributes
Term attributes are used for a) named terms, and b) patterns for quantifiers.
1 parent 8e3e625 commit 439d38c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/solvers/smt2/smt2_parser.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,39 @@ exprt smt2_parsert::function_application()
427427
throw error(msg.str());
428428
}
429429
}
430+
else if(buffer == "!")
431+
{
432+
// these are "term attributes"
433+
const auto term = expression();
434+
435+
while(peek() == KEYWORD)
436+
{
437+
next_token(); // eat the keyword
438+
if(buffer == "named")
439+
{
440+
// 'named terms' must be Boolean
441+
if(term.type().id() != ID_bool)
442+
throw error("named terms must be Boolean");
443+
444+
if(next_token() == SYMBOL)
445+
{
446+
const symbol_exprt symbol_expr(buffer, bool_typet());
447+
auto &named_term = named_terms[symbol_expr.get_identifier()];
448+
named_term.term = term;
449+
named_term.name = symbol_expr;
450+
}
451+
else
452+
throw error("invalid name attribute, expected symbol");
453+
}
454+
else
455+
throw error("unknown term attribute");
456+
}
457+
458+
if(next_token() != CLOSE)
459+
throw error("expected ')' at end of term attribute");
460+
else
461+
return term;
462+
}
430463
else
431464
{
432465
// non-indexed symbol; hash it

src/solvers/smt2/smt2_parser.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ class smt2_parsert:public smt2_tokenizert
4242
using id_mapt=std::map<irep_idt, idt>;
4343
id_mapt id_map;
4444

45+
struct named_termt
46+
{
47+
exprt term;
48+
symbol_exprt name;
49+
};
50+
51+
using named_termst = std::map<irep_idt, named_termt>;
52+
named_termst named_terms;
53+
4554
bool exit;
4655

4756
/// This skips tokens until all bracketed expressions are closed

0 commit comments

Comments
 (0)