-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.txt
More file actions
62 lines (56 loc) · 948 Bytes
/
2.txt
File metadata and controls
62 lines (56 loc) · 948 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Develop, Implement and Execute a program using YACC tool to recognize all strings ending with b preceded by n a’s using the grammar an b (note: input n value).
LEX PROGRAM:
%{
#include"y.tab.h"
%}
%%
[a] {return A;}
[b] {return B;}
. {return yytext[0];}
"\n" {return NL;}
%%
YACC PROGRAM:
%{
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
%}
%token A B NL
%%
stmt:s B NL {printf("valid string\n");exit(0);};
s:s A
|
;
%%
extern FILE *yyin;
int main()
{
FILE *fp;
char a[10],b[10];
int n,m,i;
printf("enter the value of n and m:\n");
scanf("%d%d",&n,&m);
for(i=0; i<n; i++)
{
a[i]='a';
}
a[n]='\0';
for(i=0; i<m; i++)
{
b[i]='b';
}
b[m]='\0';
strcat(a,b);
printf("the generated string is: %s\n",a);
fp=fopen("string.txt","w");
fprintf(fp,"%s\n",a);
fclose(fp);
fp=fopen("string.txt","r");
yyin=fp;
yyparse();
}
int yyerror()
{
printf("Invalid expression\n");
return 0;
}