Lex Program to Check Parenthesis Matching

This is the lex program to check parenthesis matching,it checks whether left parenthesis or right parenthesis is missing

[cc lang=”c”]
%{
#include
int l=0,r=0,cbl=0,cbr=0;
%}
%%
[(] l++;
[)] r++;
[{] cbl++;
[}] cbr++;
[a-zA-Z0-9]+
“n” check();
%%
main()
{
yylex();}

check(){
if(l-r==0) printf(“Equal”);
else if(l>r) printf(“Ri Mising”);
else printf(“lefmisii”);
if(cbl-cbr==0) printf(“Equal”);
else if(cbl>cbr) printf(“Ri Mising”);
else printf(“lefmisii”);}
[/cc]

You may also like...

1 Response

  1. Ajinkya says:

    Why “n” is used in the program

Leave a Reply

Your email address will not be published. Required fields are marked *