-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6bss.l
More file actions
58 lines (34 loc) · 731 Bytes
/
Copy path6bss.l
File metadata and controls
58 lines (34 loc) · 731 Bytes
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
%{
#include<stdio.h>
int count=0;
%}
op [\+\-\*\/\=]
nop[\,\;\””]
letter [a-zA-Z]
digitt [0-9]
id {letter}*|({letter}{digitt})+
notid ({digitt}{letter})+
%%
[\t\n]+
("int")|("float")|("char")|("case")|("default")|("if")|("for")|("printf")|("scanf")|("include") { printf("%s is a keyword\n", yytext); }
{id} {printf("%s is an identifier\n", yytext); count++;}
"+"|"-"|"*"|"/"|"=" {printf( "An operator: %s\n", yytext);}
{notid} {printf("%s is not an identifier\n", yytext);}
{nop} {;}
%%
int main()
{
FILE *fp;
char file[10];
printf("\nEnter the filename: ");
scanf("%s", file);
fp=fopen(file,"r");
yyin=fp;
yylex();
printf("Total identifiers are: %d\n", count);
return 0;
}
int yywrap()
{
return 1;
}