SS 2 – YACC – RECOGNIZE ALL STRINGS

  SS LAB
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 Grammarn”);exit(0);}
s: A s1 B| B s1: ; | A s1
%%

main()
{
printf(“Enter A Stringn”); yyparse();
}

int yyerror()
{
printf(“Error n”); exit(0);
}

OUTPUT :( click on image to zoom )

LEAVE A COMMENT