SE250:lab-8:dsan039

From Marks Wiki
Jump to navigation Jump to search

Task Two

Getting up to this point was difficult and took the bulk of my lab time. Modifying the code and moving some functions around was costly and still don't fully understand the mk_Node function. i was able to deduce the pattern however and so my output for task 1 looked like this:

 -(-(1 2))

code:

 ParseTree* t = mkNode('-',mkNode( '-', mkNode( '1', 0 ), mkNode( '2', 0 ), 0 ),0);

<html><img src="http://img174.imageshack.us/img174/9226/treebn1.png"></html>

Task Three

ParseTree* t = 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), 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 );

this code was difficult to write in the sense that it was very easy to make a mistake which could not be found.

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

<html><img src="http://img225.imageshack.us/img225/8675/tree2wv9.png"></html>

Task Four

The tree i drew was a match to the one generated by the tree_to_graph function - i thought it was easier to make the tree than it was to code it.

Task Five

I think the semi-colon is not needed because of the way the conditional statement is read by the compiler. The '?' has 3 children, 1 being the condition to test, the other 2 being the next course of action to take if the conditional statement evaluates either true or false. Because it has to be either true or false, only one path is taken.