Skip to content

Commit a0bfd42

Browse files
author
Daniel Kroening
committed
smt2irep now uses smt2_tokenizert
1 parent 3587184 commit a0bfd42

File tree

1 file changed

+61
-53
lines changed

1 file changed

+61
-53
lines changed

src/solvers/smt2/smt2irep.cpp

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,76 +11,84 @@ Author: Daniel Kroening, [email protected]
1111
#include <cassert>
1212
#include <stack>
1313

14-
#include "smt2_parser.h"
14+
#include "smt2_tokenizer.h"
1515

16-
class smt2irept:public smt2_parsert
16+
class smt2irept:public smt2_tokenizert
1717
{
1818
public:
19-
explicit smt2irept(std::istream &_in):smt2_parsert(_in)
19+
explicit smt2irept(std::istream &_in):smt2_tokenizert(_in)
2020
{
2121
}
2222

2323
inline irept operator()()
2424
{
25-
smt2_parsert::operator()();
25+
parse();
2626
return result;
2727
}
2828

29+
bool parse() override;
30+
2931
protected:
3032
irept result;
31-
std::stack<irept> stack;
32-
33-
// overload from smt2_parsert
34-
35-
virtual void symbol()
36-
{
37-
if(stack.empty())
38-
result=irept(buffer);
39-
else
40-
stack.top().get_sub().push_back(irept(buffer));
41-
}
42-
43-
virtual void string_literal()
44-
{
45-
symbol(); // we don't distinguish
46-
}
47-
48-
virtual void numeral()
49-
{
50-
symbol(); // we don't distinguish
51-
}
52-
53-
// '('
54-
virtual void open_expression()
55-
{
56-
// produce sub-irep
57-
stack.push(irept());
58-
}
59-
60-
// ')'
61-
virtual void close_expression()
62-
{
63-
// done with sub-irep
64-
assert(!stack.empty()); // unexpected )
65-
66-
irept tmp=stack.top();
67-
stack.pop();
68-
69-
if(stack.empty())
70-
result=tmp;
71-
else
72-
stack.top().get_sub().push_back(tmp);
73-
}
33+
};
7434

75-
virtual void keyword()
76-
{
77-
// ignore
78-
}
35+
bool smt2irept::parse()
36+
{
37+
std::stack<irept> stack;
38+
result.clear();
7939

80-
virtual void error(const std::string &message)
40+
while(true)
8141
{
42+
switch(next_token())
43+
{
44+
case END_OF_FILE:
45+
error() << "unexpected end of file" << eom;
46+
return true;
47+
48+
case STRING_LITERAL:
49+
case NUMERAL:
50+
case SYMBOL:
51+
if(stack.empty())
52+
{
53+
result=irept(buffer);
54+
return false; // all done!
55+
}
56+
else
57+
stack.top().get_sub().push_back(irept(buffer));
58+
break;
59+
60+
case OPEN: // '('
61+
// produce sub-irep
62+
stack.push(irept());
63+
break;
64+
65+
case CLOSE: // ')'
66+
// done with sub-irep
67+
if(stack.empty())
68+
{
69+
error() << "unexpected ')'" << eom;
70+
return true;
71+
}
72+
else
73+
{
74+
irept tmp=stack.top();
75+
stack.pop();
76+
77+
if(stack.empty())
78+
{
79+
result=tmp;
80+
return false; // all done!
81+
}
82+
83+
stack.top().get_sub().push_back(tmp);
84+
break;
85+
}
86+
87+
default:
88+
return true;
89+
}
8290
}
83-
};
91+
}
8492

8593
irept smt2irep(std::istream &in)
8694
{

0 commit comments

Comments
 (0)