Professional Documents
Culture Documents
Week 4 & 5
Week 4 & 5
%{
int n = 0 ;
%}
/* rule section */
%%
. ;
%%
int main()
yylex();
}
5.Implement following programs using Lex.
A. Create a Lexer to take input from text file and count no of characters, no. of lines & no. of words.
/* DESCRIPTION/DEFINITION SECTION */
%{
#include<stdio.h>
%}
/* RULE SECTION */
%%
%%
int main(){
yylex();
return 0;
5B /*Write a LEX program to count the number of vowels and consonants in a given string */
%{
int vow_count=0;
%}
%%
[aeiouAEIOU] {vow_count++;}
[a-zA-Z] {const_count++;}
%%
int yywrap(){}
int main()
{
yylex();
return 0;