-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
196 lines (131 loc) · 4.08 KB
/
Copy pathparser.h
File metadata and controls
196 lines (131 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#ifndef __parser_h__
#define __parser_h__
#include <lemon_base.h>
#include <vector>
#include <string>
#include "types.h"
#include "token.h"
//#include "symbol_table.h"
#include "common.h"
#include "include/scoped_map.h"
class parser : public lemon_base<Token> {
public:
enum SegmentType {
none,
code,
data,
};
static std::unique_ptr<parser> make();
//using lemon_base::parse;
SegmentQueue segments();
std::vector<identifier> imports();
std::vector<identifier> exports();
void error(const Token &t, const char *format, ...);
void error(const char *format, ...);
void verror(const Token &where, const char *format, va_list ap);
void warn(const Token &t, const char *format, ...);
void warn(const char *format, ...);
void vwarn(const Token &where, const char *format, va_list ap);
int error_count() const { return _error; }
int warn_count() const { return _warn; }
void parse_token(Token &&);
void drain_queue();
std::unique_ptr<Module> module();
protected:
identifier expand_at(identifier id);
identifier expand_at(const Token &t);
identifier add_label(identifier label, bool hidden = false);
identifier add_label(const Token &t, bool hidden = false);
void add_line(BasicLinePtr &&line);
void add_lines(std::vector<BasicLinePtr> &&line);
//void add_dc(Token &t, int size, ExpressionPtr e);
void add_ds(Token &t, identifier label, int size, ExpressionPtr e);
void begin_segment(identifier name, SegmentType type);
void end_segment();
identifier gen_sym();
virtual void syntax_error(int yymajor, token_type &yyminor) override;
virtual void parse_failure() override;
void expand_include(const Token &t, filesystem::path p);
void expand_macro(const Token &t, std::vector<Token> &&arguments);
bool check_macro(Token &t);
bool check_opcode(Token &t);
bool check_equate(Token &t);
std::deque<Token> _queue;
std::unordered_set<identifier> _export_set;
scoped_map<identifier, identifier> _import_set;
scoped_map<identifier, int> _entry_set;
// labels in the current segment.
std::unordered_set<identifier> _labels;
// records...
//symbol_table _equates;
scoped_map<identifier, ExpressionPtr> _equates;
scoped_map<identifier, identifier> _types;
SegmentQueue _segments;
std::unique_ptr<Segment> _data_segment; // anonymous data segment.
// current segment.
Segment *_segment = nullptr;
LineQueue _lines;
SegmentType _seg_type = none;
unsigned _error = 0;
unsigned _warn = 0;
unsigned _gen_sym = 0;
std::vector<identifier> _file_stack;
identifier _current_file = nullptr;
std::vector<identifier> _macro_stack;
identifier _current_macro = nullptr;
identifier _current_label = nullptr;
/* opcode for current line. used by error/warn. */
Token _opcode = {};
protected:
/*
* macro stuff
*/
bool install_macro(const Token &t, const std::vector<Token> &formal);
bool install_equate(const Token &t, ExpressionPtr &e);
struct macro {
identifier name = nullptr;
identifier file = nullptr;
int line = 0;
bool variadic = false; // true if last parm is &xxx....
std::vector<identifier> params;
std::vector<Token> body;
};
macro _tmp_macro;
std::unordered_map<identifier, macro> _macros;
protected:
/*
* record stuff
*/
struct field {
identifier name = nullptr;
int offset = 0;
identifier record = nullptr;
};
struct record {
identifier name = nullptr;
identifier file = nullptr;
int line = 0;
int offset = 0;
int size = 0;
std::vector< field > fields;
};
record _tmp_record;
std::unordered_map<identifier, record> _records;
identifier install_record_label(const Token &t);
bool install_record_ds(const Token &t, identifier label, int modifier, ExpressionPtr e);
bool install_record(const Token &t);
/*
* record . field resolution is deferred until the end of the segment so
* labels can be defined later in the segment.
*/
std::unordered_map<identifier, std::vector<Token>> _pending_records;
void resolve_records();
void verify_identifiers();
int field_offset(const record &r, std::vector<Token> &tokens);
protected:
/*
* include stuff.
*/
std::vector<filesystem::path> _include_paths;
};
#endif