Sunday, 16 November 2014

YACC PROGRAM to recognize the grammar (a^n)(b^n)


program to recognize the grammar (a^n)(b^n) where n>=0



6.l
%{
#include "y.tab.h"
%}
%%
"a"|"A" {return A;}
"b"|"B" {return B;}
[ \t] {;}
\n {return 0;}
. {return yytext[0];}
%%


6.y
%{
#include<stdio.h>
%}
%token A B
%%
stmt: S
    ;
S: A S B
  |
 ;
%%
void main()
{
printf("enter \n");
yyparse();
printf("valid");
exit(0);
}
void yyerror()
{
printf("invalid ");
exit(0);
}

4 comments:

Total Pageviews