LEX code to extract HTML tags from a file

Lex is a computer program that generates lexical analyzers and was written by Mike Lesk and Eric Schmidt.
Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language.
Prerequisite: Flex (Fast lexical Analyzer Generator)

The extraction is based on the way tags are written in HTML. All tags are included in < >. This will set the rule to extract the HTML tags from the given input file.

Input File: tags.txt

Below is the implementation to extract HTML tags from file:





/* Declaration section*/
"<"[^>]*> {printf("%s\n", yytext); }  /* if anything enclosed in 
                                      these < > occur print text*/
. ;  // else do nothing
int yywrap(){}
int main(int argc, char*argv[])
    // Open tags.txt in read mode
    extern FILE *yyin = fopen("tags.txt","r"); 
    // The function that starts the analysis
    return 0;


Output :

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : nidhi_biet

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.