-
Notifications
You must be signed in to change notification settings - Fork 1
/
compiler.cpp
executable file
·2001 lines (1420 loc) · 36.6 KB
/
compiler.cpp
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
//remove single and multiline comments as well as blank spaces(starting and trailing) from a source file
//input: source file path e.g E:\B1-75\LAB2\test.cpp
//output: E:\B1-75\compiled.cpp
//limitation-1: cannot process strings like cout<<"a" <spaces> ; or if(a==5) <spaces> { }
//limitation-2: escape characters are not supported within string literals e.g. " \" "
//limitation-3: limited identifer length to a maximum of 32
//limitation-4: declaration list should be terminated by ;\n
//limitation-5: assigment via condition operator should involve all identifiers of the same type
//condition to be avoided: c o u ttt <<a; //will make separate entries for c,o,u ttt in symbol table
//above condition may over-write some existing identifiers in symbol table
//note:maximum one space may occur after the delimitor and before \n
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define hash_size 256 //size of hash table
#define keywords_length 32 //size of keyword array
#define reserved_length 4 //size of reserved length array
#define types_length 2 //size of types array
void statement();
void statement_list();
int listundec();
void skip();
void asm_declarations();
void asm_statement();
void asm_statement_list();
FILE *f,*f1,*f2,*f3,*f4,*f5,*f6,*f7;
char name[200]="E:\\B1-75\\LAB2\\test.cpp"; //the source file
char output[200]="E:\\B1-75\\compiled.cpp";
char tokens[200]="E:\\B1-75\\tokens.txt"; //repetition in file
char key[200]="E:\\B1-75\\keywords.txt";//non-repeating in file
char ops[200]="E:\\B1-75\\operators.txt";//repetition in file
char numbers[200]="E:\\B1-75\\numbers.txt"; //repetition in file
char special[200]="E:\\B1-75\\special.txt"; //repetition in file
char identify[200]="E:\\B1-75\\identify.txt"; //repetition in file
//char identifier[200]="E:\\B1-75\\identifiers.txt";
//f is the original code
//f1 is the updated file
//f2 is the tokens file (keywords + identifiers)
//f3 is the keywords file
//f4 is the operators file
//f5 is the numbers file
//f6 is the special characters file
//f7 is the identifiers file
char keywords[][8]={"auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while"};
//length of keyword array=keywords_length=32
char reservedwords[][32]={"main","cout","cin","exit"};
//length of reserved array=reserved_length=4
char types[][32]={"char","int"};
//length of types array=types_length=2
int printkey[keywords_length]; //printed[i]=1 if ith keyword has been printed
//char defkey[][10]={"auto ","break ","break;","case ","char ","const ","continue ","continue;","default:","do{","double ","else ","else{","enum{","extern ","float ","for(","goto ","if(","int ","long ","register ","return ","return;","short ","signed ","sizeof(","static ","struct ","switch(","typedef ","union ","unsigned ","void ","volatile ","while("};
char c,tok[32];
struct node{
char name[32]; //lexeme name
char type; //token type (e.g. keywords, identifiers, numbers, special symbols
char datatype; // char(c), int(i), char array(d), int array(j)
int size; //size of data type (char=1, int=2, char array,int array=size in [])
int verified; //check if an identifier has been declared on not
struct node* next;
};
node* asm_term(char from[]);
void asm_simple_expn(char from[]);
node* asm_tprime(char from[]);
node* t=NULL;
int linerr=1,openbrac=0,closebrac=0; //parser counters for scope mismatches
int dec_label_count=0, loop_label_count=0;
// counters for assembly labels for decision and looping statements
node* getnode(){
node* p=(node*)malloc(sizeof(node));
return p;
}
node* hash[hash_size]; //hash table used as a data-structure for symbol table
void overwrite(){ //copies changes back to test.cpp
f=fopen(name,"w");
f1=fopen(output,"r");
char c=getc(f1);
while(c!=EOF){
putc(c,f);
c=getc(f1);
}//while close
fclose(f);
fclose(f1);
}//overwrite() close
void inittable(){
for(int i=0;i<hash_size;i++){
hash[i]=NULL; //initialize hash pointers to NULL
}
}
int calchash(char buf[]){
int val=0,pos=0;
while(buf[pos]!='\0'){
val+=(int)buf[pos];
pos++;
}
return (val%hash_size);
}//calchash close
void addtotable(char symbol[], char t, char dt, int s, int pos){ //pos=location in hash table
//type,datatype,size
node *p=getnode();
strcpy(p->name,symbol);
p->type=t;
p->datatype=dt;
p->size=s;
p->next=NULL;
p->verified=0;
if(hash[pos]==NULL) hash[pos]=p;
else if(hash[pos]!=NULL){
node* prev=hash[pos];
while(prev->next!=NULL) prev=prev->next;
prev->next=p;
}
}//addtotable close
int searchtable(char key[]){
int pos=calchash(key);
node* t=hash[pos];
while(t!=NULL){
if(strcmp(key,t->name)==0) return 1;
t=t->next;
}//while close
return 0;
}
node* findintable(char key[]){
int pos=calchash(key);
node* t=hash[pos];
while(t!=NULL){
if(strcmp(key,t->name)==0) return t;
t=t->next;
}//while close
return NULL;
}
void createtable(FILE* curfile, char type, char datatype, int size){
//f7=fopen(identify,"r");
char c,buf[32];
int bufpos=0;
c=getc(curfile);
//in every file, for every string\n, search in hash table, if not found, find position and insert into table
while(c!=EOF){
bufpos=0;
while(c!='\n'){
buf[bufpos++]=c;
c=getc(curfile);
}
buf[bufpos++]='\0';
//puts(buf);
int found=searchtable(buf);
if(found==0){
if(datatype=='c') addtotable(buf,type,datatype,strlen(buf),calchash(buf));
else if(datatype=='n') addtotable(buf,type,datatype,strlen(buf)*2,calchash(buf));
else addtotable(buf,type,datatype,size,calchash(buf));
}
c=getc(curfile);
}//while close
fclose(curfile);
}//createtable() close
void populatetable(){
f7=fopen(identify,"r"); //type, datatype, size
createtable(f7,'i','i',9);
f6=fopen(special,"r");
createtable(f6,'s','c',1);
f5=fopen(numbers,"r");
createtable(f5,'n','i',2); //numbers by default taken as integers
f4=fopen(ops,"r");
createtable(f4,'o','c',1);
f3=fopen(key,"r");
createtable(f3,'k','c',9);
}//populatetable cose
void edittable(char buf[], char t, char dt, int s){
//int loc=calchash(buf);
node* n=hash[calchash(buf)];
while(n!=NULL){
if(strcmp(buf,n->name)==0){
n->type=t;
n->datatype=dt;
n->size=s;
break;
}
n=n->next;
}//while close
}//edittable() close
void displaytable(){
int print=0;
for(int i=0;i<hash_size;i++){
if(hash[i]!=NULL){
cout<<"At "<<i<<" ";
node* t=hash[i];
while(t!=NULL){
print++;
int pos=0;
while(t->name[pos]!='\0') cout<<t->name[pos++];
cout<<" "<<t->type<<" "<<t->datatype<<" "<<t->size<<" "<<" ";
t=t->next;
if(print%4==0) cout<<endl;
}//while close
}//if close
}//for close
}//displaytable() close
void displaynode(node* t){
int p=0;
while(t->name[p]!='\0') cout<<t->name[p++];
cout<<t->type<<t->datatype<<t->size<<" ";
}
int reserved(char buf[]){
for(int i=0;i<reserved_length;i++){ //4=length of reservedwords array
if(strcmp(buf,reservedwords[i])==0) return 1;
}
return 0;
}
void listidentifiers(){
f2=fopen(tokens,"r");
f7=fopen(identify,"w");
char c,buf[32],bufpos=0;
int flag=1; //if flag=1 assumes that current token is an identifier
c=getc(f2);
//for each token, check if it matches a keyword. If not, then write to f7
while(c!=EOF){
bufpos=0;
flag=1;
while(c!='\n'){
buf[bufpos++]=c;
c=getc(f2);}
buf[bufpos++]='\0';
//puts(buf);
for(int i=0;i<keywords_length;i++){ //32=length of keywords array
if(strcmp(buf,keywords[i])==0 || reserved(buf)==1){
flag=0; //0 = not an identifier
break;}
}
if(flag==1){
for(int j=0;j<strlen(buf);j++){
putc(buf[j],f7);}
putc('\n',f7);
}
c=getc(f2);
}//while c!=EOF close
fclose(f2);
fclose(f7);
}//listidentifiers() close
void listoperators(){
char c,d,e;
int flag=0;
f1=fopen(output,"r");
f4=fopen(ops,"w");
f6=fopen(special,"w");
c=getc(f1);
while(c!=EOF){
flag=0;
if(c=='"'){ //bypass string literals
c=getc(f1);
while(c!='"'){
c=getc(f1);
}
c=getc(f1);
}//if c=='"' close
else if(c=='~' || c==','|| c=='(' || c==')' || c=='!' || c==';'){
putc(c,f4);
flag=1;}
else if(c=='+'){
putc(c,f4);
d=getc(f1);
if(d=='='|| d=='+') putc(d,f4);
flag=1;
}//c=='+' close
else if(c=='-'){
putc(c,f4);
d=getc(f1);
if(d=='=' || d=='-') putc(d,f4);
flag=1;
}//c=='-' close
else if(c=='=' || c=='*' || c=='/' || c=='%' || c=='^'){
putc(c,f4);
d=getc(f1);
if(d=='=') putc(d,f4);
flag=1;
}
else if(c=='&'){
putc(c,f4);
d=getc(f1);
if(d=='&'|| d=='=') putc(d,f4);
flag=1;
}//c=='&' close
else if(c=='|'){
putc(c,f4);
d=getc(f1);
if(d=='|' || d=='=') putc(d,f4);
flag=1;
}//c=='|' close
else if(c=='<'){
putc(c,f4);
d=getc(f1);
if(d=='=') putc(d,f4);
else if(d=='<'){
putc(d,f4);
e=getc(f1);
if(e=='=') putc(e,f4);
else ungetc(e,f1);
}
flag=1;
}//c=='<' close
else if(c=='>'){
putc(c,f4);
d=getc(f1);
if(d=='=') putc(d,f4);
else if(d=='>'){
putc(d,f4);
e=getc(f1);
if(e=='=') putc(e,f4);
else ungetc(e,f1);
}
flag=1;
}//c=='>' close
/*
else if(c=='?'){ //check for conditional operator
d=getc(f1);
while(d!=':' & d!='\n') d=getc(f1); //characters may be present in between!
if(d==':'){ putc('?',f4); putc(d,f4); }
flag=1;
}
*/
else if(!isdigit(c) & !isalpha(c) & c!=';' & c!=' ' & c!='\n' & c!='\t'){
putc(c,f6);
putc('\n',f6);
}
if(flag==1) putc('\n',f4);
c=getc(f1);
}//while close
fclose(f1);
fclose(f4);
fclose(f6);
}//listoperators() close
void listkeywords(){
f2=fopen(tokens,"r");
f3=fopen(key,"w");
char buf[10];
int pos,i,k=0;
char c=getc(f2);
cout<<"Keywords:\n";
while(c!=EOF){
pos=0;
//f2=getline(buf,f2,'\n');
while(c!='\n'){
buf[pos++]=c;
c=getc(f2);}
buf[pos]='\0';
//puts(buf);
for(i=0;i<keywords_length;i++){ //32=length of keywords array
k=0;
if(strcmp(buf,keywords[i])==0){
if(printkey[i]==0){
//int position=calchash(buf);
//addtotable(buf,'k',9,position);
while(buf[k]!='\0'){
cout<<(char)toupper(buf[k]);
putc(buf[k],f3);
k++;}
cout<<endl;
putc('\n',f3);
}
printkey[i]=1;
}
}//for close
c=getc(f2);
}//while close
fclose(f2);
fclose(f3);
}//listkeywords() close
void listtokens(){
char c;
int i,j;
f=fopen(name,"r");
f2=fopen(tokens,"w");
f5=fopen(numbers,"w");
c=getc(f);
while(c!=EOF){
if(c=='"'){ //bypass string literals
c=getc(f);
while(c!='"'){
c=getc(f);
}
c=getc(f);
}//if c=='"' close
else if(isalpha(c)){
putc(c,f2);
c=getc(f);
while(isdigit(c) || isalpha(c)){
putc(c,f2);
c=getc(f);
}//while close
putc('\n',f2);
}//else if (isalpha() close)
else if(isdigit(c)){
putc(c,f5);
c=getc(f);
while(isdigit(c)){
putc(c,f5);
c=getc(f);
}
putc('\n',f5);
}//else if isdigit(c) close
else { c=getc(f); }
}//while c!=EOF close
fclose(f);
fclose(f2);
fclose(f5);
}//listtokens() close
void removelines(){
char c,d,e;
int flag=0;
f=fopen(name,"r");
f1=fopen(output,"w");
c=getc(f);
while(c!=EOF){
flag=0;
if(c=='"'){
putc(c,f1);
d=getc(f);
while(d!='"'){
putc(d,f1);
d=getc(f);}
c=d;
}//c==' " ' close
else if(c=='\n'){
while(c=='\n') c=getc(f);
flag=1;
}
if(flag==1){
putc('\n',f1);
if(c!=EOF) putc(c,f1);
}
else putc(c,f1);
c=getc(f);
}
fclose(f);
fclose(f1);
}//removelines() close
void removespaces(){
//new function
char c,d;
int pos=0,len=0;
f=fopen(name,"r");
f1=fopen(output,"w");
char buf[5000]; //maximum size of 1 line=5000 characters
c=getc(f);
while(c!=EOF){
buf[pos++]=c;
if(c=='\n'){
//buf[pos++]='\0';
//remove leading extra spaces
for(int i=0;i<pos;i++){
if(buf[0]!=' ' & buf[0]!='\t') break;
if(buf[i]==' '|| buf[i]=='\t') continue;
len=i;
for(int j=0;j<pos;j++) buf[j]=buf[len+j]; //shift characters to left
pos=pos-len;
}//for close
//print truncated line
for(i=0;i<pos;i++){
if(pos==1) break; //do not print single \n
putc(buf[i],f1);
}
for(i=0;i<5000;i++) buf[i]=NULL;
pos=0;
len=0;
}//if c=='\n' close
c=getc(f);
}//while(c!=EOF) close
fclose(f1);
fclose(f);
//remove other extra spaces
overwrite();
//remove other and leading spaces
int extra=0;
f=fopen(name,"r");
f1=fopen(output,"w");
c=getc(f);
while(c!=EOF){
extra=0;
if(c=='"'){
while(c!='"'){
putc(c,f1);
c=getc(f);}
}
while(c==' ' || c=='\t'){ //all consecutive spaces and tabs are replaced by a single space
c=getc(f);
extra=1;
}
if(extra==1) putc(' ',f1);
putc(c,f1);
c=getc(f);
}
fclose(f);
fclose(f1);
//new function
}//removespaces() close
void removecomments(FILE* f){
char c,d,e,g;
int comm=0,multi=0,flag=0;
f1=fopen(output,"w");
c=getc(f);
while(c!=EOF){
flag=0;
if(c=='"'){ //comments within quotes are allowed!
putc(c,f1);
c=getc(f);
while(c!='"'){
putc(c,f1);
c=getc(f);}
flag=0;
}//if c=='"' close
if(c=='/'){
d=getc(f);
if(d=='/'){ //single line comment detected
flag=1;
e=getc(f);
comm++;
while(e!='\n'){
e=getc(f);
}
}//d=='/' close
else if(d=='*'){ //multiline comment detected
flag=1;
e=getc(f);
multi++; /* */
//cd eg
g=getc(f);
while(1){
if(e=='*' & g=='/') break;
else{
e=g;
g=getc(f);
}
}
}//if d=='*' close
else{
flag=1;
putc(c,f1);
putc(d,f1);
}
}//if c=='/' close
if(flag==0)
putc(c,f1);
c=getc(f);
}//while close
fclose(f);
fclose(f1);
//cout<<"Single line comments:"<<comm<<"\n";
//cout<<"Multiple line comments:"<<multi<<"\n";
}//removecomments() close
void identifydatatypes(){
f1=fopen(output,"r"); //open compiled.cpp
int idsize,pos=0,flag;
char buf[32],dt;
char c=getc(f1);
while(c!=EOF){
idsize=9;
pos=0;
flag=0;
if(c=='"'){ //bypass string literals
c=getc(f);
while(c!='"'){
c=getc(f);
}
//c=getc(f);
}//if c=='"' close
else if(isalpha(c)){
buf[pos++]=c;
c=getc(f1);
while(isalpha(c)){
buf[pos++]=c;
c=getc(f1);}
buf[pos]='\0';
//0 1 2 3
//1 2 4 6
for(int i=0;i<types_length;i++){
if(strcmp(buf,types[i])==0){
if(i==0){
idsize=1; //size of char=1
dt='c';}
else{
idsize=i*2; //size of int=2
dt='i';
}
flag=1; //flag==1 denotes that a valid datatype is found
break;
}
}//for close
//int p=0;
//while(buf[p]!='\0') cout<<buf[p++];
//cout<<"\t";
}//if(isalpha(c)) close
if(flag==1){
char id[32];
int idpos=0,num;//num=size of arrays in declaration list
//c is now one character ahead of datatype
c=getc(f1); //move to next character in the declaration list
while(c!='\n' & c!=';'){
idpos=0;
num=0;
while(isalpha(c)){
id[idpos++]=c;
c=getc(f1);
while(isdigit(c) || isalpha(c)){
id[idpos++]=c;
c=getc(f1);}
//support for array identification can be added here
if(c=='['){
num=0; //array size
c=getc(f1);
while(isdigit(c)){
num=num*10+((int)c-48);
c=getc(f1);
}
//idsize*=num;
//dt++;
//c=getc(f1);
}//if c=='[' close
id[idpos]='\0';
int f=searchtable(id);
if(f==1){
//int p=0;
//while(buf[p]!='\0') cout<<buf[p++];
//cout<<"\t";
if(num>0)
edittable(id,'i',dt+1,idsize*num);
else
edittable(id,'i',dt,idsize);
}
}//while(isalpha(c)) close
c=getc(f1);
}//while(c!='\n' & c!=';') close
}//if flag==1 close
c=getc(f1);
}//while(c!=EOF) close
fclose(f1);
}//identifydatatypes() close
void neutralize(){
for(int i=0;i<32;i++) tok[i]='\0';
}//neutralize() close
node* lex(FILE* f1){
char d,e,pos=0;
node* t=NULL;
//int p=0;
c=getc(f1);
while(c!=EOF){
neutralize();
t=NULL;
pos=0;
if(c==' '){
//c=getc(f1);
//cout<<"space\n";
//return NULL;
tok[0]=c;
tok[1]='\0';
break;
}
else if(c=='\n'){
//c=getc(f1);
//cout<<"newline\n";
//return NULL;
tok[0]=c;
tok[1]='\0';
break;
}
else if(c=='"'){ //bypass string literals
//cout<<"String literal\n";
c=getc(f1);
while(c!='"'){
c=getc(f1);
}
strcpy(tok,"String");
break;
//return NULL;
}//if c=='"' close
else if(isalpha(c) || isdigit(c)){
tok[pos++]=c;
c=getc(f1);
while(isalpha(c) || isdigit(c)){
tok[pos++]=c;
c=getc(f1);
}//while close
ungetc(c,f1);
tok[pos]='\0';
t=findintable(tok);
if(t!=NULL) return t;
else break;
}//else if (isalpha(c) || isdigit(c) close)
else{ //check for special characters and operators
//cout<<"SS\t";
if(c=='+'){
tok[pos++]=c;
//cout<<c;
d=getc(f1);
if(d=='='|| d=='+'){
tok[pos++]=d;
}
else ungetc(d,f1);
}//c=='+' close
else if(c=='-'){
tok[pos++]=c;
//cout<<c;
d=getc(f1);
if(d=='='|| d=='-'){
tok[pos++]=d;
}
else ungetc(d,f1);
}//c=='+' close
else if(c=='~' || c==','|| c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c==';'){
tok[pos++]=c;
}
else if(c=='<'){
tok[pos++]=c;
//putc(c,f4);
d=getc(f1);
if(d=='=') tok[pos++]=d;
else if(d=='<'){
tok[pos++]=d;
e=getc(f1);
if(e=='=') tok[pos++]=e;
else ungetc(e,f1);
}
else ungetc(d,f1);
}//c=='<' close
else if(c=='>'){
tok[pos++]=c;
d=getc(f1);
if(d=='=') tok[pos++]=d;
else if(d=='>'){
tok[pos++]=d;
e=getc(f1);
if(e=='=') tok[pos++]=e;
else ungetc(e,f1);
}
else ungetc(d,f1);
}//c=='>' close
else if(c=='|'){
tok[pos++]=c;
//putc(c,f4);