SE250:lab-8:vpup001

From Marks Wiki
Jump to navigation Jump to search

This lab is about parse trees. There were few errors in the code. I have fixed them with the help of my friend and the tutor. The 'expect' function should be after the 'error' function.

Task 1

Just downloading the code from wiki.

Task 2

The code for this task...

int main(){
	char *file="lab8.jpg";
	ParseTree* t = mkNode('-', mkNode( '-', mkNode( 'a', 0 ), mkNode( 'b', 0 ), 0 ), 0);
	prefix_tree(t);
	tree_to_graph( t, file );
	return 0;
}

Output: -(-(a b))

Task 3 & 4

For this task, I have done 3 parse trees and combined them.

int main(){
	char *file="lab8.jpg";
	ParseTree* t1 = mkNode('>', mkNode( '+', mkNode( 'a', 0 ), mkNode( 'b', 0 ), 0), mkNode('c' ,0), 0);
	ParseTree* t2 = mkNode( '*', mkNode('z', 0), mkNode('+', mkNode( 'y', 0), mkNode( 'b', 0), 0), 0);
	ParseTree* t3 = mkNode('?', mkNode('=', mkNode('a', 0), mkNode('2', 0), 0), mkNode('-', mkNode('x', 0), mkNode('y', 0), 0), mkNode('-', mkNode('y', 0), mkNode('x', 0), 0), 0);
	ParseTree* t = mkNode('?', t1, t2, t3, 0);
	prefix_tree(t);
	tree_to_graph( t, file );
	return 0;
}

Output: ?(>(+(a b) c) *(z +(y b)) ?(=(a 2) -(x y) -(y x)))

I found it easier to split the tree and combine it instead of doing the whole thing in one line. I have also drawn the graph.