FLEX (Fast Lexical Analyzer Generator) is a tool/computer program for generating lexical analyzers (scanners or lexers) written by Vern Paxson in C around 1987. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. The function yylex() is the main flex function which runs the Rule Section. Prerequisite: FLEX (Fast Lexical Analyzer Generator) Example:
Input:
hello how
are
you?
Output:
hellohowareyou?
Input:
Welcome to
Geeks for
Geeks
Output:
WelcometoGeeksforGeeks
Approach: Open input file in read mode and whenever parser encounters newline (\n), space ( ) or tab (\t) remove it and write all the other characters in output file. Input File: Input.txt (Input File used in this program)
Below is the implementation program:
C
% {
%
}
% %
[ \n\t]+ { fprintf (yyout, "%s");}
. { fprintf (yyout, "%s", yytext); }
% %
int main()
{
extern FILE *yyin, *yyout;
yyin = fopen ("Input.txt", "r");
yyout = fopen ("Output.txt", "w");
yylex();
return 0;
}
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
14 Feb, 2023
Like Article
Save Article