Print out all HTML tags in file in Lex
EXAMPLE :-
Create first file tag.l or tag.lex , and Create Second file tags.txt
tag.l
%{
%}
%%
"<"[^>]*> {printf("%s\n", yytext); }
. ;
%%
int yywrap(){}
int main(int argc, char*argv[])
{
yyin=fopen("tags.txt","r");
yylex();
return 0;
}
INPUT :-
tags.txt
<html>
<title> Html Tags </title>
<head></head>
<body>
<h1> A smile is happiness you’ll find right under your nose. </h1>
</body>
</html>
OUTPUT
sunny@sunny-PC:~/Desktop$ flex h.l
sunny@sunny-PC:~/Desktop$ gcc lex.yy.c
sunny@sunny-PC:~/Desktop$ ./a.out
<html>
<title>
</title>
<head>
</head>
<body>
<h1>
</h1>
</body>
</html>
No comments:
Post a Comment
Please do not any spam link in Comment Box