1 using System;
2 using System.Lex;
3 using MdbTokens;
4
5
6
7 public class MdbLexer : System.Lex.Lexer
8 {
9 public MdbLexer(const ustring& content_, const string& fileName_, int fileIndex_) :
10 base(content_, fileName_, fileIndex_)
11 {
12 SetKeywordMap(MdbKeywords.GetKeywordMap());
13 MdbClassMap.Init();
14 }
15 public MdbLexer(const uchar* start_, const uchar* end_, const string& fileName_, int fileIndex_) :
16 base(start_, end_, fileName_, fileIndex_)
17 {
18 SetKeywordMap(MdbKeywords.GetKeywordMap());
19 MdbClassMap.Init();
20 }
21 public override int NextState(int state, uchar c)
22 {
23 int i = MdbClassMap.GetClass(c);
24 switch (state)
25 {
26 case 0:
27 {
28 switch (i)
29 {
30 case 0: case 7: case 8: case 9: case 10: case 12: case 13:
31 {
32 return 1;
33 }
34 case 2: case 3: case 4: case 5:
35 {
36 return 2;
37 }
38 case 6:
39 {
40 return 3;
41 }
42 case 11:
43 {
44 return 4;
45 }
46 case 14:
47 {
48 return 5;
49 }
50 case 15:
51 {
52 return 6;
53 }
54 case 16:
55 {
56 return 7;
57 }
58 case 17:
59 {
60 return 8;
61 }
62 case 18:
63 {
64 return 9;
65 }
66 case 19:
67 {
68 return 10;
69 }
70 case 20:
71 {
72 return 11;
73 }
74 case 21:
75 {
76 return 12;
77 }
78 case 22:
79 {
80 return 13;
81 }
82 case 23:
83 {
84 return 14;
85 }
86 case 24:
87 {
88 return 15;
89 }
90 case 25:
91 {
92 return 16;
93 }
94 case 26:
95 {
96 return 17;
97 }
98 case 27:
99 {
100 return 18;
101 }
102 case 28:
103 {
104 return 19;
105 }
106 default:
107 {
108 return -1;
109 }
110 }
111 return -1;
112 }
113 case 19:
114 {
115 System.Lex.Lexeme prevMatch = token.match;
116 token.match = lexeme;
117 int tokenId = GetTokenId(19);
118 if (tokenId == CONTINUE_TOKEN)
119 {
120 token.id = CONTINUE_TOKEN;
121 return -1;
122 }
123 else
124 {
125 if (tokenId != INVALID_TOKEN)
126 {
127 token.id = tokenId;
128 }
129 else
130 {
131 token.match = prevMatch;
132 }
133 }
134 return -1;
135 }
136 case 18:
137 {
138 System.Lex.Lexeme prevMatch = token.match;
139 token.match = lexeme;
140 int tokenId = GetTokenId(18);
141 if (tokenId == CONTINUE_TOKEN)
142 {
143 token.id = CONTINUE_TOKEN;
144 return -1;
145 }
146 else
147 {
148 if (tokenId != INVALID_TOKEN)
149 {
150 token.id = tokenId;
151 }
152 else
153 {
154 token.match = prevMatch;
155 }
156 }
157 return -1;
158 }
159 case 17:
160 {
161 System.Lex.Lexeme prevMatch = token.match;
162 token.match = lexeme;
163 int tokenId = GetTokenId(17);
164 if (tokenId == CONTINUE_TOKEN)
165 {
166 token.id = CONTINUE_TOKEN;
167 return -1;
168 }
169 else
170 {
171 if (tokenId != INVALID_TOKEN)
172 {
173 token.id = tokenId;
174 }
175 else
176 {
177 token.match = prevMatch;
178 }
179 }
180 return -1;
181 }
182 case 16:
183 {
184 System.Lex.Lexeme prevMatch = token.match;
185 token.match = lexeme;
186 int tokenId = GetTokenId(16);
187 if (tokenId == CONTINUE_TOKEN)
188 {
189 token.id = CONTINUE_TOKEN;
190 return -1;
191 }
192 else
193 {
194 if (tokenId != INVALID_TOKEN)
195 {
196 token.id = tokenId;
197 }
198 else
199 {
200 token.match = prevMatch;
201 }
202 }
203 return -1;
204 }
205 case 15:
206 {
207 System.Lex.Lexeme prevMatch = token.match;
208 token.match = lexeme;
209 int tokenId = GetTokenId(15);
210 if (tokenId == CONTINUE_TOKEN)
211 {
212 token.id = CONTINUE_TOKEN;
213 return -1;
214 }
215 else
216 {
217 if (tokenId != INVALID_TOKEN)
218 {
219 token.id = tokenId;
220 }
221 else
222 {
223 token.match = prevMatch;
224 }
225 }
226 return -1;
227 }
228 case 14:
229 {
230 switch (i)
231 {
232 case 23:
233 {
234 return 20;
235 }
236 default:
237 {
238 return -1;
239 }
240 }
241 return -1;
242 }
243 case 20:
244 {
245 System.Lex.Lexeme prevMatch = token.match;
246 token.match = lexeme;
247 int tokenId = GetTokenId(14);
248 if (tokenId == CONTINUE_TOKEN)
249 {
250 token.id = CONTINUE_TOKEN;
251 return -1;
252 }
253 else
254 {
255 if (tokenId != INVALID_TOKEN)
256 {
257 token.id = tokenId;
258 }
259 else
260 {
261 token.match = prevMatch;
262 }
263 }
264 return -1;
265 }
266 case 13:
267 {
268 switch (i)
269 {
270 case 22:
271 {
272 return 21;
273 }
274 default:
275 {
276 return -1;
277 }
278 }
279 return -1;
280 }
281 case 21:
282 {
283 System.Lex.Lexeme prevMatch = token.match;
284 token.match = lexeme;
285 int tokenId = GetTokenId(13);
286 if (tokenId == CONTINUE_TOKEN)
287 {
288 token.id = CONTINUE_TOKEN;
289 return -1;
290 }
291 else
292 {
293 if (tokenId != INVALID_TOKEN)
294 {
295 token.id = tokenId;
296 }
297 else
298 {
299 token.match = prevMatch;
300 }
301 }
302 return -1;
303 }
304 case 12:
305 {
306 System.Lex.Lexeme prevMatch = token.match;
307 token.match = lexeme;
308 int tokenId = GetTokenId(12);
309 if (tokenId == CONTINUE_TOKEN)
310 {
311 token.id = CONTINUE_TOKEN;
312 return -1;
313 }
314 else
315 {
316 if (tokenId != INVALID_TOKEN)
317 {
318 token.id = tokenId;
319 }
320 else
321 {
322 token.match = prevMatch;
323 }
324 }
325 return -1;
326 }
327 case 11:
328 {
329 System.Lex.Lexeme prevMatch = token.match;
330 token.match = lexeme;
331 int tokenId = GetTokenId(11);
332 if (tokenId == CONTINUE_TOKEN)
333 {
334 token.id = CONTINUE_TOKEN;
335 return -1;
336 }
337 else
338 {
339 if (tokenId != INVALID_TOKEN)
340 {
341 token.id = tokenId;
342 }
343 else
344 {
345 token.match = prevMatch;
346 }
347 }
348 return -1;
349 }
350 case 10:
351 {
352 System.Lex.Lexeme prevMatch = token.match;
353 token.match = lexeme;
354 int tokenId = GetTokenId(10);
355 if (tokenId == CONTINUE_TOKEN)
356 {
357 token.id = CONTINUE_TOKEN;
358 return -1;
359 }
360 else
361 {
362 if (tokenId != INVALID_TOKEN)
363 {
364 token.id = tokenId;
365 }
366 else
367 {
368 token.match = prevMatch;
369 }
370 }
371 return -1;
372 }
373 case 9:
374 {
375 System.Lex.Lexeme prevMatch = token.match;
376 token.match = lexeme;
377 int tokenId = GetTokenId(9);
378 if (tokenId == CONTINUE_TOKEN)
379 {
380 token.id = CONTINUE_TOKEN;
381 return -1;
382 }
383 else
384 {
385 if (tokenId != INVALID_TOKEN)
386 {
387 token.id = tokenId;
388 }
389 else
390 {
391 token.match = prevMatch;
392 }
393 }
394 return -1;
395 }
396 case 8:
397 {
398 System.Lex.Lexeme prevMatch = token.match;
399 token.match = lexeme;
400 int tokenId = GetTokenId(8);
401 if (tokenId == CONTINUE_TOKEN)
402 {
403 token.id = CONTINUE_TOKEN;
404 return -1;
405 }
406 else
407 {
408 if (tokenId != INVALID_TOKEN)
409 {
410 token.id = tokenId;
411 }
412 else
413 {
414 token.match = prevMatch;
415 }
416 }
417 return -1;
418 }
419 case 7:
420 {
421 System.Lex.Lexeme prevMatch = token.match;
422 token.match = lexeme;
423 int tokenId = GetTokenId(7);
424 if (tokenId == CONTINUE_TOKEN)
425 {
426 token.id = CONTINUE_TOKEN;
427 return -1;
428 }
429 else
430 {
431 if (tokenId != INVALID_TOKEN)
432 {
433 token.id = tokenId;
434 }
435 else
436 {
437 token.match = prevMatch;
438 }
439 }
440 return -1;
441 }
442 case 6:
443 {
444 System.Lex.Lexeme prevMatch = token.match;
445 token.match = lexeme;
446 int tokenId = GetTokenId(6);
447 if (tokenId == CONTINUE_TOKEN)
448 {
449 token.id = CONTINUE_TOKEN;
450 return -1;
451 }
452 else
453 {
454 if (tokenId != INVALID_TOKEN)
455 {
456 token.id = tokenId;
457 }
458 else
459 {
460 token.match = prevMatch;
461 }
462 }
463 return -1;
464 }
465 case 5:
466 {
467 System.Lex.Lexeme prevMatch = token.match;
468 token.match = lexeme;
469 int tokenId = GetTokenId(4);
470 if (tokenId == CONTINUE_TOKEN)
471 {
472 token.id = CONTINUE_TOKEN;
473 return -1;
474 }
475 else
476 {
477 if (tokenId != INVALID_TOKEN)
478 {
479 token.id = tokenId;
480 }
481 else
482 {
483 token.match = prevMatch;
484 }
485 }
486 switch (i)
487 {
488 case 14:
489 {
490 return 5;
491 }
492 default:
493 {
494 return -1;
495 }
496 }
497 return -1;
498 }
499 case 4:
500 {
501 switch (i)
502 {
503 case 12: case 13: case 14:
504 {
505 return 22;
506 }
507 default:
508 {
509 return -1;
510 }
511 }
512 return -1;
513 }
514 case 22:
515 {
516 System.Lex.Lexeme prevMatch = token.match;
517 token.match = lexeme;
518 int tokenId = GetTokenId(3);
519 if (tokenId == CONTINUE_TOKEN)
520 {
521 token.id = CONTINUE_TOKEN;
522 return -1;
523 }
524 else
525 {
526 if (tokenId != INVALID_TOKEN)
527 {
528 token.id = tokenId;
529 }
530 else
531 {
532 token.match = prevMatch;
533 }
534 }
535 switch (i)
536 {
537 case 12: case 13: case 14:
538 {
539 return 22;
540 }
541 default:
542 {
543 return -1;
544 }
545 }
546 return -1;
547 }
548 case 3:
549 {
550 switch (i)
551 {
552 case 7: case 8: case 9: case 10: case 13:
553 {
554 return 23;
555 }
556 case 14:
557 {
558 return 24;
559 }
560 default:
561 {
562 return -1;
563 }
564 }
565 return -1;
566 }
567 case 24:
568 {
569 System.Lex.Lexeme prevMatch = token.match;
570 token.match = lexeme;
571 int tokenId = GetTokenId(2);
572 if (tokenId == CONTINUE_TOKEN)
573 {
574 token.id = CONTINUE_TOKEN;
575 return -1;
576 }
577 else
578 {
579 if (tokenId != INVALID_TOKEN)
580 {
581 token.id = tokenId;
582 }
583 else
584 {
585 token.match = prevMatch;
586 }
587 }
588 switch (i)
589 {
590 case 14:
591 {
592 return 24;
593 }
594 default:
595 {
596 return -1;
597 }
598 }
599 return -1;
600 }
601 case 23:
602 {
603 System.Lex.Lexeme prevMatch = token.match;
604 token.match = lexeme;
605 int tokenId = GetTokenId(1);
606 if (tokenId == CONTINUE_TOKEN)
607 {
608 token.id = CONTINUE_TOKEN;
609 return -1;
610 }
611 else
612 {
613 if (tokenId != INVALID_TOKEN)
614 {
615 token.id = tokenId;
616 }
617 else
618 {
619 token.match = prevMatch;
620 }
621 }
622 return -1;
623 }
624 case 2:
625 {
626 System.Lex.Lexeme prevMatch = token.match;
627 token.match = lexeme;
628 int tokenId = GetTokenId(0);
629 if (tokenId == CONTINUE_TOKEN)
630 {
631 token.id = CONTINUE_TOKEN;
632 return -1;
633 }
634 else
635 {
636 if (tokenId != INVALID_TOKEN)
637 {
638 token.id = tokenId;
639 }
640 else
641 {
642 token.match = prevMatch;
643 }
644 }
645 switch (i)
646 {
647 case 2: case 3: case 4: case 5:
648 {
649 return 2;
650 }
651 default:
652 {
653 return -1;
654 }
655 }
656 return -1;
657 }
658 case 1:
659 {
660 System.Lex.Lexeme prevMatch = token.match;
661 token.match = lexeme;
662 int tokenId = GetTokenId(5);
663 if (tokenId == CONTINUE_TOKEN)
664 {
665 token.id = CONTINUE_TOKEN;
666 return -1;
667 }
668 else
669 {
670 if (tokenId != INVALID_TOKEN)
671 {
672 token.id = tokenId;
673 }
674 else
675 {
676 token.match = prevMatch;
677 }
678 }
679 switch (i)
680 {
681 case 0: case 1: case 7: case 8: case 9: case 10: case 12: case 13: case 14:
682 {
683 return 25;
684 }
685 default:
686 {
687 return -1;
688 }
689 }
690 return -1;
691 }
692 case 25:
693 {
694 System.Lex.Lexeme prevMatch = token.match;
695 token.match = lexeme;
696 int tokenId = GetTokenId(5);
697 if (tokenId == CONTINUE_TOKEN)
698 {
699 token.id = CONTINUE_TOKEN;
700 return -1;
701 }
702 else
703 {
704 if (tokenId != INVALID_TOKEN)
705 {
706 token.id = tokenId;
707 }
708 else
709 {
710 token.match = prevMatch;
711 }
712 }
713 switch (i)
714 {
715 case 0: case 1: case 7: case 8: case 9: case 10: case 12: case 13: case 14:
716 {
717 return 25;
718 }
719 default:
720 {
721 return -1;
722 }
723 }
724 return -1;
725 }
726 }
727 return -1;
728 }
729 private int GetTokenId(int statementIndex)
730 {
731 switch (statementIndex)
732 {
733 case 0:
734 {
735 Retract();
736 break;
737 }
738 case 1:
739 {
740 Retract();
741 return SEG;
742 break;
743 }
744 case 2:
745 {
746 Retract();
747 return REG;
748 break;
749 }
750 case 3:
751 {
752 Retract();
753 return HEX;
754 break;
755 }
756 case 4:
757 {
758 Retract();
759 return DEC;
760 break;
761 }
762 case 5:
763 {
764 Retract();
765 int kw = GetKeywordToken(token.match);
766 if (kw == INVALID_TOKEN) return ID;
767 else return kw;
768 break;
769 }
770 case 6:
771 {
772 Retract();
773 return PLUS;
774 break;
775 }
776 case 7:
777 {
778 Retract();
779 return MINUS;
780 break;
781 }
782 case 8:
783 {
784 Retract();
785 return BAR;
786 break;
787 }
788 case 9:
789 {
790 Retract();
791 return CARET;
792 break;
793 }
794 case 10:
795 {
796 Retract();
797 return AST;
798 break;
799 }
800 case 11:
801 {
802 Retract();
803 return SLASH;
804 break;
805 }
806 case 12:
807 {
808 Retract();
809 return PERCENT;
810 break;
811 }
812 case 13:
813 {
814 Retract();
815 return SHIFT_LEFT;
816 break;
817 }
818 case 14:
819 {
820 Retract();
821 return SHIFT_RIGHT;
822 break;
823 }
824 case 15:
825 {
826 Retract();
827 return AMP;
828 break;
829 }
830 case 16:
831 {
832 Retract();
833 return TILDE;
834 break;
835 }
836 case 17:
837 {
838 Retract();
839 return DOT;
840 break;
841 }
842 case 18:
843 {
844 Retract();
845 return LPAREN;
846 break;
847 }
848 case 19:
849 {
850 Retract();
851 return RPAREN;
852 break;
853 }
854 }
855 return CONTINUE_TOKEN;
856 }
857 }