SE250:lab-8:aomr001

From Marks Wiki
Jump to navigation Jump to search

at the start i was really stuck trying to compile the code .. as it had some unexpected errors .. i had to ask the tutor who told me to move the function "error" higher up on the code .. and change the function name "strcmip" to strcmp which fixed the compilation problems ..


task2

we were asked to write a mkNode function for the expression -(-(a b )) i have done that using the code :

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

the output was:

-(-(a b)) 


task3

we were asked to make an expression ?(>(+(a b) c) *(z +(y b)) ?(=(a 2) -(x y) -(y x)))

code:

ParseTree* branch1 = mkNode('>',mkNode('+',mkNode('a',0),mkNode('b',0),0),mkNode('c',0),0) ;
    ParseTree* branch2 = mkNode('*',mkNode('z',0),mkNode('+',mkNode('y',0),mkNode('b',0),0),0); ;
    ParseTree* branch3 = 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* final = mkNode('?',branch1,branch2,branch3) ;

    prefix_tree(final);


output:

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


task4

we were then asked to draw the tree .. then graph it and compare between the 2 .. in my case .. my expectations on the shape of the parse tree ., was the same as the graph given when using tree_to_graph function

<html> <img src="http://aamranovich.googlepages.com/graphictask1.jpg"> </html>


task5

the colon ":" is used in C to distinguish and separate different conditions.. the parse tree doesn't need to use that because the different conditions are in different branches of the parse tree.