Skip to content

Latest commit

 

History

History
46 lines (40 loc) · 581 Bytes

.md

File metadata and controls

46 lines (40 loc) · 581 Bytes

9. Demonstrate a Lex program to printout all HTML tags in file.

%{
#include<stdio.h>
int c = 0;
%}
%%
[<][^>]*[>] {printf("%s", yytext);c++;}
.|\n {;}
%%
void main()
{
	yyin = fopen("test.html", "r");
	yylex();
	printf("\nTotal tags = %d\n",c);
}
int yywrap()
{ 
	return 1;
}
test.html :-
<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <p>
            this is paragraph.
        </p>
    </body>
</html>

Output :-
<html><head><title></title></head><body><p></p></body></html>
Total tags = 10