Lex Program to Identify Tokens

This is the Lex Program to identify tokens in a program using regular expressions

[cc lang=”c”]
%{
#include
%}
%%
bool|int|float printf(“Keyword”);
[-,+]?[0-9]+ printf(“Constants”);
[,.'”]+ printf(“Punctuation Chars”);
[!@#$%^&*()]+ printf(“Special Chars”);
[a-zA-Z]+ printf(“Identifiers”);
%%
main(){yylex();}
[/cc]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *