This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.h
245 lines (210 loc) · 6.12 KB
/
token.h
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
Copyright (c) 2002-2012 René Ladan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef BF2C_TOKEN_H
#define BF2C_TOKEN_H 1
typedef enum { ttToken, ttPtr, ttVal, ttPut, ttGet, ttDo, ttOd, ttEof,
ttMulzero } tokenType;
typedef enum { dtWhile, dtIf, dtFor } doType;
/* generic token */
class Token {
public:
Token();
virtual ~Token();
virtual int getValue();
virtual int getOffset();
virtual int getCount();
virtual bool isAbsoluteValue();
virtual bool isAbsoluteOffset();
virtual int getOffsetDestination();
virtual int getOffsetSource();
virtual int getMultiplier();
virtual doType getDoType();
virtual bool isWrapped();
virtual bool isAbsoluteOffsetDestination();
virtual bool isAbsoluteOffsetSource();
virtual tokenType getType();
virtual char *getName();
virtual char *getCode();
virtual bool interpret(unsigned **array, unsigned *pointer,
bool running, unsigned range);
virtual bool isUsable();
virtual void setValue(int value);
virtual void setOffset(int offset);
virtual void setCount(int count);
virtual void makeAbsoluteValue(bool absoluteValue);
virtual void makeAbsoluteOffset(bool absoluteOffset);
virtual void setDoType(doType dotype);
virtual void setOffsetDestination(int ofsdest);
virtual void setOffsetSource(int ofssrc);
virtual void setMultiplier(int mult);
virtual void setWrapped(bool wrapped);
virtual void makeAbsoluteOffsetDestination(bool absofsdest);
virtual void makeAbsoluteOffsetSource(bool absofssrc);
protected:
virtual void format(char **dest, char *head, int value,
bool absolutevalue);
char *myname;
tokenType mytype;
};
class Ptr : public Token {
/* tokens : < >
* relative: p++, p--, p += N, p -= N
* absolute: p = N
*/
public:
Ptr();
bool isUsable();
int getValue();
bool isAbsoluteValue();
char *getCode();
bool interpret(unsigned **array, unsigned *pointer, bool running, unsigned range);
void setValue(int value);
void makeAbsoluteValue(bool absoluteValue);
private:
int myvalue;
bool myabsolutevalue;
};
class Val : public Token {
/* tokens : - + */
/* relative,relative: a[p+M]++, a[p-M]++, a[p+M]--, a[p-M]--, a[p+M] += N, a[p+M] -= N, a[p] += N, a[p] -= N
* relative,absolute: a[p+M] = N, a[p-M] = N, a[p] = N
* absolute,relative: a[M]++, a[M]--, a[M] += N, a[M] -= N
* absolute,absolute: a[M] = N
*/
public:
Val();
bool isUsable();
int getValue();
int getOffset();
bool isAbsoluteValue();
bool isAbsoluteOffset();
char *getCode();
bool interpret(unsigned **array, unsigned *pointer, bool running, unsigned range);
void setValue(int value);
void setOffset(int offset);
void makeAbsoluteValue(bool absoluteValue);
void makeAbsoluteOffset(bool absoluteOffset);
private:
int myvalue;
int myoffset;
bool myabsolutevalue;
bool myabsoluteoffset;
};
class Put : public Token {
/* . */
public:
Put();
bool isUsable();
int getCount();
int getOffset();
int getValue();
bool isAbsoluteOffset();
bool isAbsoluteValue();
char *getCode();
bool interpret(unsigned **array, unsigned *pointer, bool running, unsigned range);
void setCount(int count);
void setOffset(int offset);
void setValue(int value);
void makeAbsoluteOffset(bool absoluteoffset);
void makeAbsoluteValue(bool absolutevalue);
private:
int mycount;
int myoffset;
bool myabsoluteoffset;
int myvalue;
bool myabsolutevalue;
};
class Get : public Token {
/* , */
public:
Get();
bool isUsable();
int getCount();
int getOffset();
bool isAbsoluteOffset();
char *getCode();
bool interpret(unsigned **array, unsigned *pointer, bool running, unsigned range);
void setCount(int count);
void setOffset(int offset);
void makeAbsoluteOffset(bool absoluteoffset);
private:
int mycount;
int myoffset;
bool myabsoluteoffset;
};
class Do : public Token {
/* [ */
public:
Do();
bool isUsable();
doType getDoType();
char *getCode();
bool interpret(unsigned **array, unsigned *pointer, bool running, unsigned range);
void setDoType(doType dotype);
private:
doType mydotype;
};
class Od : public Token {
/* ] */
public:
Od();
bool isUsable();
char *getCode();
bool interpret(unsigned **array, unsigned *pointer, bool running, unsigned range);
};
class Eof : public Token {
/* EOF */
public:
Eof();
bool isUsable();
char *getCode();
bool interpret(unsigned **array, unsigned *pointer, bool running, unsigned range);
};
class Mulzero : public Token {
/* (optimized) */
public:
Mulzero();
bool isUsable();
int getOffsetDestination();
int getOffsetSource();
int getMultiplier();
bool isWrapped();
bool isAbsoluteOffsetDestination();
bool isAbsoluteOffsetSource();
char *getCode();
bool interpret(unsigned **array, unsigned *pointer, bool running, unsigned range);
void setOffsetDestination(int ofsdest);
void setOffsetSource(int ofssrc);
void setMultiplier(int mult);
void setWrapped(bool wrapped);
void makeAbsoluteOffsetDestination(bool absofsdest);
void makeAbsoluteOffsetSource(bool absofssrc);
private:
int myofsdest;
int myofssrc;
int mymult;
bool mywrapped;
bool myabsofsdest;
bool myabsofssrc;
};
#endif