SE250:lab-8:mabd065

From Marks Wiki
Jump to navigation Jump to search

The first problem was compiling the paresetree.c file. After fixing the problem (by the tutor's help), i was able to compile and run the code.

Task 2

Following the example given in the PDF, i came up with this code:

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

and the output image is:

<HTML> <img src="http://img90.imageshack.us/img90/6213/qtwoxm7.jpg"> </HTML>


Task 3

code :

int main () {
    char* filename = "qThree.jpg";

    ParseTree* q = mkNode('=',mkNode('a',0),mkNode('z',0),0);
    ParseTree* r = mkNode('-',mkNode('x',0),mkNode('y',0),0);
    ParseTree* s = mkNode('-',mkNode('y',0),mkNode('x',0),0);

    ParseTree* k = mkNode('+',mkNode('a',0),mkNode('b',0),0);
    ParseTree* n = mkNode('+',mkNode('y',0),mkNode('b',0),0);

    ParseTree* m = mkNode('>',k,mkNode('c',0),0);
    ParseTree* o = mkNode('*',mkNode('z',0),n,0);
    ParseTree* p = mkNode('?',q,r,s,0);

    ParseTree* ultimate = mkNode('?',m,o,p,0);

    prefix_tree(ultimate);
    tree_to_graph(ultimate, filename);
    return 0;
}


Task 4

I have drawn the graph and then used tree_to_graph and they give the same result!

<HTML> <img src="http://img90.imageshack.us/img90/4479/qthreefb0.jpg"> </HTML>

Task 5

Because we are using a ternary node. ('m', 'o' and '?')

First, if 'm' evaluates to true, 'o' is excuted. Otherwise, we go to the '?' node and we do what we did again excuting the most left branch, if it is true, we excute the second left one. Other wise, the right most on is excuted (all relative to the second '?' node).