Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include<stdio.h>
- int others = 0;
- int keyword = 0;
- int id = 0;
- %}
- %%
- "int"|"double"|"float"|"char"|"do"|"while"|"main"|"return"|"printf"|"scanf"|"include"|"stdio.h" {
- keyword++;
- printf("\'%s\' is a keyword\n",yytext);}
- [a-zA-Z_][a-zA-Z0-9_]* {
- id++;
- printf("\'%s\' is a identifier\n",yytext);}
- . {}
- %%
- int main()
- {
- yyin = fopen("input.c","r");
- yylex();
- printf("Number of identifier is %d\n", id);
- printf("Number of keyword is %d\n", keyword);
- return 0;
- }
- int yywrap()
- {
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement