-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyscanner.c
More file actions
191 lines (189 loc) · 5.44 KB
/
myscanner.c
File metadata and controls
191 lines (189 loc) · 5.44 KB
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
#include <stdio.h>
#include "defs.h"
#include <string.h>
#include <stdlib.h>
extern int yylex(); // gets token id
extern int yylineno; // has token line number
extern char* yytext; // has token value
int main(void)
{
FILE * fp = fopen ("out.txt","w");
int token;
token = yylex();
while (token){
switch(token){
case ERROR:
fprintf(fp,"Error values: %s at line %d\n",yytext,yylineno);
break;
case CONSTANT:
fprintf(fp,"Constant key word: %s at line %d\n",yytext,yylineno);
break;
case INT:
fprintf(fp,"Int key word: %s at line %d\n",yytext,yylineno);
break;
case FLOAT:
fprintf(fp,"Float key word: %s at line %d\n",yytext,yylineno);
break;
case STRING:
fprintf(fp,"String key word: %s at line %d\n",yytext,yylineno);
break;
case CHAR:
fprintf(fp,"Char key word: %s at line %d\n",yytext,yylineno);
break;
case BOOL:
fprintf(fp,"Boolean key word: %s at line %d\n",yytext,yylineno);
break;
case IF:
fprintf(fp,"If key word: %s at line %d\n",yytext,yylineno);
break;
case THEN:
fprintf(fp,"Then key word: %s at line %d\n",yytext,yylineno);
break;
case ELSE:
fprintf(fp,"Else key word: %s at line %d\n",yytext,yylineno);
break;
case WHILE:
fprintf(fp,"While key word: %s at line %d\n",yytext,yylineno);
break;
case DO:
fprintf(fp,"Do key word: %s at line %d\n",yytext,yylineno);
break;
case SWITCH:
fprintf(fp,"Switch key word: %s at line %d\n",yytext,yylineno);
break;
case CASE:
fprintf(fp,"Case key word: %s at line %d\n",yytext,yylineno);
break;
case DEFAULT:
fprintf(fp,"Default key word: %s at line %d\n",yytext,yylineno);
break;
case FOR:
fprintf(fp,"For key word: %s at line %d\n",yytext,yylineno);
break;
case AND:
fprintf(fp,"And key word: %s at line %d\n",yytext,yylineno);
break;
case OR:
fprintf(fp,"Or key word: %s at line %d\n",yytext,yylineno);
break;
case EQUALEQUAL:
fprintf(fp,"EQUALEQUAL values: %s at line %d\n",yytext,yylineno);
break;
case GREATERTHAN:
fprintf(fp,"GREATERTHAN values: %s at line %d\n",yytext,yylineno);
break;
case SMALLERTHAN:
fprintf(fp,"SMALLERTHAN values: %s at line %d\n",yytext,yylineno);
break;
case GREATERTHANOREQUAL:
fprintf(fp,"GREATERTHANOREQUAL values: %s at line %d\n",yytext,yylineno);
break;
case SMALLERTHANOREQUAL:
fprintf(fp,"SMALLERTHANOREQUAL values: %s at line %d\n",yytext,yylineno);
break;
case INTVALUE:
fprintf(fp,"int values: %s at line %d\n",yytext,yylineno);
break;
case FLOATVALUE:
fprintf(fp,"Float values: %s at line %d\n",yytext,yylineno);
break;
case STRINGVALUE:
fprintf(fp,"String values: %s at line %d\n",yytext,yylineno);
break;
case CHARVALUE:
fprintf(fp,"Char values: %s at line %d\n",yytext,yylineno);
break;
case BOOLVALUE:
fprintf(fp,"Boolean values: %s at line %d\n",yytext,yylineno);
break;
case IDENTIFIER:
fprintf(fp,"Identifier values: %s at line %d\n",yytext,yylineno);
break;
case OPENED_BRACKET:
fprintf(fp,"Opened bracket: %s at line %d\n",yytext,yylineno);
break;
case SEMI_COLON:
fprintf(fp,"Semi colon: %s at line %d\n",yytext,yylineno);
break;
case CLOSED_BRACKET:
fprintf(fp,"Closed bracket: %s at line %d\n",yytext,yylineno);
break;
case OPENED_BRACE:
fprintf(fp,"Opened brace: %s at line %d\n",yytext,yylineno);
break;
case CLOSED_BRACE:
fprintf(fp,"Closed brace: %s at line %d\n",yytext,yylineno);
break;
case OPENED_SQ_BRACKET:
fprintf(fp,"Opened sq bracket: %s at line %d\n",yytext,yylineno);
break;
case CLOSED_SQ_BRACKET:
fprintf(fp,"Closed sq bracket: %s at line %d\n",yytext,yylineno);
break;
case COMMA:
fprintf(fp,"Comma: %s at line %d\n",yytext,yylineno);
break;
case TWO_DOTS:
fprintf(fp,"Two dots: %s at line %d\n",yytext,yylineno);
break;
case PLUS:
fprintf(fp,"Plus: %s at line %d\n",yytext,yylineno);
break;
case MINUS:
fprintf(fp,"Minus: %s at line %d\n",yytext,yylineno);
break;
case MULTIPLY:
fprintf(fp,"Multiply: %s at line %d\n",yytext,yylineno);
break;
case DIVIDE:
fprintf(fp,"Divide: %s at line %d\n",yytext,yylineno);
break;
case REMAINDER:
fprintf(fp,"Remainder: %s at line %d\n",yytext,yylineno);
break;
case PLUS_EQUAL:
fprintf(fp,"Plus equal: %s at line %d\n",yytext,yylineno);
break;
case MINUS_EQUAL:
fprintf(fp,"Minus equal: %s at line %d\n",yytext,yylineno);
break;
case MULTIPLY_EQUAL:
fprintf(fp,"multiply equal: %s at line %d\n",yytext,yylineno);
break;
case DIVIDE_EQUAL:
fprintf(fp,"divide equal: %s at line %d\n",yytext,yylineno);
break;
case PLUS_PLUS:
fprintf(fp,"plus plus: %s at line %d\n",yytext,yylineno);
break;
case MINUS_MINUS:
fprintf(fp,"minus minus: %s at line %d\n",yytext,yylineno);
break;
case EQUAL:
fprintf(fp,"equal: %s at line %d\n",yytext,yylineno);
break;
case NOT:
fprintf(fp,"Not: %s at line %d\n",yytext,yylineno);
break;
case NOTEQUAL:
fprintf(fp,"Not equal: %s at line %d\n",yytext,yylineno);
break;
case RETURN:
fprintf(fp,"Return values: %s at line %d\n",yytext,yylineno);
break;
case MAIN:
fprintf(fp,"Main values: %s at line %d\n",yytext,yylineno);
break;
case COMMENT:
fprintf(fp,"Comment values: %s at line %d\n",yytext,yylineno);
break;
case VOID:
fprintf(fp,"Void values: %s at line %d\n",yytext,yylineno);
break;
}
token = yylex();
}
fclose (fp);
printf("Done!\n");
return 0;
}