Wisdom Materials
Home
About Us
Our Clients
Careers
Services
Education
Jobs
News
Business
Health
Astrology
Entertainment
RealEstate
Devotion
Contact Us
Compiler Construction Lab Manual
/ Counting Vowels and Consonants LEX Program
Program Name
Write a Compiler Construction Program for Counting Vowels and Consonants LEX Program.
Theory
//Vi file.c Hello World
Program Code
Copy Program Code
%{ #include
int vowels; int cons; char n; %} %% [a|e|i|o|u|A|E|I|O|U] {vowels++;} [a-zA-Z] {cons++;} %% int main(int argc,char *argv[]) { yyin=fopen(argv[1],"r"); yylex(); printf("no of vowels=%d\n no of constants=%d\n",vowels,cons); fclose(yyin); return 0; } int yywrap(void){ return 1; }
Saving:
vi voww.l
Compiling and Running
lex voww.l
cc lex.yy.c
./a.out file.c
Input
Output
no of vowels=3 no of constants=7
Home
Back