Professional Documents
Culture Documents
Keywords
Keywords
keywords____________________________________________________________
i-->
%{
#include <stdio.h>
int keywordCount = 0;
%}
%%
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 {
printf("Keyword: %s\n", yytext);
keywordCount++;
}
[a-zA-Z][a-zA-Z0-9]* { /* Ignore identifiers */ }
.|\n { /* Ignore other characters */ }
%%
int main() {
char fileName[256];
printf("Enter the name of the C code file: ");
scanf("%255s", fileName);
yylex();
fclose(file);
return 0;
}
ii-->
#include<stdio.h>
void main(){
//my single line comment
printf("my prog");
for(i=0;i<n;i++)
printf("sam.file");
return 0;
/*this ismulti line comment*/
}
output____________________
$ vi identifier.l
$ vi sam.c
$ lex identifier.l
$ cc lex.yy.c -o identifier -ll
$ ./identifier
Enter the name of the C code file: sam.c
Keyword: void
Keyword: for
Keyword: return