This post was published long ago, when I was a student and an amateur blogger. The links might be outdated and content may not be useful anymore. Please read this content keeping its age in mind.
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
………………………………………………………………………………………………………………………….
PART – A
………………………………………………………………………………………………………………………….
5b. Program to recognize strings ‘aaab’, ‘abbb’, ‘ab’ and ‘a’ using the grammar (anbn, n>= 0).
5b.l
%{
#include<stdio.h>
#include “y.tab.h”
%}
%%
[a] return A;
[b] return B;
. return yytext[0];
n return yytext[0];
%%
5b.y
%{
#include<stdio.h>
%}
%token A B
%%
input:expr ‘n’ {return 0;}
expr: X
X: A X B|;
%%
main()
{
printf(“nEnter string: “);
if(!yyparse())
{
printf(“nValid”);
exit(0);
}
}
int yyerror()
{
printf(“nInvalid”);
return 1;
}
int yywrap()
{
return 1;
}
Leave a ReplyCancel reply