ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
parser.h
Go to the documentation of this file.
1#ifndef CPROVER_PARSER_H
2#define CPROVER_PARSER_H
3
4#include <string>
5#include <util/irep/expr.h>
7#include <vector>
8#include <istream>
9
11{
12public:
13 std::istream *in;
15
16 unsigned line_no;
17 std::string last_line;
18
19 std::vector<exprt> stack;
20
21 virtual void clear()
22 {
23 line_no = 0;
24 stack.clear();
25 filename.clear();
26 char_buffer.clear();
27 }
28
30 {
31 clear();
32 }
33
34 parsert(const parsert &obj) = delete;
35 parsert &operator=(const parsert &rhs) = delete;
36
37 virtual bool read(char &ch)
38 {
39 if (!read2(ch))
40 return false;
41
42 if (ch == '\n')
43 last_line = "";
44 else
45 last_line += ch;
46
47 return true;
48 }
49
50 virtual bool parse()
51 {
52 return true;
53 }
54
55 virtual bool peek(char &ch)
56 {
57 if (!char_buffer.empty())
58 {
59 ch = char_buffer.front();
60 return true;
61 }
62
63 if (!in->read(&ch, 1))
64 return false;
65
66 char_buffer.push_back(ch);
67 return true;
68 }
69
70 virtual bool eof()
71 {
72 return char_buffer.empty() && in->eof();
73 }
74
75 void parse_error(const std::string &message, const std::string &before);
76
78 {
79 locationt &l = e.location();
80
82
83 if (filename != "")
85
86 if (function != "")
88 }
89
90private:
91 virtual bool read2(char &ch)
92 {
93 if (!char_buffer.empty())
94 {
95 ch = char_buffer.front();
96 char_buffer.pop_front();
97 return true;
98 }
99
100 in->read(&ch, 1);
101 return !in->fail();
102 }
103
104 std::list<char> char_buffer;
105};
106
107exprt &_newstack(parsert &parser, unsigned &x);
108
109#define YY_INPUT(buf, result, max_size) \
110 do \
111 { \
112 for (result = 0; result < max_size;) \
113 { \
114 char ch; \
115 if (!PARSER.read(ch)) \
116 { \
117 if (result == 0) \
118 result = YY_NULL; \
119 break; \
120 } \
121 \
122 if (ch != '\r') \
123 { \
124 buf[result++] = ch; \
125 if (ch == '\n') \
126 { \
127 ++PARSER.line_no; \
128 break; \
129 } \
130 } \
131 } \
132 } while (0)
133#endif
Definition expr.h:34
Definition irep_idt.h:12
Definition location.h:7
void set_file(const irep_idt &file)
Definition location.h:31
void set_function(const irep_idt &function)
Definition location.h:56
void set_line(const irep_idt &line)
Definition location.h:36
Definition parser.h:11
virtual bool parse()
Definition parser.h:50
irep_idt filename
Definition parser.h:14
irep_idt function
Definition parser.h:14
std::istream * in
Definition parser.h:13
virtual bool peek(char &ch)
Definition parser.h:55
std::string last_line
Definition parser.h:17
parsert & operator=(const parsert &rhs)=delete
parsert()
Definition parser.h:29
virtual bool eof()
Definition parser.h:70
parsert(const parsert &obj)=delete
virtual bool read(char &ch)
Definition parser.h:37
void set_location(exprt &e)
Definition parser.h:77
void parse_error(const std::string &message, const std::string &before)
Definition parser.cpp:23
std::vector< exprt > stack
Definition parser.h:19
unsigned line_no
Definition parser.h:16
virtual void clear()
Definition parser.h:21
Definition __init__.py:1
exprt & _newstack(parsert &parser, unsigned &x)
Definition parser.cpp:12