You are on page 1of 6

SWATHI MN.

N 3 SEM MCA USN: 1PT12MCA49


6. Program to recognie !tring! "aaa#$%$a###$%$a#$ an& "a$ '!ing
t(e grammar a)n#)n n*+,
-E. P/01/AM
%{
#include"y.tab.h"
%}
%%
[a]+ return A;
[b]+ return B;
"1" return ONE;
\n return ;
. return yyte!t[];
%%
2ACC P/01/AM
%{
#include"#tdi$.h%
int &alid';
%}
%t$(en A B ONE
%%
#t) e!*n {&alid'1;}
e!*n) A B
+A
+B
+ONE;
%%
,ain-.{
*rint/-"\n Enter a #entence ) \n".;
yy*ar#e-.;
i/-&alid0'.{
*rint/-"\n 1alid 2entence\n".;
}
el#e
*rint/-"\n 3n&lid 2entence\n".;
}
yyerr$r-char 4#.{
*rint/-"\nErr$r i# ) %#\n"5#.;
}
S2STEMS P/01/AMMIN1 -A3 2451,52,13 6EPA/TMENT 07 MCA
SWATHI MN.N 3 SEM MCA USN: 1PT12MCA49
0't8't:
[user109@localhost user109]$ yacc -d partbpr6.y
[user109@localhost user109]$ lex partbpr6.l
[user109@localhost user109]$ cc lex.yy.c y.tab.c -ll
[user109@localhost user109]$ ./a.out
1. Enter a sentence :
a
Vald !entence
". Enter a sentence :
aaab
Vald !entence
#. Enter a sentence :
ab
Vald !entence
$. Enter a sentence :
b
Vald !entence
%. Enter a sentence :
aaaa
Vald !entence
6. Enter a sentence :
aaaaaaaab
Vald !entence
&. Enter a sentence :
abbbbbbbbb
Vald !entence
'. Enter a sentence :
1
Vald !entence
9. Enter a sentence :
aaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb
Vald !entence
10. Enter a sentence :
a(b
Error s : syntax error
)n*ald !entence
S2STEMS P/01/AMMIN1 -A3 2451,52,13 6EPA/TMENT 07 MCA
SWATHI MN.N 3 SEM MCA USN: 1PT12MCA49
9. Program to recognie t(e grammar a)#% n*+1,:
-E. P/01/AM
%{
#include"y.tab.h"
%}
%%
[a]{6} {return AN3NE;}
a return A;
b return B;
\n return EN7E8;
. return yyte!t[];
%%
2ACC P/01/AM
%{
#include"#tdi$.h%
int &alid';
%}
%t$(en AN3NE A B EN7E8
%%
#t) AN3NE e!*n B EN7E8 {&alid'1;}
e!*n) A e!*n
+A
;
%%
,ain-.{
*rint/-"\n Enter a #entence ) \n".;
yy*ar#e-.;
i/-&alid0'.{
*rint/-"\n 1alid 2entence\n".;
}
el#e
*rint/-"\n 3n&lid 2entence\n".;
}
yyerr$r-char 4#.{
*rint/-"\nErr$r i# ) %#\n"5#.;
}
S2STEMS P/01/AMMIN1 -A3 2451,52,13 6EPA/TMENT 07 MCA
SWATHI MN.N 3 SEM MCA USN: 1PT12MCA49
0't8't:
[user109@localhost user109]$ lex partbpr&.l
[user109@localhost user109]$ cc lex.yy.c y.tab.c -ll
[user109@localhost user109]$ ./a.out
1. Enter a sentence :
aaaaaaab
Error s : syntax error
)n*ald !entence
". Enter a sentence :
aaaaaaaaaab
Vald !entence
#. Enter a sentence :
aaaaaaaaaaaab
Vald !entence
$. Enter a sentence :
aaaaaaaaaaaaabb
Error s : syntax error
)n*ald !entence
%. Enter a sentence :
+aaaa$$$$$+++aaaaaaaaaaab(,-
)n*ald !entence
S2STEMS P/01/AMMIN1 -A3 2451,52,13 6EPA/TMENT 07 MCA
SWATHI MN.N 3 SEM MCA USN: 1PT12MCA49
#. .ro/ra0 to reco/n1e a *ald arth0etc expresson that uses 23
- 4and /
-E. P/01/AM
%{
#include"#tdi$.h%
#include"y.tab.h"
%}
%%
[96]+ return N:;;
[\t] ;
\n return ;
. return yyte!t[];
%%
2ACC P/01/AM
%{
#include"#tdi$.h%
int &';
%}
%t$(en N:;
%le/t <+<<9<
%le/t <4<<=<
%n$na##$c >;3N:2
%%
#) e!* {&'1;}
e!*) <-< e!*? <.<
+e!*?
e!*?) e!* <+< e!*
+e!* <9< e!*
+e!* <4< e!*
+e!* <=< e!*
+<9<e!* %*rec >;3N:2
+N:;;
%%
,ain-.{
*rint/-"\n Enter the nu,eric e!*re##i$n)\n".;
yy*ar#e-.;
i/-&.
*rint/-"\n 1alid E!*re##i$n\n".;
el#e
*rint/-"\n 3n&alid e!*re##i$n\n".;
}
yyerr$r-char 4#.{
*rint/-"\nErr$r i# ) %#"5#.;
}
S2STEMS P/01/AMMIN1 -A3 2451,52,13 6EPA/TMENT 07 MCA
SWATHI MN.N 3 SEM MCA USN: 1PT12MCA49
0't8't:
[user109@localhost user109]$ yacc -d partbpr#.y
[user109@localhost user109]$ cc lex.yy.c y.tab.c
[user109@localhost user109]$ ./a.out
1. Enter the nu0erc expresson:
512106-%
Vald Expresson
". Enter the nu0erc expresson:
59-664#/'-"5
Error s : syntax error
)n*ald expresson
#. Enter the nu0erc expresson:
59-'/"21064'/"-6/"2&
Vald Expresson
$. Enter the nu0erc expresson:
a2b-'/"
Error s : syntax error
)n*ald expresson
%. Enter the nu0erc expresson:
592"6
Vald Expresson
6. Enter the nu0erc expresson:
5946
Error s : syntax error
)n*ald expresson
&. Enter the nu0erc expresson:
'
Vald Expresson
'. Enter the nu0erc expresson:
9264$/"
Vald Expresson
S2STEMS P/01/AMMIN1 -A3 2451,52,13 6EPA/TMENT 07 MCA