-
Notifications
You must be signed in to change notification settings - Fork 0
/
TokenAnalyzer.hpp
1354 lines (1291 loc) · 52.7 KB
/
TokenAnalyzer.hpp
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef _TOKENANALYZER_H
#define _TOKENANALYZER_H
#endif
#include <iostream>
#include <string>
#include "./constvar.hpp"
using namespace std;
#define NOT_BLANCK(c) ((c != '\t') || (c != '\f') || (c != '\v') || (c != '\0') || ( c!= ' '))
#define BLANCK(c) (!NOT_BLANCK(c))
#define NOT_NEWLINE(c) (c != '\n')
#define NEWLINE(c) (!NOT_NEWLINE(c))
#define IsDights(c) ((c >= '0') && (c <= '9'))
#define OneToNine(c) ((c >= '1') && (c <= '9'))
#define ZeroToSeven(c) ((c >= '0') && (c <= '7'))
#define FloatPost(c) (c == 'f' || c == 'F' || c == 'l' || c == 'L')
#define LETTER_(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_')
#define HexDights(c) (IsDights(c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
#define IsSpecial(c) ((c == '\'') || (c == '\"') || (c == '?') || (c == '\\') || (c == 'a') || \
(c == 'b') || (c == 'f') || (c == 'n') || (c == 'r') || (c == 't') || (c == 'v'))
#define AppendCharToString(c) {\
TokenString.push_back(CurrentChar);\
TokenLength++;\
}
#define NEXT(first,second) do{ \
AppendCharToString(CurrentChar)\
CurrentChar = ReadAChar();\
if(CurrentChar == first || CurrentChar == second){\
AppendCharToString(CurrentChar)\
}\
else\
SeekFileHandler(-1L);\
return SYN_NUMBER; \
}while(0);
#define NEXT_U(symbol) do{\
AppendCharToString(CurrentChar)\
CurrentChar = ReadAChar();\
if(CurrentChar == symbol)\
NEXT('u','U')\
else if(CurrentChar == 'u' || CurrentChar == 'U'){\
AppendCharToString(CurrentChar)\
return SYN_NUMBER;\
}\
else\
{\
SeekFileHandler(-1L);\
return SYN_NUMBER;\
}\
}while(0);
#define ReadACharUntilNotHex(CurrentChar) for(CurrentChar = ReadAChar();HexDights(CurrentChar);CurrentChar = ReadAChar()){ \
if(CurrentChar == 0){ \
exit(0);\
}\
AppendCharToString(CurrentChar)\
}
#define ReadACharUntilNotDight(CurrentChar) for(CurrentChar = ReadAChar();IsDights(CurrentChar);CurrentChar = ReadAChar()){\
if(CurrentChar == 0){\
exit(0);\
}\
AppendCharToString(CurrentChar)\
}
#define ReadACharUntilNotOtc(CurrentChar) for(CurrentChar = ReadAChar();ZeroToSeven(CurrentChar);CurrentChar = ReadAChar()){\
if(CurrentChar == 0){\
exit(0);\
}\
AppendCharToString(CurrentChar)\
}
static bool FileStart = true;
static bool HeadFile = false;
class TokenAnalyzer{
public:
TokenAnalyzer()=default;
void SetFileName(const std::string FileName);
TOKEN NextToken(void);
int IsADecimal(void);
int IsOtcimal(void);
int IsHeximal(void);
int IsDecFloat(void);
int IsHexFloat(void);
int IsStringOrChar(void);
inline void RenewLex(void);
int ContinueRead(void);
int NextRead(void);
void ChangeStringToNumber(TOKEN &token);
// Real Number Change
inline signed String2Signed(void);
inline short String2Short(void);
inline unsigned short String2UnSignedShort(void);
inline int String2Int(void);
inline signed int String2SignedInt(void);
inline unsigned int String2UnSignedInt(void);
inline long String2Long(void);
inline signed long String2SignedLong(void);
inline unsigned long String2UnSignedLong(void);
inline float String2Float(void);
inline double String2Double(void);
void SeekFileHandler(long offset);
char ReadAChar(void);
inline bool isEOF(void);
inline int tokenLength(void);
inline std::string tokenString(void);
inline bool &getPreProcessStatus(void);
inline bool &getGlobalStatus(void);
int Processor(void);
int FoundKeyWord(void);
void CloseFile(void);
~TokenAnalyzer();
private:
std::ifstream FileHandler;
int TokenLength;
char PreChar;
bool PreProcess_ = false;
bool Global_ = true;
std::string TokenString;
};
TokenAnalyzer::~TokenAnalyzer(){
//Nothing to do
}
void TokenAnalyzer::CloseFile(void){
FileHandler.close();
}
void TokenAnalyzer::SetFileName(const std::string FileName){
FileHandler.open(FileName,std::ios_base::in);
if(!FileHandler.is_open())
{
std::cout << "No Such File or Direcotry!" << std::endl;
exit(0);
}
}
inline bool &TokenAnalyzer::getGlobalStatus(void){
return Global_;
}
inline bool &TokenAnalyzer::getPreProcessStatus(void){
return PreProcess_;
}
inline bool TokenAnalyzer::isEOF(void){
return (FileHandler.eof()) ? 1:0;
}
inline int TokenAnalyzer::tokenLength(void){
return TokenLength;
}
inline std::string TokenAnalyzer::tokenString(void){
return TokenString;
}
int TokenAnalyzer::IsHeximal(void){
char CurrentChar;
ReadACharUntilNotHex(CurrentChar)
switch(CurrentChar){
case 'U':
case 'u':
CurrentChar = ReadAChar();
switch(CurrentChar){
case 'l':
NEXT('l','l');
case 'L':
NEXT('L','L');
}
SeekFileHandler(-1L);
return SYN_NUMBER;
case 'l':
NEXT_U('l');
case 'L':
NEXT_U('L');
default:
SeekFileHandler(-1L);
return SYN_NUMBER;
}
}
int TokenAnalyzer::NextRead(void){
char CurrentChar;
for(CurrentChar = ReadAChar();CurrentChar && CurrentChar != '\'' && CurrentChar != '\\' && CurrentChar != '\n' ;CurrentChar = ReadAChar()){
AppendCharToString(CurrentChar)
}
if(CurrentChar == '\''){
AppendCharToString(CurrentChar)
return SYN_STRING;
}
else if(CurrentChar == '\\'){
AppendCharToString(CurrentChar)
return ContinueRead();
}
else if(CurrentChar == '\n'){
while((CurrentChar = ReadAChar()) == '\n');
if(CurrentChar == '\\'){
AppendCharToString(CurrentChar)
return ContinueRead();
}
else if(CurrentChar == '\'' || CurrentChar == '\"'){
AppendCharToString(CurrentChar)
return SYN_NUMBER;
}
else if(FileHandler.eof()){
#if defined(TOKENANALYZER)
std::cout << "Meet File End!" << std::endl;
#endif
return ERROR;
}
else{
return NextRead();
}
}
return ERROR;
}
int TokenAnalyzer::ContinueRead(void){
char CurrentChar;
CurrentChar = ReadAChar();
if(IsSpecial(CurrentChar)){
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
if(CurrentChar == '\'' || CurrentChar == '\"'){
AppendCharToString(CurrentChar)
return SYN_STRING;
}
else{
AppendCharToString(CurrentChar)
return IsStringOrChar();
}
}
else if(ZeroToSeven(CurrentChar)){
AppendCharToString(CurrentChar)
ReadACharUntilNotOtc(CurrentChar)
SeekFileHandler(-1L);
return NextRead();
}
else{
AppendCharToString(CurrentChar)
switch (CurrentChar)
{
case 'x':
ReadACharUntilNotHex(CurrentChar)
SeekFileHandler(-1L);
return NextRead();
case 'U':
case 'u':
ReadACharUntilNotHex(CurrentChar)
SeekFileHandler(-1L);
return NextRead();
default:
std::cout << "Lex:Symbol Error!" << CurrentChar << std::endl;
exit(1);
}
}
}
int TokenAnalyzer::IsStringOrChar(void){
char CurrentChar;
CurrentChar = ReadAChar();
if(CurrentChar == '\\'){
AppendCharToString(CurrentChar)
return ContinueRead();
}
else if(CurrentChar != '\'' && CurrentChar != '\\' && CurrentChar != '\n' && CurrentChar != '\"'){
AppendCharToString(CurrentChar)
char TempChar = CurrentChar;
CurrentChar = ReadAChar();
if(CurrentChar != '\'' && CurrentChar != '\\' && CurrentChar != '\n' && CurrentChar != '\"'){
AppendCharToString(CurrentChar)
return IsStringOrChar();
}
else if(CurrentChar == '\'' || CurrentChar == '\"' ){
AppendCharToString(CurrentChar)
return SYN_STRING;
}
else{
/* std::cout << "Symbol Error!---" << CurrentChar << std::endl;
exit(1);*/
AppendCharToString(CurrentChar)
return ContinueRead();
}
}
else if(CurrentChar == '\"' || CurrentChar == '\''){
AppendCharToString(CurrentChar)
return SYN_STRING;
}
else{
std::cout << "Lex:Symbol Error!" << CurrentChar << std::endl;
exit(1);
}
}
int TokenAnalyzer::IsDecFloat(void){
char CurrentChar;
ReadACharUntilNotDight(CurrentChar)
switch (CurrentChar)
{
case '.':
AppendCharToString(CurrentChar)
ReadACharUntilNotDight(CurrentChar)
if(FloatPost(CurrentChar)){
AppendCharToString(CurrentChar)
goto postfloat;
}
else if(CurrentChar == 'e' || CurrentChar == 'E')
;
else{
SeekFileHandler(-1L);
return SYN_NUMBER;
}
case 'e':
case 'E':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
AppendCharToString(CurrentChar)
switch(CurrentChar){
case '+':
case '-':
ReadACharUntilNotDight(CurrentChar)
}
if(IsDights(CurrentChar))
ReadACharUntilNotDight(CurrentChar)
if(FloatPost(CurrentChar)){
AppendCharToString(CurrentChar)
return SYN_NUMBER;
}
else{
SeekFileHandler(-1L);
return SYN_NUMBER;
}
postfloat:
case 'f':
case 'F':
case 'L':
case 'l':
AppendCharToString(CurrentChar)
return SYN_NUMBER;
default:
SeekFileHandler(-1L);
return SYN_NUMBER;
}
}
int TokenAnalyzer::IsOtcimal(void){
char CurrentChar;
ReadACharUntilNotOtc(CurrentChar)
switch(CurrentChar){
case 'u':
case 'U':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case 'l':
NEXT('l','l');
case 'L':
NEXT('L','L');
default:
SeekFileHandler(-1L);
return SYN_NUMBER;
}
case 'l':
NEXT_U('l')
case 'L':
NEXT_U('L')
default:
SeekFileHandler(-1L);
return SYN_NUMBER;
}
}
int TokenAnalyzer::IsADecimal(void){
char CurrentChar;
ReadACharUntilNotDight(CurrentChar)
switch(CurrentChar){
case '.':
AppendCharToString(CurrentChar)
return IsDecFloat();
case 'u':
case 'U':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case 'l':
NEXT('l','l');
case 'L':
NEXT('L','L');
default:
SeekFileHandler(-1L);
return SYN_NUMBER;
}
case 'l':
NEXT_U('l')
case 'L':
NEXT_U('L')
default:
SeekFileHandler(-1L);
return SYN_NUMBER;
}
}
int TokenAnalyzer::IsHexFloat(void){
char CurrentChar;
ReadACharUntilNotHex(CurrentChar)
switch(CurrentChar){
case '.':
AppendCharToString(CurrentChar)
ReadACharUntilNotHex(CurrentChar)
if(CurrentChar == 'p' || CurrentChar == 'P')
; // Nothing to do
else{
std::cout <<"Lex:Symbol Error!" << CurrentChar << std::endl;
exit(1);
}
case 'p':
case 'P':
AppendCharToString(CurrentChar)
ReadACharUntilNotDight(CurrentChar)
if(CurrentChar == '+' || CurrentChar == '-'){
ReadACharUntilNotDight(CurrentChar)
if(FloatPost(CurrentChar)){
AppendCharToString(CurrentChar)
return SYN_KEYWORD;
}
else{
SeekFileHandler(-1L);
return SYN_KEYWORD;
}
}
if(FloatPost(CurrentChar)){
AppendCharToString(CurrentChar)
return SYN_KEYWORD;
}
else {
SeekFileHandler(-1L);
return SYN_KEYWORD;
}
default:
std::cout << "Lex:Symbol Error!" << CurrentChar << std::endl;
exit(1);
}
}
void TokenAnalyzer::SeekFileHandler(long offset){
if(FileHandler){
FileHandler.seekg(offset,std::ios::cur);
if(PreProcess_){
PreProcesstext.pop_back();
}
if(Global_){
text.pop_back();
}
}
else{
#if defined(TOKENANALYZER)
std::cout << "Meet File End!" << std::endl;
#endif
return;
}
return ;
}
char TokenAnalyzer::ReadAChar(void){
char TempChar;
TempChar = FileHandler.get();
if(PreProcess_){
PreProcesstext.push_back(TempChar);
}
if(Global_){
text.push_back(TempChar);
}
return TempChar;
}
int TokenAnalyzer::Processor(void){
char CurrentChar;
if(FileHandler.eof()){
return ERROR;
}
for(CurrentChar = ReadAChar();CurrentChar ;CurrentChar = ReadAChar()){
// Is Blanck ?
switch(CurrentChar){
case '\t':
case '\f':
case '\v':
case ' ':
case '\n':
do{
if(CurrentChar == '\n'){
#if defined(syntaxanalyzer)
std::cout << "No."<< LineNumber << std::endl;
#endif
if(RunTimeTrans)
RunTimeLine++;
LineNumber++;
}
CurrentChar = ReadAChar();
}while(!NOT_BLANCK(CurrentChar));
if(!FileHandler.eof()){
SeekFileHandler(-1L);
continue;
}
else{
#if defined(TOKENANALYZER)
std::cout << "Meet File End!" << std::endl;
#endif
return(0);
}
default:
break;
}
// Is Calculatoer ?
switch(CurrentChar){
case '+':{
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_AE;
case '+':
AppendCharToString(CurrentChar)
return SYN_INC;
default:
if(IsDights(CurrentChar)){
AppendCharToString(CurrentChar)
char TempChar ;
int Count = 0;
switch(CurrentChar){
case '0':
CurrentChar = ReadAChar();
if(CurrentChar == 'x' || CurrentChar == 'X'){
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
Count++;
do{
if(!HexDights(CurrentChar))
break;
else{
CurrentChar = ReadAChar();
Count++;
}
}while(1);
Count = 0 - Count;
SeekFileHandler(Count);
if(CurrentChar == '.' || CurrentChar == 'P' || CurrentChar == 'p'){
return IsHexFloat();
}
else if(CurrentChar == 'u' || CurrentChar == 'U' || CurrentChar == 'l' ||
CurrentChar == 'L' ){
return IsHeximal();
}
else
{
return IsHeximal();
}
}
else if(ZeroToSeven(CurrentChar)){
AppendCharToString(CurrentChar)
switch(CurrentChar){
case '.':
AppendCharToString(CurrentChar)
return IsDecFloat();
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
do{
if(!IsDights(CurrentChar))
break;
else
{
CurrentChar = ReadAChar();
Count++;
}
}while(1);
Count = 0 - Count;
SeekFileHandler(Count);
if(CurrentChar == '.'){
return IsDecFloat();
}
else if(CurrentChar == 'u' || CurrentChar == 'U' ||
CurrentChar == 'l' || CurrentChar == 'L'){
return IsOtcimal();
}
else
{
break;
}
case '8':
case '9':
case 'u':
case 'U':
case 'l':
case 'L':
return IsOtcimal();
}
}
if(IsDights(CurrentChar)){
AppendCharToString(CurrentChar)
return IsDecFloat();
}
if(CurrentChar == '.'){
AppendCharToString(CurrentChar)
return IsDecFloat();
}
SeekFileHandler(-1);
return SYN_NUMBER;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return IsADecimal();
default:break;
}
}
else{
SeekFileHandler(-1L);
return SYN_ADD;
}
}
}
case '-':{
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_SE;
case '-':
AppendCharToString(CurrentChar)
return SYN_DEC;
case '>':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '*':
AppendCharToString(CurrentChar)
return SYN_POINTERMUL;
default:
SeekFileHandler(-1L);
return SYN_POINTER;
}
default:
if(IsDights(CurrentChar)){
AppendCharToString(CurrentChar)
char TempChar ;
int Count = 0;
switch(CurrentChar){
case '0':
CurrentChar = ReadAChar();
if(CurrentChar == 'x' || CurrentChar == 'X'){
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
Count++;
do{
if(!HexDights(CurrentChar))
break;
else{
CurrentChar = ReadAChar();
Count++;
}
}while(1);
Count = 0 - Count;
SeekFileHandler(Count);
if(CurrentChar == '.' || CurrentChar == 'P' || CurrentChar == 'p'){
return IsHexFloat();
}
else if(CurrentChar == 'u' || CurrentChar == 'U' || CurrentChar == 'l' ||
CurrentChar == 'L' ){
return IsHeximal();
}
else
{
return IsHeximal();
}
}
else if(ZeroToSeven(CurrentChar)){
AppendCharToString(CurrentChar)
switch(CurrentChar){
case '.':
AppendCharToString(CurrentChar)
return IsDecFloat();
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
do{
if(!IsDights(CurrentChar))
break;
else
{
CurrentChar = ReadAChar();
Count++;
}
}while(1);
Count = 0 - Count;
SeekFileHandler(Count);
if(CurrentChar == '.'){
return IsDecFloat();
}
else if(CurrentChar == 'u' || CurrentChar == 'U' ||
CurrentChar == 'l' || CurrentChar == 'L'){
return IsOtcimal();
}
else
{
break;
}
case '8':
case '9':
case 'u':
case 'U':
case 'l':
case 'L':
return IsOtcimal();
}
}
if(IsDights(CurrentChar)){
AppendCharToString(CurrentChar)
return IsDecFloat();
}
if(CurrentChar == '.'){
AppendCharToString(CurrentChar)
return IsDecFloat();
}
SeekFileHandler(-1);
return SYN_NUMBER;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return IsADecimal();
default:break;
}
}
else{
SeekFileHandler(-1L);
return SYN_SUB;
}
}
}
case '*':{
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_ME;
default:
SeekFileHandler(-1L);
return SYN_MUL;
}
}
case '/':{
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_DE;
case '/':
do{
CurrentChar = ReadAChar();
if(FileHandler.eof())
break;
}while(NOT_NEWLINE(CurrentChar));
if(!FileHandler.eof()){
TokenString.pop_back();
TokenLength--;
//SeekFileHandler(-1L);
continue;
}
else{
#if defined(TOKENANALYZER)
std::cout << "Meet File End!" << std::endl;
#endif
return(0);
}
case '*':
char tempchar;
while (!isEOF() && ((tempchar = ReadAChar())!='/' || CurrentChar != '*')){
if(CurrentChar == '\n'){
if(RunTimeTrans)
RunTimeLine++;
LineNumber++;
}
CurrentChar = tempchar;
}
TokenString.pop_back();
TokenLength--;
continue;
default:
SeekFileHandler(-1L);
return SYN_DIV;
}
}
case '%':{
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_MODEQ;
default:
SeekFileHandler(-1L);
return SYN_MOD;
}
}
}
// Is Bit Operatoer
switch(CurrentChar){
case '&':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '&':
AppendCharToString(CurrentChar)
return SYN_AND;
case '=':
AppendCharToString(CurrentChar)
return SYN_BIT_ANDEQ;
default:
SeekFileHandler(-1L);
return SYN_BIT_AND;
}
case '|':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '|':
AppendCharToString(CurrentChar)
return SYN_OR;
case '=':
AppendCharToString(CurrentChar)
return SYN_BIT_OREQ;
default:
SeekFileHandler(-1L);
return SYN_BIT_OR;
}
case '^':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_BIT_XOREQ;
default:
SeekFileHandler(-1L);
return SYN_BIT_XOR;
}
case '~':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_BIT_NOTEQ;
default:
SeekFileHandler(-1L);
return SYN_BIT_NOT;
}
case '!':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_NOTEQ;
default:
SeekFileHandler(-1L);
return SYN_NOT;
}
}
// Is Relation Operator
switch(CurrentChar){
case '>':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '>':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
if(CurrentChar == '='){
AppendCharToString(CurrentChar)
return SYN_BIT_SHREQ;
}
SeekFileHandler(-1L);
return SYN_BIT_SHR;
case '=':
AppendCharToString(CurrentChar)
return SYN_GE;
default:
SeekFileHandler(-1L);
HeadFile = false;
return SYN_GT;
}
case '<':
TokenString.push_back(CurrentChar);
TokenLength++;
CurrentChar = ReadAChar();
switch(CurrentChar){
case '<':
TokenString.push_back(CurrentChar);
TokenLength++;
CurrentChar = ReadAChar();
if(CurrentChar == '='){
TokenString.push_back(CurrentChar);
TokenLength++;
return SYN_BIT_SHLEQ;
}
SeekFileHandler(-1L);
return SYN_BIT_SHL;
case '=':
TokenString.push_back(CurrentChar);
TokenLength++;
return SYN_LE;
default:
SeekFileHandler(-1L);
HeadFile = true;
return SYN_LT;
}
case '=':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
switch(CurrentChar){
case '=':
AppendCharToString(CurrentChar)
return SYN_EQ;
default:
SeekFileHandler(-1L);
return SYN_SET;
}
}
// Is Misc
switch(CurrentChar){
case '#':
AppendCharToString(CurrentChar)
CurrentChar = ReadAChar();
if(CurrentChar == '#')
return SYN_POST;
else if(LETTER_(CurrentChar)){
AppendCharToString(CurrentChar)
do{
CurrentChar = ReadAChar();
if(LETTER_(CurrentChar) || IsDights(CurrentChar)){
AppendCharToString(CurrentChar)
}
else{
SeekFileHandler(-1L);
return SYN_KEYWORD;
}
}while(1);
}
else
{
SeekFileHandler(-1L);
return SYN_SHARP;
}
case '\\':
if(PreProcess_){
continue;
}
else
{