DEADSOFTWARE

Patched for Linux
[mp3cc.git] / MPC.3.5.LINUX / lex / lex.yy.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "tokens.h"
5 #include "../util/strings.h"
6 #include "../util/error.h"
8 extern int mathType;
9 extern int goverify;
10 char charbuf[10240];
11 char textbuf[10240];
12 char strconst[10240];
13 int charcount;
14 FILE *yyin; //, *yyout; //source file
15 char *yytext; //current token string
16 string *string_constant;
17 char char_constant;
18 char boolean_constant;
19 float real_constant;
20 long int integer_constant;
21 int linenum;
22 int fileSize;
23 char c;
25 void yyrestart(char *fname) { //FILE *new_file){ //open source file
26 yyin = fopen(fname, "r");
27 if (yyin == NULL) die(5);
28 fseek(yyin, 0, SEEK_END);
29 fileSize = ftell(yyin);
30 fseek(yyin, 0, SEEK_SET);
31 charcount=0;
32 string_constant=&strconst;
33 yytext=&textbuf;
34 linenum=1;
35 };
37 char nextchar(){
38 int d;
39 if (charcount>0){
40 charcount--;
41 return charbuf[charcount];
42 }
43 d=fgetc(yyin);
44 if (d==10) linenum++;
45 if (d==EOF) return '\255';
46 return d;
47 }
49 void backchar(int c){ //put the char back to stream
50 charbuf[charcount]=c;
51 charcount++;
52 };
55 int yylex(){ //get token
56 int i,ncount,r;
57 char *p;
58 i = ftell(yyin);
59 compile_progress(i * 100 / fileSize);
60 do {
61 r=0;
62 //lab:
63 //if (linenum==1059) {
64 // linenum=1059;
65 //}
66 p=yytext;
67 *p='\0';
68 c=nextchar();
69 while ((c<=' ')&&(c!='\255')) c=nextchar();
70 if (((c>='A') && (c<='Z')) || ((c>='a') && (c<='z')) || (c=='_')) {
71 while (((c>='A') && (c<='Z')) || ((c>='a') && (c<='z')) || ((c>='0') && (c<='9')) || (c=='_')) {
72 *p=c;
73 p=p+1;
74 c=nextchar();
75 }
76 backchar(c);
77 *p='\0';
78 lowercase(yytext);
79 if (strcmp(yytext, "begin") == 0) return KWD_BEGIN;
80 if (strcmp(yytext, "end") == 0) return KWD_END;
81 if (strcmp(yytext, "and") == 0) return OP_AND;
82 if (strcmp(yytext, "program") == 0) return KWD_PROGRAM;
83 if (strcmp(yytext, "procedure") == 0) return KWD_PROCEDURE;
84 if (strcmp(yytext, "function") == 0) return KWD_FUNCTION;
85 if (strcmp(yytext, "var") == 0) return KWD_VAR;
86 if (strcmp(yytext, "for") == 0) return KWD_FOR;
87 if (strcmp(yytext, "to") == 0) return KWD_TO;
88 if (strcmp(yytext, "downto") == 0) return KWD_DOWNTO;
89 if (strcmp(yytext, "do") == 0) return KWD_DO;
90 if (strcmp(yytext, "const") == 0) return KWD_CONST;
91 if (strcmp(yytext, "type") == 0) return KWD_TYPE;
92 if (strcmp(yytext, "if") == 0) return KWD_IF;
93 if (strcmp(yytext, "then") == 0) return KWD_THEN;
94 if (strcmp(yytext, "else") == 0) return KWD_ELSE;
95 if (strcmp(yytext, "case") == 0) return KWD_CASE;
96 if (strcmp(yytext, "of") == 0) return KWD_OF;
97 if (strcmp(yytext, "while") == 0) return KWD_WHILE;
98 if (strcmp(yytext, "repeat") == 0) return KWD_REPEAT;
99 if (strcmp(yytext, "until") == 0) return KWD_UNTIL;
100 if (strcmp(yytext, "forever") == 0) return KWD_FOREVER;
101 if (strcmp(yytext, "with") == 0) return KWD_WITH;
102 if (strcmp(yytext, "packed") == 0) return KWD_PACKED;
103 if (strcmp(yytext, "array") == 0) return KWD_ARRAY;
104 if (strcmp(yytext, "or") == 0) return OP_OR;
105 if (strcmp(yytext, "file") == 0) return KWD_FILE;
106 if (strcmp(yytext, "set") == 0) return KWD_SET;
107 if (strcmp(yytext, "record") == 0) return KWD_RECORD;
108 if (strcmp(yytext, "in") == 0) return OP_IN;
109 if (strcmp(yytext, "not") == 0) return OP_NOT;
110 if (strcmp(yytext, "xor") == 0) return OP_XOR;
111 if (strcmp(yytext, "forward") == 0) return KWD_FORWARD;
112 if (strcmp(yytext, "break") == 0) return KWD_BREAK;
113 if (strcmp(yytext, "uses") == 0) return KWD_USES;
114 if (strcmp(yytext, "unit") == 0) return KWD_UNIT;
115 if (strcmp(yytext, "interface") == 0) return KWD_INTERFACE;
116 if (strcmp(yytext, "implementation") == 0) return KWD_IMPLEMENTATION;
117 if (strcmp(yytext, "initialization") == 0) return KWD_INITIALIZATION;
118 if (strcmp(yytext, "finalization") == 0) return KWD_FINALIZATION;
119 if (strcmp(yytext, "mod") == 0) return OP_MOD;
120 if (strcmp(yytext, "div") == 0) return OP_DIV;
121 if (strcmp(yytext, "shr") == 0) return OP_SHR; //***
122 if (strcmp(yytext, "shl") == 0) return OP_SHL; //***
123 if (strcmp(yytext, "ushr") == 0) return OP_USHR; // j-a-s-d
124 if (strcmp(yytext, "inline") == 0) return KWD_INLINE; //***?
125 if (strcmp(yytext, "bytecode") == 0) return KWD_BYTECODE; // j-a-s-d
126 if (strcmp(yytext, "exit") == 0) return KWD_EXIT; // j-a-s-d
127 if (strcmp(yytext, "result") == 0) return KWD_RESULT; // j-a-s-d
128 //////
129 if (strcmp(yytext, "true") == 0) {boolean_constant=1; return CST_BOOLEAN;}
130 if (strcmp(yytext, "false") == 0) {boolean_constant=0; return CST_BOOLEAN;}
131 //////
132 return IDENTIFIER;
133 } else if ((c>='0') && (c<='9')) {
134 integer_constant=0;
135 while ((c>='0') && (c<='9')) {
136 integer_constant=integer_constant*10+c-48;
137 c=nextchar();
139 if (c!='.') {backchar(c); return CST_INTEGER;}
140 c=nextchar();
141 if (c=='.') {backchar(c);backchar(c);return CST_INTEGER;}
142 real_constant=(float)integer_constant;
143 ncount=1;
144 integer_constant=0;
145 while ((c>='0') && (c<='9')) {
146 integer_constant=integer_constant*10+c-48;
147 ncount++;
148 c=nextchar();
150 //real_constant=real_constant+(float)integer_constant/(10*ncount);
151 // j-a-s-d: little but important bugfix, it was corrupting the decimal part
152 real_constant+=(float)integer_constant/pow(10,--ncount);
153 /*
154 i=1;
155 j=0;
156 ncount=1;
157 real_constant=(float)integer_constant;
158 while (((c>='0') && (c<='9'))) {
159 j=j*10+c-48;
160 i++;
161 c=nextchar();
163 real_constant=real_constant+(j/(10*i));
164 */
165 backchar(c);
166 return CST_REAL;
167 } else if (c=='$') {
168 int ok;
169 integer_constant=0;
170 do {
171 c=nextchar();
172 ok=0;
173 if ((c>='0') && (c<='9')) {
174 integer_constant = integer_constant*16+c-48;
175 ok=1;
177 if ((c>='A') && (c<='Z')) {
178 integer_constant = integer_constant*16+10+c-65;
179 ok=1;
181 if ((c>='a') && (c<='z')) {
182 integer_constant = integer_constant*16+10+c-97;
183 ok=1;
185 } while (ok==1);
186 backchar(c);
187 return CST_INTEGER;
188 } else if (c=='/') {
189 c=nextchar();
190 if (c=='*') { // j-a-s-d: C-style /* */ multiline comments support
191 char ch=c;
192 while (!((c=='/')&&(ch=='*'))) {ch=c; c=nextchar();}
193 r=1;
194 } else
195 if (c=='/') {
196 while (c!=10) c=nextchar();
197 //goto lab;
198 r=1;
199 } else {
200 backchar(c);
201 return OP_SLASH;
203 } else if ((c=='\'')||(c=='\"')||(c=='#')) { // j-a-s-d: C-style double-quoted strings support
204 char o_c = c;
205 i=0;
206 do {
207 if (c=='#') {
208 c=nextchar();
209 integer_constant=0;
210 if (c=='$') {
211 int ok;
212 do {
213 c=nextchar();
214 ok=0;
215 if ((c>='0') && (c<='9')) {
216 integer_constant = integer_constant*16+c-48;
217 ok=1;
219 if ((c>='A') && (c<='Z')) {
220 integer_constant = integer_constant*16+10+c-65;
221 ok=1;
223 if ((c>='a') && (c<='z')) {
224 integer_constant = integer_constant*16+10+c-97;
225 ok=1;
227 } while (ok==1);
228 } else {
229 while (((c>='0') && (c<='9'))) {
230 integer_constant=integer_constant*10+c-48;
231 c=nextchar();
234 *p=(char)integer_constant;
235 p=p+1;
236 i=i+1;
237 } else {
238 c=nextchar();
239 while (c!=o_c) {
240 if (c==10) {
241 int current_token;
242 add_error_message(101, "", "");
243 do {
244 current_token = yylex();
245 } while ((current_token != END_OF_INPUT) && (current_token != SEMI_COLON));
246 break;
248 rep: *p=c;
249 p=p+1;
250 i++;
251 c=nextchar();
253 c=nextchar();
254 if (c==o_c) goto rep;
256 } while ((c==o_c)||(c=='#'));
257 *p='\0';
258 backchar(c);
259 if (i==1) {p=p-1; char_constant=*p; return CST_CHAR;}
260 string_constant=string_from_cstr(yytext);
261 return CST_STRING;
262 } else if (c=='+') {
263 return OP_PLUS;
264 } else if (c=='-') {
265 return OP_MINUS;
266 } else if (c=='*') {
267 return OP_MULT;
268 } else if (c=='=') {
269 return OP_EQUAL;
270 } else if (c==';') {
271 return SEMI_COLON;
272 } else if (c==':') {
273 c=nextchar();
274 if (c=='=') return OP_ASSIGN;
275 backchar(c);
276 return COLON;
277 } else if (c=='<') {
278 c=nextchar();
279 if (c=='=') return OP_LESS_EQUAL;
280 if (c=='>') return OP_NOT_EQUAL;
281 if (c=='<') return OP_SHL;
282 backchar(c);
283 return OP_LESS;
284 } else if (c=='>') {
285 c=nextchar();
286 if (c=='=') return OP_GREATER_EQUAL;
287 if (c=='>') {
288 c=nextchar();
289 if (c=='>') return OP_USHR;
290 backchar(c);
291 return OP_SHR;
293 backchar(c);
294 return OP_GREATER;
295 } else if (c=='.') {
296 c=nextchar();
297 if (c=='.') return DOTDOT;
298 backchar(c);
299 return DOT;
300 } else if (c=='[') {
301 return OPEN_SQ_BR;
302 } else if (c==']') {
303 return CLOSE_SQ_BR;
304 } else if (c=='(') {
305 char ch;
306 c=nextchar();
307 if (c!='*') {
308 backchar(c);
309 return OPEN_BR;
311 ch=c;
312 while (!((c==')')&&(ch=='*'))) {ch=c; c=nextchar();}
313 //goto lab;
314 r=1;
315 } else if (c==')') {
316 return CLOSE_BR;
317 } else if (c==',') {
318 return COMMA;
319 } else if (c=='{') { //skip comment
320 c=nextchar();
321 // j-a-s-d: removing $R and $V to avoid ambiguities
322 /*
323 if (c=='$') {
324 c=nextchar();
325 if (c=='R') { //real type switch
326 c=nextchar();
327 if (c=='-') mathType=1;
328 if (c=='+') mathType=2;
330 if (c=='V') { //preverify_bytecode switch
331 c=nextchar();
332 if (c=='-') goverify=0;
333 if (c=='+') goverify=1;
336 */
337 while (c!='}') c=nextchar();
338 //goto lab;
339 r=1;
341 } while (r==1);
342 return END_OF_INPUT;
345 //#define CST_INTEGER 0
346 //#define CST_REAL 1
347 //#define CST_BOOLEAN 2
348 //#define CST_CHAR 3
349 //#define CST_STRING 4
350 //
351 //#define OP_MOD 5
352 //#define OP_DIV 6
353 //#define OP_PLUS 7
354 //#define OP_MINUS 8
355 //#define OP_MULT 9
356 //#define OP_SLASH 10
357 //#define OP_EQUAL 11
358 //#define SEMI_COLON 18
359 //#define COLON 19
360 //#define OP_ASSIGN 20
361 //#define OP_LESS 21
362 //#define OP_GREATER 22
363 //#define OP_LESS_EQUAL 23
364 //#define OP_GREATER_EQUAL 24
365 //#define OP_NOT_EQUAL 25
366 //#define DOT 26
367 //#define OPEN_SQ_BR 27
368 //#define CLOSE_SQ_BR 28
369 //#define OPEN_BR 34
370 //#define CLOSE_BR 35
371 //#define IDENTIFIER 57
372 //#define COMMA 58
373 //#define DOTDOT 59
374 //#define END_OF_INPUT 100
375 /*
376 #define CST_INTEGER 0
377 #define CST_REAL 1
378 #define CST_BOOLEAN 2
379 #define CST_CHAR 3
380 #define CST_STRING 4
381 #define OP_MOD 5
382 #define OP_DIV 6
383 #define OP_PLUS 7
384 #define OP_MINUS 8
385 #define OP_MULT 9
386 #define OP_SLASH 10
387 #define OP_EQUAL 11
388 #define KWD_BEGIN 12
389 #define KWD_END 13
390 #define OP_AND 14
391 #define KWD_PROGRAM 15
392 #define KWD_PROCEDURE 16
393 #define KWD_FUNCTION 17
394 #define SEMI_COLON 18
395 #define COLON 19
396 #define OP_ASSIGN 20
397 #define OP_LESS 21
398 #define OP_GREATER 22
399 #define OP_LESS_EQUAL 23
400 #define OP_GREATER_EQUAL 24
401 #define OP_NOT_EQUAL 25
402 #define DOT 26
403 #define OPEN_SQ_BR 27
404 #define CLOSE_SQ_BR 28
405 #define KWD_VAR 29
406 #define KWD_FOR 30
407 #define KWD_TO 31
408 #define KWD_DOWNTO 32
409 #define KWD_DO 33
410 #define OPEN_BR 34
411 #define CLOSE_BR 35
412 #define KWD_CONST 36
413 #define KWD_TYPE 37
414 #define KWD_IF 38
415 #define KWD_THEN 39
416 #define KWD_ELSE 40
417 #define KWD_CASE 41
418 #define KWD_OF 42
419 #define KWD_WHILE 43
420 #define KWD_REPEAT 44
421 #define KWD_UNTIL 45
422 #define KWD_WITH 46
423 #define KWD_PACKED 47
424 #define KWD_ARRAY 48
425 #define OP_OR 49
426 #define KWD_FILE 50
427 #define KWD_SET 51
428 #define KWD_RECORD 52
429 #define OP_IN 53
430 #define OP_NOT 54
431 #define OP_XOR 55
432 #define KWD_FORWARD 56
433 #define IDENTIFIER 57
434 #define COMMA 58
435 #define DOTDOT 59
436 #define KWD_BREAK 60
437 #define KWD_USES 61
438 #define KWD_UNIT 62
439 #define KWD_INTERFACE 63
440 #define KWD_IMPLEMENTATION 64
441 #define KWD_INITIALIZATION 65
442 #define KWD_FINALIZATION 66
443 #define END_OF_INPUT 100
445 /*
446 "mod" = (OP_MOD);
447 "div" = (OP_DIV);
448 "+" = (OP_PLUS);
449 "-" = (OP_MINUS);
450 "*" = (OP_MULT);
451 "/" = (OP_SLASH);
452 "=" = (OP_EQUAL);
453 "begin" = (KWD_BEGIN);
454 "end" = (KWD_END);
455 "and" = (OP_AND);
456 "program" = (KWD_PROGRAM);
457 "procedure" = (KWD_PROCEDURE);
458 "function" = (KWD_FUNCTION);
459 ";" = (SEMI_COLON);
460 ":" = (COLON);
461 ":=" = (OP_ASSIGN);
462 "<" = (OP_LESS);
463 ">" = (OP_GREATER);
464 "<=" = (OP_LESS_EQUAL);
465 ">=" = (OP_GREATER_EQUAL);
466 "<>" = (OP_NOT_EQUAL);
467 "." = (DOT);
468 ".." = (DOTDOT);
469 "[" = (OPEN_SQ_BR);
470 "]" = (CLOSE_SQ_BR);
471 "var" = (KWD_VAR);
472 "for" = (KWD_FOR);
473 "to" = (KWD_TO);
474 "downto" = (KWD_DOWNTO);
475 "do" = (KWD_DO);
476 "(" = (OPEN_BR);
477 ")" = (CLOSE_BR);
478 "const" = (KWD_CONST);
479 "type" = (KWD_TYPE);
480 "if" = (KWD_IF);
481 "then" = (KWD_THEN);
482 "else" = (KWD_ELSE);
483 "case" = (KWD_CASE);
484 "of" = (KWD_OF);
485 "while" = (KWD_WHILE);
486 "repeat" = (KWD_REPEAT);
487 "until" = (KWD_UNTIL);
488 "with" = (KWD_WITH);
489 "packed" = (KWD_PACKED);
490 "array" = (KWD_ARRAY);
491 "or" = (OP_OR);
492 "file" = (KWD_FILE);
493 "set" = (KWD_SET);
494 "record" = (KWD_RECORD);
495 "in" = (OP_IN);
496 "not" = (OP_NOT);
497 "xor" = (OP_XOR);
498 "forward" = (KWD_FORWARD);
499 "break" = (KWD_BREAK);
500 "," = (COMMA);
501 "uses" = (KWD_USES);
502 "unit" = (KWD_UNIT);
503 "interface" = (KWD_INTERFACE);
504 "implementation" = (KWD_IMPLEMENTATION);
505 "initialization" = (KWD_INITIALIZATION);
506 "finalization" = (KWD_FINALIZATION);
507 */
510 /*
511 c=nextchar();
512 i=0;
513 rep:
514 while (c!='\'') {
515 *p=c;
516 p=p+1;
517 i++;
518 c=nextchar();
520 c=nextchar();
521 if (c=='\'') {*p=c; p=p+1; i=i+1; c=nextchar(); goto rep;}
522 if (c=='#') {
523 j=0;
524 c=nextchar();
525 while (((c>='0') && (c<='9'))) {
526 j=j*10+c-48;
527 c=nextchar();
529 *p=(char)j;
530 p=p+1;
531 i=i+1;
532 goto rep;
534 */
536 /*
537 int getnum() { //get number
538 int sum;
539 sum=0;
540 ncount=1;
541 if (c=='$') {
542 c=nextchar();
543 do {
544 if ((c >= 'A') && (c <= 'Z')) {sum = sum*16+10+c-65; ncount=ncount+1;}
545 else if ((c >= 'a') && (c <= 'z')) {sum = sum*16+10+c-97; ncount=ncount+1;}
546 else if (('0'>=c) && (c<='9')) {sum = sum*16+c-48; ncount=ncount+1;}
547 else break;
548 c=nextchar();
549 } while (1==1);
550 } else {
551 while (('0'>=c) && (c<='9')) {
552 sum = sum*10+c-48;
553 ncount=ncount+1;
554 c=nextchar();
557 //if (numcount==1) backchar(255); //bad number
558 return sum;
560 */