cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
smt2_tokenizer.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
#ifndef CPROVER_SOLVERS_SMT2_SMT2_TOKENIZER_H
10
#define CPROVER_SOLVERS_SMT2_SMT2_TOKENIZER_H
11
12
#include <sstream>
13
#include <string>
14
15
class
smt2_tokenizert
16
{
17
public
:
18
explicit
smt2_tokenizert
(std::istream &_in) :
peeked
(false),
token
(
NONE
)
19
{
20
in
=&_in;
21
line_no
=1;
22
}
23
24
class
smt2_errort
25
{
26
public
:
27
smt2_errort
(
smt2_errort
&&) =
default
;
28
29
smt2_errort
(
const
smt2_errort
&other)
30
{
31
// ostringstream does not have a copy constructor
32
message
<< other.
message
.str();
33
line_no
= other.
line_no
;
34
}
35
36
smt2_errort
(
const
std::string &_message,
unsigned
_line_no)
37
:
line_no
(_line_no)
38
{
39
message
<< _message;
40
}
41
42
explicit
smt2_errort
(
unsigned
_line_no) :
line_no
(_line_no)
43
{
44
}
45
46
std::string
what
()
const
47
{
48
return
message
.str();
49
}
50
51
unsigned
get_line_no
()
const
52
{
53
return
line_no
;
54
}
55
56
std::ostringstream &
message_ostream
()
57
{
58
return
message
;
59
}
60
61
protected
:
62
std::ostringstream
message
;
63
unsigned
line_no
;
64
};
65
66
using
tokent
=
enum
{
67
NONE
,
68
END_OF_FILE,
69
STRING_LITERAL,
70
NUMERAL,
71
SYMBOL,
72
KEYWORD,
73
OPEN,
74
CLOSE
75
};
76
77
tokent
next_token
();
78
79
tokent
peek
()
80
{
81
if
(
peeked
)
82
return
token
;
83
else
84
{
85
get_token_from_stream
();
86
peeked
=
true
;
87
return
token
;
88
}
89
}
90
91
const
std::string &
get_buffer
()
const
92
{
93
return
buffer
;
94
}
95
96
bool
token_is_quoted_symbol
()
const
97
{
98
return
quoted_symbol
;
99
}
100
102
smt2_errort
error
(
const
std::string &message)
const
103
{
104
return
smt2_errort
(message,
line_no
);
105
}
106
108
smt2_errort
error
()
const
109
{
110
return
smt2_errort
(
line_no
);
111
}
112
113
protected
:
114
std::istream *
in
;
115
unsigned
line_no
;
116
std::string
buffer
;
117
bool
quoted_symbol
=
false
;
118
bool
peeked
;
119
tokent
token
;
120
123
void
skip_to_end_of_list
();
124
125
private
:
126
tokent
get_decimal_numeral
();
127
tokent
get_hex_numeral
();
128
tokent
get_bin_numeral
();
129
tokent
get_simple_symbol
();
130
tokent
get_quoted_symbol
();
131
tokent
get_string_literal
();
132
134
void
get_token_from_stream
();
135
};
136
138
template
<
typename
T>
139
smt2_tokenizert::smt2_errort
140
operator<<
(
smt2_tokenizert::smt2_errort
&&e,
const
T &message)
141
{
142
e.
message_ostream
() << message;
143
return
std::move(e);
144
}
145
146
bool
is_smt2_simple_symbol_character
(
char
);
147
148
#endif
// CPROVER_SOLVERS_SMT2_SMT2_PARSER_H
smt2_tokenizert::smt2_errort
Definition
smt2_tokenizer.h:25
smt2_tokenizert::smt2_errort::smt2_errort
smt2_errort(const smt2_errort &other)
Definition
smt2_tokenizer.h:29
smt2_tokenizert::smt2_errort::smt2_errort
smt2_errort(smt2_errort &&)=default
smt2_tokenizert::smt2_errort::smt2_errort
smt2_errort(const std::string &_message, unsigned _line_no)
Definition
smt2_tokenizer.h:36
smt2_tokenizert::smt2_errort::message
std::ostringstream message
Definition
smt2_tokenizer.h:62
smt2_tokenizert::smt2_errort::message_ostream
std::ostringstream & message_ostream()
Definition
smt2_tokenizer.h:56
smt2_tokenizert::smt2_errort::get_line_no
unsigned get_line_no() const
Definition
smt2_tokenizer.h:51
smt2_tokenizert::smt2_errort::smt2_errort
smt2_errort(unsigned _line_no)
Definition
smt2_tokenizer.h:42
smt2_tokenizert::smt2_errort::what
std::string what() const
Definition
smt2_tokenizer.h:46
smt2_tokenizert::smt2_errort::line_no
unsigned line_no
Definition
smt2_tokenizer.h:63
smt2_tokenizert::get_token_from_stream
void get_token_from_stream()
read a token from the input stream and store it in 'token'
Definition
smt2_tokenizer.cpp:211
smt2_tokenizert::get_string_literal
tokent get_string_literal()
Definition
smt2_tokenizer.cpp:170
smt2_tokenizert::get_decimal_numeral
tokent get_decimal_numeral()
Definition
smt2_tokenizer.cpp:57
smt2_tokenizert::next_token
tokent next_token()
Definition
smt2_tokenizer.cpp:201
smt2_tokenizert::tokent
enum { NONE, END_OF_FILE, STRING_LITERAL, NUMERAL, SYMBOL, KEYWORD, OPEN, CLOSE } tokent
Definition
smt2_tokenizer.h:66
smt2_tokenizert::smt2_tokenizert
smt2_tokenizert(std::istream &_in)
Definition
smt2_tokenizer.h:18
smt2_tokenizert::in
std::istream * in
Definition
smt2_tokenizer.h:114
smt2_tokenizert::error
smt2_errort error() const
generate an error exception
Definition
smt2_tokenizer.h:108
smt2_tokenizert::get_bin_numeral
tokent get_bin_numeral()
Definition
smt2_tokenizer.cpp:84
smt2_tokenizert::token
tokent token
Definition
smt2_tokenizer.h:119
smt2_tokenizert::get_simple_symbol
tokent get_simple_symbol()
Definition
smt2_tokenizer.cpp:24
smt2_tokenizert::get_quoted_symbol
tokent get_quoted_symbol()
Definition
smt2_tokenizer.cpp:142
smt2_tokenizert::get_buffer
const std::string & get_buffer() const
Definition
smt2_tokenizer.h:91
smt2_tokenizert::error
smt2_errort error(const std::string &message) const
generate an error exception, pre-filled with a message
Definition
smt2_tokenizer.h:102
smt2_tokenizert::token_is_quoted_symbol
bool token_is_quoted_symbol() const
Definition
smt2_tokenizer.h:96
smt2_tokenizert::line_no
unsigned line_no
Definition
smt2_tokenizer.h:115
smt2_tokenizert::buffer
std::string buffer
Definition
smt2_tokenizer.h:116
smt2_tokenizert::quoted_symbol
bool quoted_symbol
Definition
smt2_tokenizer.h:117
smt2_tokenizert::peek
tokent peek()
Definition
smt2_tokenizer.h:79
smt2_tokenizert::peeked
bool peeked
Definition
smt2_tokenizer.h:118
smt2_tokenizert::skip_to_end_of_list
void skip_to_end_of_list()
skip any tokens until all parentheses are closed or the end of file is reached
smt2_tokenizert::get_hex_numeral
tokent get_hex_numeral()
Definition
smt2_tokenizer.cpp:113
complexity_violationt::NONE
@ NONE
Definition
complexity_violation.h:19
operator<<
smt2_tokenizert::smt2_errort operator<<(smt2_tokenizert::smt2_errort &&e, const T &message)
add to the diagnostic information in the given smt2_tokenizer exception
Definition
smt2_tokenizer.h:140
is_smt2_simple_symbol_character
bool is_smt2_simple_symbol_character(char)
Definition
smt2_tokenizer.cpp:11
solvers
smt2
smt2_tokenizer.h
Generated by
1.17.0