Lex program to identify the capital words from the given input string
Problem definition:
Write a Lex Program to recognize the capital words from the given input string and display the result on standard output.
Video Tutorial:
Structure of LEX Program:
| %{ Definition section %} %% Rules section %% User Subroutine section |
Click here to learn – How to Compile & Run LEX / YACC Programs on Windows 8, 10, and 11?
Source Code – Lex program to identify the capital words from a string
/* Lex program to identify the capital words from the given input string.*/
%{
#include<stdio.h>
%}
%%
[A-Z]+[\t\n ] { printf("%s",yytext); }
. ;
%%
main( )
{
printf("Enter some string with capital words in between\n");
yylex();
}
int yywrap( )
{
return 1;
}Output:
maheshgh@maheshgh:~/LexYacc$ lex demo.l
maheshgh@maheshgh:~/LexYacc$ gcc lex.yy.c
maheshgh@maheshgh:~/LexYacc$ ./a.out
Enter some string with capital words in between
Mahesh Huddar VTU Belagavi Karnataka INDIA
(Note: press control+d after input)
VTU INDIA
Summary:
This article discusses how to Write a Lex Program to recognize the capital words from the given input string and display the result on standard output. If you like the article, do share it with your friends.
