-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parser.c
More file actions
61 lines (57 loc) · 1.25 KB
/
test_parser.c
File metadata and controls
61 lines (57 loc) · 1.25 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
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <stdlib.h>
#include "ast.h"
#include "symtab.h"
#include "y.tab.h"
extern int yylineno;
extern char *filename;
extern FILE *outfile;
extern DeclrListNode *ast;
char* samples[] = {
"./test_files/ack.m",
"./test_files/ary.m",
"./test_files/blocks.m",
"./test_files/dangling.m",
"./test_files/fibo.m",
"./test_files/hello.m",
"./test_files/loops.m",
"./test_files/priority.m",
"./test_files/random.m",
"./test_files/sumcol.m",
NULL
};
int main() {
int i;
int test_passed = 1;
for(i = 0; test_passed && samples[i]; i++) {
FILE *sample, *tmp1, *tmp2;
char c1, c2;
char temp1[L_tmpnam];
char temp2[L_tmpnam];
filename = samples[i];
sample = fopen(samples[i],"r");
yyrestart(sample);
yylineno = 1;
yyparse();
tmp1 = tmpfile();
outfile = tmp1;
print_declrlist(0, ast);
fflush(tmp1);
rewind(tmp1);
fclose(sample);
yyrestart(tmp1);
yylineno = 1;
yyparse();
tmp2 = tmpfile();
outfile = tmp2;
print_declrlist(0, ast);
fflush(tmp2);
rewind(tmp1);
rewind(tmp2);
while((c1=fgetc(tmp1))!= EOF && (c2=fgetc(tmp2))!= EOF)
test_passed = (test_passed && c1 == c2);
fclose(tmp1);
fclose(tmp2);
}
if(test_passed) printf("Ok\n");
}