-
Notifications
You must be signed in to change notification settings - Fork 0
/
printParseTree.c
59 lines (56 loc) · 1.49 KB
/
printParseTree.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
/*
Group Number: 55
Group Member details:
1. Aarjav Jain -- 2018A7PS0222P
2. Pranav Gupta -- 2018A7PS0190P
3. Harsh Sulakhe -- 2018A7PS0186P
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "datastructuresandprototypes.h"
// Function Definition: printParseTree (parseTree *t)
int printParseTree(parseTree *t) {
if (t == NULL)
return 1;
if (t->depth == 0)
printf ("%20s\t%10s\t%10s\t%15s\t %10s\t\t%5s\t%10s\n", "Symbol", "isTerminal", "Lexeme", "Line Number", "Grammar Rule", "Depth", "Type Expression");
printf("%20s\t", t->symbolName);
if (t->isTerminal){
printf("%10s\t","True");
} else {
printf("%10s\t","False");
}
if (t->lexeme) {
printf("%10s\t", t->lexeme);
} else {
printf("%10s\t", "-");
}
// if (t->isLeaf) {
// printf("%d \t", t->lineNumber);
// } else {
// printf("- \t");
// }
printf("%10d\t\t", getLineNumber(t));
if (!(t->isLeaf)) {
printf("%3d\t\t", t->grammarRuleUsed->grammarRuleNum);
} else {
printf("%3s\t\t", "-");
}
printf("%5d\t", t->depth);
if (!(t->isLeaf) && t->type) {
printTypeExpression(t->type);
printf("\t");
} else {
printf ("%10s\t", "-");
}
printf("\n");
//line, grammar, depth
// print children
for (int i = 0; i < MAX_PARSE_TREE_CHILDREN; i++) {
if (t->children[i])
printParseTree(t->children[i]);
}
return 0;
}