SE250:lab-8:sgha014

From Marks Wiki
Jump to navigation Jump to search

TASK 2

i first tried it out using the example they gave in the pdf. i just copied from their and it wasnt working. Then i got told that the ' is differnt in the pdf so i had to go through and change the ' and then it worked. So then i did the actual task

int main(void){
	ParseTree* t = mkNode( '-', mkNode( '-', 0 ), mkNode( 'a', 0 ), mkNode('b', 0), 0 );
	 prefix_tree(t);
	 return 0;
}

i used the cygwin to compile and run coz visual studio seems to never work anymore.

$ gcc parsetree.c -o parsetree && ./parsetree.exe
-(- a b)

for some reason tree-to-graph doesnt work.

someone posted some help on the wiki of how to make tree-to-graph work so i managed to get a picture of my tree :D

TASK 4

i did task 4 before task 3. i drew what i expected the tree to look like, then did task three.

TASK 3

it took a while to figure out how to do it in subtrees and then combine them, but i got there in the end. i drew one subtree and checkd it and then did the other and so on. Then combined them into 1 big tree.

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

	 return 0;
}

heres the tree i got: tree

TASK 5

cond ? e1 : e2.

this means that if the condiition is true, do e1, else do e2. so i dont relly understand why the tree doesnt have the : in it.