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
%{
#include<stdio.h>
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");}
Why “n” is used in the program