SE250:lab-8:asin185

From Marks Wiki
Jump to navigation Jump to search

Lab 8

In this lab we explored parse tree, then going into deep structure and shallow structure......First things first....This code doesn't compile, not to worry 5 min of the demonstrators help and were away.

Task 1

ParseTree* t = mkNode( '-', mkNode( '-', mkNode( 'a', 0 ), mkNode( 'b', 0 ), 0 ), 0);
prefix_tree(t);

Task 2

ParseTree* t = mkNode( '?', mkNode( '>', mkNode( '+', mkNode( 'a', 0 ), mkNode( 'b', 0 ), 0  ),mkNode ( 'c', 0)) ,
mkNode('*', mkNode('z', 0), mkNode('+', mkNode( 'a', 0 ), mkNode( 'b', 0 ), 0), 0), mkNode( '?',         mkNode( '=',
mkNode( 'a', 0 ), mkNode( '2', 0 ), 0), 0), mkNode( '-', mkNode( 'x', 0 ), mkNode( 'y', 0 ), 0),  mkNode( '-', mkNode( 'y', 0 ),
mkNode( 'x', 0 ), 0), 0);
prefix_tree(t);
Output: 
?(>(+(a b) c) *(z +(a b)) ?(=(a 2)) -(x y) -(y x))

Task 3

The code for this was as follows:

int main(void){
	ParseTree* t= mkNode('-', mkNode('-', mkNode('a',0),mkNode('b',0),0),0);
	ParseTree* n= 
		mkNode('?',mkNode('>',mkNode('+',mkNode('a',0),mkNode('b',0),0),mkNode('c',0),0),
		mkNode('*',mkNode('z',0),mkNode('+',mkNode('y',0),mkNode('b',0),0),
		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),0),0);
	prefix_tree(n);
	tree_to_graph(n,"new_tree_to_graph.jpg");
	return 0;
}

There was suppose to be a diagram but it too big too be put up, Here is the output anyway.

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

Task 4

Graph should be up here, but can be seen on some computers and not on some. Not sure why.

Task 5

The parse tree does not need to include the colon (:) is because of the structure on the Tree. This is only required by the compiler to separate variables, but trees the it is done implicitly.