SE250:lab-8:stsa027

From Marks Wiki
Jump to navigation Jump to search

Got struggled a bit to get going. Had to fiddle with the 'parsetree.c' file before the class manage to get it to work.

Task One

Download done...


Task Two

Wrote main function, and done inside that. First tried to make a mkNode('a b',0) which didn't work. Got the required result using this:

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


Task Three

Not hard conceptually, but just a pain to write... I did it in chunks, printing as I go, so I can't go too badly wrong before I notice...

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);


Task Four

Drew the tree wrong the first time. Very wrong. Had a quick glance, saw that it was wrong, and tried again. Got it right the second time. The reason I got it wrong the first time was that I didn't do it methodically enough... just ... guessed, I guess.


Task Five

Got told what the tree in task 3 actually means. That the first tree represents the condition. If the condition is true, then the first branch is executed. If false, then the second branch is executed. That is why the colon is not required.


Task Six

Tried... don't know how to do it. result = tree->arg[0]->name + tree->arg[1]->name;