nabaztag_hack_kit 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/README.md +119 -0
- data/Rakefile +21 -0
- data/bin/mtl_comp +41 -0
- data/bin/mtl_merge +22 -0
- data/bin/mtl_simu +40 -0
- data/bytecode/lib/buffer.mtl +109 -0
- data/bytecode/lib/button.mtl +27 -0
- data/bytecode/lib/data_helper.mtl +88 -0
- data/bytecode/lib/ear.mtl +90 -0
- data/bytecode/lib/led.mtl +33 -0
- data/bytecode/lib/rfid.mtl +50 -0
- data/bytecode/main.mtl +129 -0
- data/config.ru +6 -0
- data/ext/bytecode/Commands.md +172 -0
- data/ext/bytecode/Docs.md +488 -0
- data/ext/bytecode/README.md +5 -0
- data/ext/bytecode/lib/arp.mtl +159 -0
- data/ext/bytecode/lib/cfg.mtl +74 -0
- data/ext/bytecode/lib/choreos.mtl +1487 -0
- data/ext/bytecode/lib/dhcp.mtl +152 -0
- data/ext/bytecode/lib/dns.mtl +89 -0
- data/ext/bytecode/lib/http.mtl +84 -0
- data/ext/bytecode/lib/tcp.mtl +340 -0
- data/ext/bytecode/lib/udp.mtl +49 -0
- data/ext/bytecode/lib/util.mtl +74 -0
- data/ext/bytecode/lib/var.mtl +15 -0
- data/ext/bytecode/lib/wifi.mtl +243 -0
- data/ext/bytecode/nominal-ping.mtl +5828 -0
- data/ext/mtl/Makefile +42 -0
- data/ext/mtl/README.md +13 -0
- data/ext/mtl/bc.cpp +1891 -0
- data/ext/mtl/conf.bin.sans_password +0 -0
- data/ext/mtl/config.txt +5 -0
- data/ext/mtl/dumpbc.c +2566 -0
- data/ext/mtl/extconf.rb +1 -0
- data/ext/mtl/linux_simu.c +271 -0
- data/ext/mtl/linux_simuaudio.c +16 -0
- data/ext/mtl/linux_simuaudio.h +18 -0
- data/ext/mtl/linux_simunet.c +620 -0
- data/ext/mtl/linux_simunet.h +7 -0
- data/ext/mtl/log.c +297 -0
- data/ext/mtl/log.h +20 -0
- data/ext/mtl/main_compiler.cpp +104 -0
- data/ext/mtl/main_simu.cpp +221 -0
- data/ext/mtl/mp3/GTKANAL.H +97 -0
- data/ext/mtl/mp3/LAYER3.C +2090 -0
- data/ext/mtl/mp3/TABINIT.C +82 -0
- data/ext/mtl/mp3/common.c +265 -0
- data/ext/mtl/mp3/dct64_i386.c +316 -0
- data/ext/mtl/mp3/decode_i386.c +155 -0
- data/ext/mtl/mp3/huffman.h +332 -0
- data/ext/mtl/mp3/interface.c +258 -0
- data/ext/mtl/mp3/mpg123.h +182 -0
- data/ext/mtl/mp3/mpglib.h +44 -0
- data/ext/mtl/properties.c +293 -0
- data/ext/mtl/properties.h +10 -0
- data/ext/mtl/simu.c +750 -0
- data/ext/mtl/simuaudio.c +662 -0
- data/ext/mtl/simuaudio.h +74 -0
- data/ext/mtl/simunet.c +400 -0
- data/ext/mtl/simunet.h +30 -0
- data/ext/mtl/utils/correct_const.sh +34 -0
- data/ext/mtl/vaudio.c +677 -0
- data/ext/mtl/vaudio.h +46 -0
- data/ext/mtl/vbc.h +160 -0
- data/ext/mtl/vbc_str.h +166 -0
- data/ext/mtl/vcomp/Makefile +29 -0
- data/ext/mtl/vcomp/bootstrap.cpp +89 -0
- data/ext/mtl/vcomp/compiler.cpp +470 -0
- data/ext/mtl/vcomp/compiler.h +200 -0
- data/ext/mtl/vcomp/compiler_file.cpp +929 -0
- data/ext/mtl/vcomp/compiler_prog.cpp +250 -0
- data/ext/mtl/vcomp/compiler_term.cpp +1053 -0
- data/ext/mtl/vcomp/compiler_type.cpp +872 -0
- data/ext/mtl/vcomp/compiler_var.cpp +289 -0
- data/ext/mtl/vcomp/file.cpp +79 -0
- data/ext/mtl/vcomp/file.h +39 -0
- data/ext/mtl/vcomp/filesystem.h +14 -0
- data/ext/mtl/vcomp/interpreter.cpp +85 -0
- data/ext/mtl/vcomp/interpreter.h +121 -0
- data/ext/mtl/vcomp/memory.cpp +241 -0
- data/ext/mtl/vcomp/memory.h +326 -0
- data/ext/mtl/vcomp/param.h +95 -0
- data/ext/mtl/vcomp/parser.cpp +427 -0
- data/ext/mtl/vcomp/parser.h +97 -0
- data/ext/mtl/vcomp/parser_xml.cpp +124 -0
- data/ext/mtl/vcomp/prodbuffer.cpp +125 -0
- data/ext/mtl/vcomp/prodbuffer.h +42 -0
- data/ext/mtl/vcomp/resource.h +17 -0
- data/ext/mtl/vcomp/stdlib_core.cpp +122 -0
- data/ext/mtl/vcomp/terminal.cpp +73 -0
- data/ext/mtl/vcomp/terminal.h +30 -0
- data/ext/mtl/vcomp/util.cpp +48 -0
- data/ext/mtl/vcomp/util.h +31 -0
- data/ext/mtl/vinterp.c +1349 -0
- data/ext/mtl/vinterp.h +11 -0
- data/ext/mtl/vloader.c +127 -0
- data/ext/mtl/vloader.h +31 -0
- data/ext/mtl/vlog.c +589 -0
- data/ext/mtl/vlog.h +69 -0
- data/ext/mtl/vmem.c +424 -0
- data/ext/mtl/vmem.h +107 -0
- data/ext/mtl/vnet.c +255 -0
- data/ext/mtl/vnet.h +19 -0
- data/lib/nabaztag_hack_kit/message/api.rb +39 -0
- data/lib/nabaztag_hack_kit/message/helper.rb +39 -0
- data/lib/nabaztag_hack_kit/message.rb +36 -0
- data/lib/nabaztag_hack_kit/server.rb +50 -0
- data/lib/nabaztag_hack_kit/version.rb +3 -0
- data/lib/nabaztag_hack_kit.rb +4 -0
- data/nabaztag_hack_kit.gemspec +29 -0
- data/public/bytecode.bin +0 -0
- data/test/bytecode/helper.mtl +60 -0
- data/test/bytecode/native.mtl +28 -0
- data/test/bytecode/test.mtl +221 -0
- data/test/spec_helper.rb +5 -0
- data/test/unit/message_spec.rb +56 -0
- metadata +209 -0
@@ -0,0 +1,427 @@
|
|
1
|
+
//-------------------
|
2
|
+
// Moteur 3d
|
3
|
+
// version WIN32 et POCKETPC
|
4
|
+
// Sylvain Huet
|
5
|
+
// Premiere version : 03/09/2002
|
6
|
+
// Derniere mise a jour : 05/10/2002
|
7
|
+
//
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
#include <stdio.h>
|
12
|
+
#include <string.h>
|
13
|
+
|
14
|
+
#include "param.h"
|
15
|
+
#include "filesystem.h"
|
16
|
+
#include "file.h"
|
17
|
+
#include "parser.h"
|
18
|
+
#include "terminal.h"
|
19
|
+
#include "memory.h"
|
20
|
+
|
21
|
+
// test de lettre
|
22
|
+
int isletter(int c)
|
23
|
+
{
|
24
|
+
if ((c>='A')&&(c<='Z')) return 1;
|
25
|
+
if ((c>='a')&&(c<='z')) return 1;
|
26
|
+
if (c=='_') return 1;
|
27
|
+
return 0;
|
28
|
+
}
|
29
|
+
// test de chiffre decimal
|
30
|
+
int isnum(int c)
|
31
|
+
{
|
32
|
+
if ((c>='0')&&(c<='9')) return 1;
|
33
|
+
return 0;
|
34
|
+
}
|
35
|
+
// test de lettre
|
36
|
+
int ishex(int c)
|
37
|
+
{
|
38
|
+
if ((c>='0')&&(c<='9')) return 1;
|
39
|
+
if ((c>='A')&&(c<='F')) return 1;
|
40
|
+
if ((c>='a')&&(c<='f')) return 1;
|
41
|
+
return 0;
|
42
|
+
}
|
43
|
+
|
44
|
+
// test de lettre ou de chiffre
|
45
|
+
int isletnum(int c)
|
46
|
+
{
|
47
|
+
if ((c>='A')&&(c<='Z')) return 1;
|
48
|
+
if ((c>='a')&&(c<='z')) return 1;
|
49
|
+
if ((c>='0')&&(c<='9')) return 1;
|
50
|
+
if (c=='_') return 1;
|
51
|
+
return 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
// test si un mot est un label (une lettre puis des lettres ou des chiffres)
|
55
|
+
int islabel(char* src)
|
56
|
+
{
|
57
|
+
if (!isletter(*src++)) return 0;
|
58
|
+
while(*src)
|
59
|
+
{
|
60
|
+
if (!isletnum(*src++)) return 0;
|
61
|
+
}
|
62
|
+
return 1;
|
63
|
+
}
|
64
|
+
|
65
|
+
// test si un mot est un nombre d�cimal (que des chiffres)
|
66
|
+
int isdecimal(char* src)
|
67
|
+
{
|
68
|
+
while(*src)
|
69
|
+
{
|
70
|
+
if (!isnum(*src++)) return 0;
|
71
|
+
}
|
72
|
+
return 1;
|
73
|
+
}
|
74
|
+
|
75
|
+
// test si un mot est un nombre hexad�cimal (que des chiffres)
|
76
|
+
int ishexadecimal(char* src)
|
77
|
+
{
|
78
|
+
while(*src)
|
79
|
+
{
|
80
|
+
if (!ishex(*src++)) return 0;
|
81
|
+
}
|
82
|
+
return 1;
|
83
|
+
}
|
84
|
+
|
85
|
+
// test si un mot est un nombre flottant (que des chiffres avec un point)
|
86
|
+
int isfloat(char* src)
|
87
|
+
{
|
88
|
+
int debut=1;
|
89
|
+
int point=0;
|
90
|
+
while(*src)
|
91
|
+
{
|
92
|
+
if ((*src=='.')&&(!debut)&&(!point)) point=1;
|
93
|
+
else if (!isnum(*src)) return 0;
|
94
|
+
src++;
|
95
|
+
debut=0;
|
96
|
+
}
|
97
|
+
return point;
|
98
|
+
}
|
99
|
+
|
100
|
+
// retourne le code ascii correspondant � un chiffre hexad�cimal
|
101
|
+
int ctoh(int c)
|
102
|
+
{
|
103
|
+
c&=15;
|
104
|
+
if (c<10) return '0'+c;
|
105
|
+
return 'a'+c-10;
|
106
|
+
}
|
107
|
+
|
108
|
+
// retourne le chiffre correspondant � un code ascii hexad�cimal
|
109
|
+
int htoc(int c)
|
110
|
+
{
|
111
|
+
if ((c>='0')&&(c<='9')) return c-'0';
|
112
|
+
else if ((c>='A')&&(c<='F')) return c-'A'+10;
|
113
|
+
else if ((c>='a')&&(c<='f')) return c-'a'+10;
|
114
|
+
return 0;
|
115
|
+
}
|
116
|
+
|
117
|
+
// lecture d'une cha�ne d�cimale (s'arr�te au premier caract�re incorrect)
|
118
|
+
int mtl_atoi(char* src)
|
119
|
+
{
|
120
|
+
int x,c,s;
|
121
|
+
x=s=0;
|
122
|
+
if ((*src)=='-') { s=1; src++; }
|
123
|
+
while(c=*src++)
|
124
|
+
{
|
125
|
+
if ((c>='0')&&(c<='9')) x=(x*10)+c-'0';
|
126
|
+
else return (s?(-x):x);
|
127
|
+
}
|
128
|
+
return (s?(-x):x);
|
129
|
+
}
|
130
|
+
|
131
|
+
// lecture d'une cha�ne hexad�cimale (s'arr�te au premier caract�re incorrect)
|
132
|
+
int mtl_htoi(char* src)
|
133
|
+
{
|
134
|
+
int x,c;
|
135
|
+
x=0;
|
136
|
+
while(c=*src++)
|
137
|
+
{
|
138
|
+
if ((c>='0')&&(c<='9')) x=(x<<4)+c-'0';
|
139
|
+
else if ((c>='A')&&(c<='F')) x=(x<<4)+c-'A'+10;
|
140
|
+
else if ((c>='a')&&(c<='f')) x=(x<<4)+c-'a'+10;
|
141
|
+
else return x;
|
142
|
+
}
|
143
|
+
return x;
|
144
|
+
}
|
145
|
+
|
146
|
+
// lecture d'une cha�ne flottante (s'arr�te au premier caract�re incorrect)
|
147
|
+
mtl_float mtl_atof(char* src)
|
148
|
+
{
|
149
|
+
int c;
|
150
|
+
mtl_float f=0;
|
151
|
+
mtl_float div=1;
|
152
|
+
int point=0;
|
153
|
+
while(c=*src++)
|
154
|
+
{
|
155
|
+
if ((c=='.')&&(!point)) point=1;
|
156
|
+
else if ((c>='0')&&(c<='9'))
|
157
|
+
{
|
158
|
+
f=(f*10)+c-'0';
|
159
|
+
if (point) div*=10;
|
160
|
+
}
|
161
|
+
else return f/div;
|
162
|
+
}
|
163
|
+
return f/div;
|
164
|
+
}
|
165
|
+
|
166
|
+
Parser::Parser(Terminal* t,FileSystem* fs,const char *filename)
|
167
|
+
{
|
168
|
+
term=t;
|
169
|
+
|
170
|
+
srcname=new char[strlen(filename)+1];
|
171
|
+
strcpy(srcname,filename);
|
172
|
+
|
173
|
+
File* file=new File(fs);
|
174
|
+
int size;
|
175
|
+
|
176
|
+
src=NULL;
|
177
|
+
if (!file->openread(filename)) src=file->getcontent(&size);
|
178
|
+
delete file;
|
179
|
+
if (!src)
|
180
|
+
{
|
181
|
+
t->printf(LOG_WARNING,"Parser : cannot open file %s\n",filename);
|
182
|
+
src=new char[1];
|
183
|
+
src[0]=0;
|
184
|
+
}
|
185
|
+
index=0;
|
186
|
+
|
187
|
+
indexsavedchar=-1;
|
188
|
+
|
189
|
+
again=0;
|
190
|
+
|
191
|
+
lign=offligne=0;
|
192
|
+
lign0=offligne0=offchar0=0;
|
193
|
+
|
194
|
+
token=NULL;
|
195
|
+
}
|
196
|
+
|
197
|
+
Parser::Parser(Terminal* t,const char *buf)
|
198
|
+
{
|
199
|
+
srcname=NULL;
|
200
|
+
term=t;
|
201
|
+
src=new char[strlen(buf)+1];
|
202
|
+
strcpy(src,buf);
|
203
|
+
index=0;
|
204
|
+
|
205
|
+
indexsavedchar=-1;
|
206
|
+
|
207
|
+
again=0;
|
208
|
+
|
209
|
+
lign=offligne=0;
|
210
|
+
lign0=offligne0=offchar0=0;
|
211
|
+
|
212
|
+
token=NULL;
|
213
|
+
}
|
214
|
+
|
215
|
+
|
216
|
+
Parser::~Parser()
|
217
|
+
{
|
218
|
+
delete src;
|
219
|
+
if (srcname) delete srcname;
|
220
|
+
}
|
221
|
+
|
222
|
+
void Parser::giveback()
|
223
|
+
{
|
224
|
+
again=1;
|
225
|
+
}
|
226
|
+
|
227
|
+
char* Parser::next(int filter)
|
228
|
+
{
|
229
|
+
if (again)
|
230
|
+
{
|
231
|
+
again=0;
|
232
|
+
return token;
|
233
|
+
}
|
234
|
+
|
235
|
+
int i;
|
236
|
+
while(1)
|
237
|
+
{
|
238
|
+
int k;
|
239
|
+
do
|
240
|
+
{
|
241
|
+
k=gettoken(filter);
|
242
|
+
} while (k==-2);
|
243
|
+
if (k)
|
244
|
+
{
|
245
|
+
token=NULL;
|
246
|
+
return NULL;
|
247
|
+
}
|
248
|
+
// term->printf(0,"token=%s\n",token);
|
249
|
+
if (strcmp(token,"/*")) return token; // ok
|
250
|
+
i=1; // gestion des commentaires
|
251
|
+
while(i)
|
252
|
+
{
|
253
|
+
if (gettoken(filter)==-1)
|
254
|
+
{
|
255
|
+
term->printf(LOG_COMPILER,"unbalanced comment reaches EOF\n");
|
256
|
+
token=NULL;
|
257
|
+
return NULL;
|
258
|
+
}
|
259
|
+
if (!strcmp(token,"/*")) i++;
|
260
|
+
if (!strcmp(token,"*/")) i--;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
void Parser::savechar(int i)
|
266
|
+
{
|
267
|
+
indexsavedchar=i;
|
268
|
+
savedchar=src[i];
|
269
|
+
src[i]=0;
|
270
|
+
}
|
271
|
+
|
272
|
+
// demande de relire le dernier caract�re
|
273
|
+
void Parser::againchar()
|
274
|
+
{
|
275
|
+
index--;
|
276
|
+
if (src[index]==10) lign--;
|
277
|
+
}
|
278
|
+
|
279
|
+
// lit le prochain caract�re
|
280
|
+
int Parser::nextchar()
|
281
|
+
{
|
282
|
+
int c;
|
283
|
+
|
284
|
+
c=src[index];
|
285
|
+
if (c)
|
286
|
+
{
|
287
|
+
index++;
|
288
|
+
if (c==10)
|
289
|
+
{
|
290
|
+
offligne=index;
|
291
|
+
lign++;
|
292
|
+
}
|
293
|
+
}
|
294
|
+
return c;
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
void Parser::restorechar()
|
299
|
+
{
|
300
|
+
// on restaure le caract�re escamot� � la fin du token pr�c�dent
|
301
|
+
if (indexsavedchar!=-1)
|
302
|
+
{
|
303
|
+
src[indexsavedchar]=savedchar;
|
304
|
+
indexsavedchar=-1;
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
int Parser::gettoken(int filter)
|
309
|
+
{
|
310
|
+
int c,d,f;
|
311
|
+
|
312
|
+
restorechar();
|
313
|
+
|
314
|
+
do
|
315
|
+
{ // recherche le d�but du token
|
316
|
+
// on sauvegarde la position dans le source
|
317
|
+
lign0=lign;
|
318
|
+
offligne0=offligne;
|
319
|
+
offchar0=index;
|
320
|
+
c=nextchar();
|
321
|
+
if (!c) return -1; // fin du fichier, pas de nouveau token
|
322
|
+
} while(c<=32);
|
323
|
+
|
324
|
+
token=&src[offchar0];
|
325
|
+
|
326
|
+
f=0;
|
327
|
+
if (c=='\"') // token cha�ne de caract�res
|
328
|
+
while(1)
|
329
|
+
{
|
330
|
+
c=nextchar();
|
331
|
+
if (!c)
|
332
|
+
{
|
333
|
+
term->printf(LOG_COMPILER,"uncomplete string reaches EOF\n");
|
334
|
+
return -1;
|
335
|
+
}
|
336
|
+
if ((c=='\"')&&(f==0))
|
337
|
+
{
|
338
|
+
savechar(index);
|
339
|
+
return 0;
|
340
|
+
}
|
341
|
+
if (c=='\\') f=1-f;
|
342
|
+
else f=0;
|
343
|
+
}
|
344
|
+
if (isletnum(c)) // token nombre ou label
|
345
|
+
{
|
346
|
+
int onlynum=1;
|
347
|
+
while(1)
|
348
|
+
{
|
349
|
+
if (!isnum(c)) onlynum=0;
|
350
|
+
c=nextchar();
|
351
|
+
if (!c) return 0;
|
352
|
+
if ((c=='.')&&(onlynum)) // nombre flottant
|
353
|
+
{
|
354
|
+
while(1)
|
355
|
+
{
|
356
|
+
c=nextchar();
|
357
|
+
if (!c) return 0;
|
358
|
+
if (!isnum(c))
|
359
|
+
{
|
360
|
+
againchar();
|
361
|
+
savechar(index);
|
362
|
+
return 0;
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}
|
366
|
+
if (!isletnum(c))
|
367
|
+
{
|
368
|
+
againchar();
|
369
|
+
savechar(index);
|
370
|
+
return 0;
|
371
|
+
}
|
372
|
+
}
|
373
|
+
}
|
374
|
+
d=nextchar();
|
375
|
+
if (!d) return 0; // fin du fichier sur un caract�re sp�cial
|
376
|
+
|
377
|
+
if ( ((c=='&')&&(d=='&'))
|
378
|
+
||((c=='|')&&(d=='|'))
|
379
|
+
||((c==':')&&(d==':'))
|
380
|
+
||((c=='^')&&(d=='^'))
|
381
|
+
||((c==';')&&(d==';'))
|
382
|
+
||((c=='-')&&(d=='>'))
|
383
|
+
||((c=='<')&&((d=='<')||(d=='/')))
|
384
|
+
||((c=='>')&&(d=='>'))
|
385
|
+
||((c=='=')&&(d=='='))
|
386
|
+
||((c=='/')&&((d=='*')||(d=='>')))
|
387
|
+
||((c=='*')&&(d=='/'))
|
388
|
+
)
|
389
|
+
{
|
390
|
+
// caract�re double reconnu
|
391
|
+
}
|
392
|
+
else if ((c=='/')&&(d=='/'))
|
393
|
+
{
|
394
|
+
do // cas du commentaire //
|
395
|
+
{
|
396
|
+
c=nextchar();
|
397
|
+
if (c==10) return -2;
|
398
|
+
} while (c);
|
399
|
+
return -1; // fin de fichier, pas de nouveau token
|
400
|
+
}
|
401
|
+
else if (((c=='!')||(c=='>')||(c=='<'))&&(d=='='))
|
402
|
+
{
|
403
|
+
/* d=nextchar();
|
404
|
+
if (!d) return 0; // fin du fichier sur un caract�re sp�cial compos�
|
405
|
+
if (d!='.') againchar();
|
406
|
+
*/ }
|
407
|
+
else
|
408
|
+
againchar();
|
409
|
+
savechar(index);
|
410
|
+
return 0;
|
411
|
+
}
|
412
|
+
|
413
|
+
|
414
|
+
void Parser::echoposition()
|
415
|
+
{
|
416
|
+
restorechar();
|
417
|
+
if (srcname) term->printf(LOG_COMPILER,">line %d in '%s' :\n>",lign0+1,srcname);
|
418
|
+
else term->printf(LOG_COMPILER,">line %d :\n>",lign0+1);
|
419
|
+
char* p=&src[offligne0];
|
420
|
+
int i=0;
|
421
|
+
while((p[i])&&(p[i]!='\n')) i++;
|
422
|
+
term->echo(LOG_COMPILER,p,i);
|
423
|
+
term->printf(LOG_COMPILER,"\n>");
|
424
|
+
for(i=0;i<offchar0-offligne0;i++) { term->printf(LOG_COMPILER, "%c", (p[i]!='\t') ? ' ' : '\t'); }
|
425
|
+
term->printf(LOG_COMPILER,"^\n");
|
426
|
+
}
|
427
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
//-------------------
|
2
|
+
// Moteur 3d
|
3
|
+
// version WIN32 et POCKETPC
|
4
|
+
// Sylvain Huet
|
5
|
+
// Premiere version : 03/09/2002
|
6
|
+
// Derniere mise a jour : 05/10/2002
|
7
|
+
//
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
#ifndef _PARSER_
|
12
|
+
#define _PARSER_
|
13
|
+
|
14
|
+
#define MAXParser 1024
|
15
|
+
|
16
|
+
class FileSystem;
|
17
|
+
class File;
|
18
|
+
class Terminal;
|
19
|
+
class Memory;
|
20
|
+
class Parser
|
21
|
+
{
|
22
|
+
private :
|
23
|
+
Terminal* term;
|
24
|
+
char* srcname; // nom de la source
|
25
|
+
char* src; // buffer source
|
26
|
+
int index; // index de lecture
|
27
|
+
|
28
|
+
char savedchar; // caract�re sauvegard� (momentan�ment remplac� par \0)
|
29
|
+
int indexsavedchar; //index du caract�re sauvegard�
|
30
|
+
|
31
|
+
int again; // token a relire
|
32
|
+
int lign; // ligne courante
|
33
|
+
int offligne; // offset caractere debut ligne
|
34
|
+
|
35
|
+
int lign0; // ligne courante (DERNIER TOKEN LU)
|
36
|
+
int offligne0; // offset caractere debut ligne (DERNIER TOKEN LU)
|
37
|
+
int offchar0; // offset caractere courant (DERNIER TOKEN LU)
|
38
|
+
|
39
|
+
|
40
|
+
void savechar(int i);
|
41
|
+
void restorechar();
|
42
|
+
void againchar();
|
43
|
+
int nextchar();
|
44
|
+
int gettoken(int filter);
|
45
|
+
|
46
|
+
public :
|
47
|
+
char* token;
|
48
|
+
Parser(Terminal* t,FileSystem* fs,const char *filename);
|
49
|
+
Parser(Terminal* t,const char *buffer);
|
50
|
+
~Parser();
|
51
|
+
|
52
|
+
char* next(int filter);
|
53
|
+
void giveback();
|
54
|
+
|
55
|
+
void echoposition();
|
56
|
+
|
57
|
+
int parsekeyword(const char* keyword);
|
58
|
+
int parsekeyword(const char* keyword,int filter);
|
59
|
+
int getstring(Memory* m,char separator);
|
60
|
+
};
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
// test de lettre
|
66
|
+
int isletter(int c);
|
67
|
+
// test de chiffre decimal
|
68
|
+
int isnum(int c);
|
69
|
+
// test de lettre
|
70
|
+
int ishex(int c);
|
71
|
+
|
72
|
+
// test de lettre ou de chiffre
|
73
|
+
int isletnum(int c);
|
74
|
+
|
75
|
+
// test si un mot est un label (une lettre puis des lettres ou des chiffres)
|
76
|
+
int islabel(char* src);
|
77
|
+
// test si un mot est un nombre d�cimal (que des chiffres)
|
78
|
+
int isdecimal(char* src);
|
79
|
+
// test si un mot est un nombre hexad�cimal (que des chiffres)
|
80
|
+
int ishexadecimal(char* src);
|
81
|
+
// test si un mot est un flottant (que des chiffres avec un point apr�s la premi�re position)
|
82
|
+
int isfloat(char* src);
|
83
|
+
|
84
|
+
// retourne le code ascii correspondant � un chiffre hexad�cimal
|
85
|
+
int ctoh(int c);
|
86
|
+
// retourne le chiffre correspondant � un code ascii hexad�cimal
|
87
|
+
int htoc(int c);
|
88
|
+
|
89
|
+
// lecture d'une cha�ne d�cimale (s'arr�te au premier caract�re incorrect)
|
90
|
+
int mtl_atoi(char* src);
|
91
|
+
// lecture d'une cha�ne hexad�cimale (s'arr�te au premier caract�re incorrect)
|
92
|
+
int mtl_htoi(char* src);
|
93
|
+
// lecture d'une cha�ne flottant (s'arr�te au premier caract�re incorrect)
|
94
|
+
mtl_float mtl_atof(char* src);
|
95
|
+
|
96
|
+
|
97
|
+
#endif
|
@@ -0,0 +1,124 @@
|
|
1
|
+
//-------------------
|
2
|
+
// MV
|
3
|
+
// version WIN32 et POCKETPC
|
4
|
+
// Sylvain Huet
|
5
|
+
// Premiere version : 07/01/2003
|
6
|
+
// Derniere mise a jour : 07/01/2003
|
7
|
+
//
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <string.h>
|
11
|
+
|
12
|
+
#include "param.h"
|
13
|
+
#include "filesystem.h"
|
14
|
+
#include "file.h"
|
15
|
+
#include "parser.h"
|
16
|
+
#include "terminal.h"
|
17
|
+
#include "memory.h"
|
18
|
+
#include "util.h"
|
19
|
+
#include "interpreter.h"
|
20
|
+
#include "prodbuffer.h"
|
21
|
+
|
22
|
+
// lit un keyword impos�
|
23
|
+
int Parser::parsekeyword(const char* keyword)
|
24
|
+
{
|
25
|
+
if (!next(0))
|
26
|
+
{
|
27
|
+
term->printf(LOG_COMPILER,"Parser : '%s' expected (found EOF)\n");
|
28
|
+
return MTLERR_SN;
|
29
|
+
}
|
30
|
+
if (strcmp(token,keyword))
|
31
|
+
{
|
32
|
+
term->printf(LOG_COMPILER,"Parser : '%s' expected (found '%s')\n",keyword,token);
|
33
|
+
return MTLERR_SN;
|
34
|
+
}
|
35
|
+
return 0;
|
36
|
+
}
|
37
|
+
|
38
|
+
// lit un keyword impos�
|
39
|
+
int Parser::parsekeyword(const char* keyword,int filter)
|
40
|
+
{
|
41
|
+
if (!next(filter))
|
42
|
+
{
|
43
|
+
term->printf(LOG_COMPILER,"Parser : '%s' expected (found EOF)\n");
|
44
|
+
return MTLERR_SN;
|
45
|
+
}
|
46
|
+
if (strcmp(token,keyword))
|
47
|
+
{
|
48
|
+
term->printf(LOG_COMPILER,"Parser : '%s' expected (found '%s')\n",keyword,token);
|
49
|
+
return MTLERR_SN;
|
50
|
+
}
|
51
|
+
return 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
// parsing d'une cha�ne de caract�res
|
56
|
+
int Parser::getstring(Memory* m,char separator)
|
57
|
+
{
|
58
|
+
int c,n,i;
|
59
|
+
|
60
|
+
char* name=token;
|
61
|
+
name++;
|
62
|
+
|
63
|
+
Prodbuffer* output=m->util->interpreter->output;
|
64
|
+
output->reinit();
|
65
|
+
|
66
|
+
n=0;
|
67
|
+
while(1)
|
68
|
+
{
|
69
|
+
c=*(name++);
|
70
|
+
if (c=='\\')
|
71
|
+
{
|
72
|
+
c=(*(name++))&255;
|
73
|
+
if (c<32)
|
74
|
+
{
|
75
|
+
while(((*name)&255)<32) name++;
|
76
|
+
}
|
77
|
+
else
|
78
|
+
{
|
79
|
+
if (c=='n') c=10;
|
80
|
+
else if (c=='z') c=0;
|
81
|
+
else if (c=='$')
|
82
|
+
{
|
83
|
+
i=0;
|
84
|
+
c=*name;
|
85
|
+
if (ishex(c))
|
86
|
+
{
|
87
|
+
name++;
|
88
|
+
i=htoc(c);
|
89
|
+
c=*name;
|
90
|
+
if (ishex(c))
|
91
|
+
{
|
92
|
+
name++;
|
93
|
+
i=(i<<4)+htoc(c);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
c=i;
|
97
|
+
}
|
98
|
+
else if ((c>='0')&&(c<='9'))
|
99
|
+
{
|
100
|
+
i=c-'0';
|
101
|
+
c=*name;
|
102
|
+
if ((c>='0')&&(c<='9'))
|
103
|
+
{
|
104
|
+
name++;
|
105
|
+
i=(i*10)+c-'0';
|
106
|
+
c=*name;
|
107
|
+
if ((c>='0')&&(c<='9'))
|
108
|
+
{
|
109
|
+
name++;
|
110
|
+
i=(i*10)+c-'0';
|
111
|
+
}
|
112
|
+
}
|
113
|
+
c=i;
|
114
|
+
}
|
115
|
+
output->addchar(c);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
else if (c==separator)
|
119
|
+
{
|
120
|
+
return STRPUSHBINARY(m,output->getstart(),output->getsize());
|
121
|
+
}
|
122
|
+
else output->addchar(c);
|
123
|
+
}
|
124
|
+
}
|