Enter your email address & Win:

System Software Lab Programs ( Lex and Yaac Programs ) 5b

// June 13th, 2009 // Educational, Engineering, Unix and System Software Lab // Written by sandeephegde

-->

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;
}


If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts:

  1. System Software Lab Programs ( Lex and Yaac Programs ) 5a
  2. System Software Lab Programs ( Lex and Yaac Programs ) 6a
  3. System Software Lab Programs ( Lex and Yaac Programs ) 4a
  4. System Software Lab Programs ( Lex and Yaac Programs )1b
  5. System Software Lab Programs ( Lex and Yaac Programs )2a.l
blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes