/*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
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 this code
No comments:
Post a Comment