-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.c
68 lines (65 loc) · 1.52 KB
/
driver.c
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
63
64
65
66
67
68
/*
Group 28
Utkarsh Kumar 2017B2A71008P
Suchisattam Saran 2017B2A70585P
Supratik Bhattacharya 2017B2A70745P
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "def.h"
//#include "read.h"
void printParseTree(parseTree *t)
{
if(t != NULL)
{
char term[5] = "NO";
char gram[5] = "NA";
if(t->term)
strcpy(term, "YES");
if(t->gram)
printf("\nSymbol : %s, line : %d, term? : %s, keyword? : %d, Grammar : %d\n",t->sym, t->line, term, t->key, t->gram);
else
printf("\nlabel : %s, line : %d, term? : %s, keyword? : %d, Grammar : %s\n",t->sym, t->line, term, t->key, gram);
printParseTree(t->child);
}
fflush(stdout);
return;
}
int main()
{
tokenStream *s =NULL;
char filename[20];
printf("enter name of test case file (example : t1.txt): ");
scanf("%s",&filename);
s = tokeniseSourcecode(filename, s);
tokenStream *ptr = s;
grammar G = getPoint(G);
FILE *fp2 = fopen("group_28_grammar.txt", "r");
G = readGrammar(fp2, G);
parseTree *t = NULL;
int option = 1;
while(option != 0){
printf("\nprovide options for the file (0-4): ");
scanf("%d", &option);
switch(option)
{
case 0:
break;
case 1:
t = createParseTree(t, s, G); break;
case 2:
printf("Traversal in level order not implemented !\n"); break;
case 3:
if(t != NULL){
printParseTree(t); break;}
else
{printf("Create tree first (option = 1)\n"); break;}
case 4:
printf("type expression table not implemented fully !\n"); break;
default :
printf("Not an option!\n");
}
}
return 0;
}