System Software Lab Programs ( Lex and Yaac Programs ) 6a
// June 14th, 2009 // View Comments // Educational, Engineering, Unix and System Software Lab
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
………………………………………………………………………………………………………………………….
PART – A
………………………………………………………………………………………………………………………….
6) Program to recognize the grammar (anb, n>= 10).
6.l
/* 6.l */
%{
#include<stdio.h>
#include “y.tab.h”
%}
%%
[aA] return A;
[bB] return B;
.|\n return yytext[0];
%%
—————————————–
6.y
/* 6.y */
%{
#include<stdio.h>
%}
%token A B
%%
stmt: S ‘\n’ {printf(“\nValid expression”);exit(1);}
;
S: X B
X: X A | A A A A A A A A A A
%%
main()
{
printf(“\nEnter the expression: “);
if(yyparse())
{
printf(“\nValid expression”);
exit(0);
}
}
int yyerror()
{
printf(“\nInvalid expression\n”);
return 1;
}
int yywrap()
{
return 1;
}




