YACC Program to Implement a^nb

This is the YACC Program to Implement a program that accepts string of form a^nb where n>=1 ie..aaab or aaaaab or ab.it cannot have two or more than one b’s at the end
Lex: Program
[cc lang=”c”]
%{
#include
%}
%token A CO ZA ER ERR
%%
start:CO {printf(“Valid declaration”);}
%%
void yyerror(const char *str){printf(“error”);}
int yywrap(){return 0;}
main()
{yyparse();}
[/cc]
YACC Program:
[cc lang=”c”]
%{
#include
%}
%token A CO ZA ER ERR
%%
start:CO {printf(“VAlid declaration”);}
%%
void yyerror(const char *str){printf(“error”);}
int yywrap(){return 0;}
main()
{yyparse();}
[/cc]

You may also like...

Leave a Reply

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