@@ -11,76 +11,84 @@ Author: Daniel Kroening, kroening@kroening.com
11
11
#include < cassert>
12
12
#include < stack>
13
13
14
- #include " smt2_parser .h"
14
+ #include " smt2_tokenizer .h"
15
15
16
- class smt2irept :public smt2_parsert
16
+ class smt2irept :public smt2_tokenizert
17
17
{
18
18
public:
19
- explicit smt2irept (std::istream &_in):smt2_parsert (_in)
19
+ explicit smt2irept (std::istream &_in):smt2_tokenizert (_in)
20
20
{
21
21
}
22
22
23
23
inline irept operator ()()
24
24
{
25
- smt2_parsert::operator () ();
25
+ parse ();
26
26
return result;
27
27
}
28
28
29
+ bool parse () override ;
30
+
29
31
protected:
30
32
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
+ };
74
34
75
- virtual void keyword ()
76
- {
77
- // ignore
78
- }
35
+ bool smt2irept::parse ()
36
+ {
37
+ std::stack<irept> stack;
38
+ result. clear ();
79
39
80
- virtual void error ( const std::string &message )
40
+ while ( true )
81
41
{
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
+ }
82
90
}
83
- };
91
+ }
84
92
85
93
irept smt2irep (std::istream &in)
86
94
{
0 commit comments