/* 7a. Write a LEX program to identify a compound statement */
%{
#include"stdio.h"
int count=0;
%}
%%
" [aA][nN][dD] " count ++;
" [oO][rR] " count++;
" [bB][uU][tT] " count++;
%%
main()
{
yylex();
if( count != 0 )
printf("\nIt is a compound statement");
else
printf("\nIts is a Simple statement");
}
/* 7b. Write a YACC program to identify a language a^n b^n, where n>0 */
%{
# define YYSTYPE char
%}
%token A
%token B
%%
pattern:
|pattern '\n'
|pattern id '\n'
;
id:
A B
|A id B
;
%%
#include<stdio.h>
main()
{
yyparse();
}
yylex()
{
int c;
while((c=getchar())=='\t'||c==' ');
if(c=='a')
return A;
if(c=='b')
return B;
}
yyerror(char *s)
{
printf("\n%s",s);
}