-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenDfaCode.c
More file actions
51 lines (49 loc) · 1.54 KB
/
genDfaCode.c
File metadata and controls
51 lines (49 loc) · 1.54 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char A[100];
char B[100];
int num;
int tmp;
int main(){
freopen("./gramtmp.txt", "r", stdin);
freopen("./dfaCode.txt", "w", stdout);
for(int i = 0; i <= 126; i++){
scanf("%s %d %s", A, &num, B);
printf("case %d:\n", num);
scanf("%d", &num);
int hasDefault = 0;
for(int j = 1; j <= num; j++){
scanf("%s %s", A, B);
if(A[0] == '$'){
printf("\tif(synid == END){\n");
}else if(A[0] == '{'){
hasDefault = 1;
scanf("%d", &tmp);
if(B[0] == 'r'){
printf("\treturn reduce(%d);\n", tmp);
}else if(B[0] == 's'){
printf("\treturn shift(%d, stc, canGo);\n", tmp);
}
break;
}else{
printf("\tif(synid == %s){\n", A);
}
if(B[0] == 'a'){
printf("\t\tfin = 1;\n\t\treturn NULL;\n\t}\n");
}else{
scanf("%d", &tmp);
if(strlen(B) >= 7){
printf("\t\tshift(0, stc, canGo);\n\t\treturn reduce(%d);\n\t}\n", tmp);
}else if(B[0] == 'r'){
printf("\t\treturn reduce(%d);\n\t}\n", tmp);
}else if(B[0] == 's'){
printf("\t\treturn shift(%d, stc, canGo);\n\t}\n", tmp);
}
}
}
if(!hasDefault)
printf("\tsyntax_err(stc);\n");
}
return 0;
}