Skip to content

Commit 1aaaefb

Browse files
committed
SMT2 parser: support +oo, -oo, NaN
This adds support for three floating-point constants to the SMT2 parser, to enable the use of cprover_smt2 with CBMC.
1 parent bfd1e57 commit 1aaaefb

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/solvers/smt2/smt2_parser.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,10 @@ exprt smt2_parsert::function_application()
500500
if(next_token() != smt2_tokenizert::SYMBOL)
501501
throw error("expected symbol after '_'");
502502

503-
if(has_prefix(smt2_tokenizer.get_buffer(), "bv"))
503+
// copy, the reference won't be stable
504+
const auto id = smt2_tokenizer.get_buffer();
505+
506+
if(has_prefix(id, "bv"))
504507
{
505508
mp_integer i = string2integer(
506509
std::string(smt2_tokenizer.get_buffer(), 2, std::string::npos));
@@ -515,10 +518,36 @@ exprt smt2_parsert::function_application()
515518

516519
return from_integer(i, unsignedbv_typet(width));
517520
}
521+
else if(id == "+oo" || id == "-oo" || id == "NaN")
522+
{
523+
// These are the "plus infinity", "minus infinity" and NaN
524+
// floating-point literals.
525+
if(next_token() != smt2_tokenizert::NUMERAL)
526+
throw error() << "expected number after " << id;
527+
528+
auto width_e = std::stoll(smt2_tokenizer.get_buffer());
529+
530+
if(next_token() != smt2_tokenizert::NUMERAL)
531+
throw error() << "expected second number after " << id;
532+
533+
auto width_f = std::stoll(smt2_tokenizer.get_buffer());
534+
535+
if(next_token() != smt2_tokenizert::CLOSE)
536+
throw error() << "expected ')' after " << id;
537+
538+
// width_f *includes* the hidden bit
539+
const ieee_float_spect spec(width_f - 1, width_e);
540+
541+
if(id == "+oo")
542+
return ieee_floatt::plus_infinity(spec).to_expr();
543+
else if(id == "-oo")
544+
return ieee_floatt::minus_infinity(spec).to_expr();
545+
else // NaN
546+
return ieee_floatt::NaN(spec).to_expr();
547+
}
518548
else
519549
{
520-
throw error() << "unknown indexed identifier "
521-
<< smt2_tokenizer.get_buffer();
550+
throw error() << "unknown indexed identifier " << id;
522551
}
523552
}
524553
else if(smt2_tokenizer.get_buffer() == "!")

0 commit comments

Comments
 (0)