Monday 25 April 2016

Program in YACC to recognize the string „abbb^n, „ab^n „a^n of the langauge (a^n b^n , n>=1)

//Program in YACC to recognize the string „abbb^n, „ab^n „a^n of the langauge (a^n b^n , n>=1)

File Name : pr11.y
%{
 #include<stdio.h>
 int yylex(void);
 int yyerror(char *); 
%}
%token A B

%%

statement : expr 
;
expr :A expr B
| A B   
;

%%

int main()
{
 printf("Enter the string :");
 yyparse();
 return 0;
}
int yyerror(char *s)
{
 printf("Invalid");
}


File Name : pr11.l
%{
 #include "y.tab.h"
 extern int yylval;
%}
A [a]
B [b]
%%

{A} {yylval=yytext[0];return A;}
{B} {yylval=yytext[1];return B;}
\n {return 0;}
. {return yytext[0];}

%%

// Output of the Above Program.

Program in YACC to recognize the string „abbb^n, „ab^n „a^n of the langauge (a^n b^n , n>=1)
Program in YACC to recognize the string „abbb^n, „ab^n „a^n of the langauge (a^n b^n , n>=1)

1 comment:

  1. No need of yylval assignment statement as it will return automatically the required token.

    ReplyDelete