5. Lex program to count the number of identifiers

 

Lex program to count the number of identifiers


//Lex program to count the number of identifiers
%{#include<iostream.h>
int count=0;
char ch=0;
%}
digit[0-9]
letter[a-zA-Z_]

%%
{letter}({letter}|{digit})* {
 count++;
}

%%
int main()
{
 yylex();
 printf("count: %d",count);
 return 0;
} 
 
// Output of the above Program
Lex program to count the number of identifiers
Lex program to count the number of identifiers

Comments

Popular posts from this blog

Compiler Design

7. Lex specification program that generates a C program which takes a string “abcd” and prints the pattern

10. Program in YACC to recognize the string „abbb^n, „ab^n „a^n of the langauge (a^n b^n , n>=1)