-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpros.y
More file actions
40 lines (40 loc) · 677 Bytes
/
pros.y
File metadata and controls
40 lines (40 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
%{
#include<stdio.h>
#include<stdlib.h>
int yylex();
int yyerror();
%}
%token A B P Q C G H I
%%
srt: R'\n' {printf("Grammar accepted is p^nq^n, n>0\n");return 0;}|
S'\n' {printf("Grammar accepted is a^nb, n>0\n");return 0;}|
E'\n' {printf("Grammar accepted is cg^n, n>0\n");return 0;}|
T'\n' {printf("Grammar accepted is hi^nh, n>0\n");return 0;}
S:X B
X:X A
|
;
R:P R Q
|
;
E:C F
F:F G
|
;
T:H Z H
Z:Z I
|
;
%%
int yyerror()
{
printf("Does not match any grammar\n");
exit(0);
}
int main()
{
int ch;
printf("enter according to grammar\n 1.a^nb,n>0\n 2.p^nq^n,n>0\n 3.cg^n, n>0\n 4.hi^nh, n>0\n");
printf("enter the string\n");
yyparse();
}