Category: C Programming

0

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();}...

1

Lex Program to Check String Palindrome

This is the lex program to check whether the given string is palindrome or not. [cc lang=”c”] %{ #include char num,temp[100]; int rev=0; char arr[100]; %} %% . scanf(“%s”,arr); temp=arr; while(temp!=0){rev=rev*10+(temp%10); temp/=10;} if(rev==num) printf(“PALI”);...

0

Lex Program to Identify Comment Lines

Lex Program to Identify both single line and multi line comments using regular expressions in lex [cc lang=”c”] %{ #include %} %% [/]{1}[/]{1}[a-zA-Z0-9]* printf(“Single Line Comment”); [/]{1}[*]{1}[a-zA-Z0-9]*[*]{1}[/]{1} printf(“MultiLine Comment”); %% main(){yylex();} [/cc]