Friday, May 3, 2019

SS 2 - YACC - RECOGNIZE ALL STRINGS

2 - Develop, Implement and Execute a program using YACC tool to recognize all strings ending with b preceded by n a’s using the grammar an b (note: input n value)

lab2.l - PROGRAM

%{
#include "y.tab.h"
%}
%%
a {return A;}
b {return B;}
[\n] return '\n';
%%

lab2.y - PROGRAM

%{
#include<stdio.h>
#include<stdlib.h>
%}
%token A B
%%
input:s'\n' {printf("Successful Grammar\n");exit(0);}
s: A s1 B| B s1: ; | A s1
%%

main()
{
printf("Enter A String\n"); yyparse();
}

int yyerror()
{
printf("Error \n"); exit(0);
}

OUTPUT :( click on image to zoom )



No comments:

Post a Comment