-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathminicomplexer.c
79 lines (73 loc) · 1.44 KB
/
minicomplexer.c
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
FILE *infile;
static int cur_char=' ';
char tkname[MAXLEN];
int yylex()
{
char *p=tkname;
int tmp;
while(isspace(cur_char))
cur_char=getc(infile);
if(isdigit(cur_char)){
do{
*p++=cur_char;
cur_char=getc(infile);
}while(isdigit(cur_char));
if(cur_char=='.'){
*p++=cur_char;
cur_char=getc(infile);
while(isdigit(cur_char)){
*p++=cur_char;
cur_char=getc(infile);
}
}
*p++=0;
return TKNUMBER;
}
if(isalpha(cur_char)){
do{
*p++=cur_char;
cur_char=getc(infile);
}while(isalnum(cur_char));
*p++=0;
if(!strcmp(tkname,"int"))
return TKINT;
if(!strcmp(tkname,"real"))
return TKREAL;
if(!strcmp(tkname,"if"))
return TKIF;
if(!strcmp(tkname,"else"))
return TKELSE;
if(!strcmp(tkname,"while"))
return TKWHILE;
if(!strcmp(tkname,"return"))
return TKRETURN;
return TKIDENTIFIER;
}
tmp=cur_char;
cur_char=getc(infile);
if(tmp=='!'&&cur_char=='='){
cur_char=getc(infile);
return TKNEQ;
}
if(tmp=='<'&&cur_char=='='){
cur_char=getc(infile);
return TKLEQ;
}
if(tmp=='>'&&cur_char=='='){
cur_char=getc(infile);
return TKGEQ;
}
if(tmp=='&'&&cur_char=='&'){
cur_char=getc(infile);
return TKAND;
}
if(tmp=='|'&&cur_char=='|'){
cur_char=getc(infile);
return TKOR;
}
if(tmp==':'&&cur_char=='='){
cur_char=getc(infile);
return TKASSIGN;
}
return tmp;
}