SE250:lab-8:rbha033
Lab 8
The Error() function needs to be put above the Exclude() function to get rid of an error. not sure why.
Task 2
Output required:
gcc parsetree.c -o parsetree && parsetree.exe -(-(a b))
To get this output I looked at the code from our brief:
ParseTree* t = mkNode( ’+’, mkNode( ’1’, 0 ), mkNode( ’2’, 0 ), 0 ); +(1 2)
I then changed it to the following to get our required output:
ParseTree* t = mkNode( '-', mkNode( '-',mkNode( 'a',0 ),mkNode('b',0), 0),0 )
Now to using tree_to_graph(), here's the final code:
int main(){ ParseTree* t = mkNode( '-', mkNode( '-',mkNode( 'a',0 ),mkNode('b',0), 0),0 ); prefix_tree(t); tree_to_graph(t, "1.jpg"); return 0; }
Output is:
gcc parsetree.c -o parsetree && parsetree.exe -(-(a b)) Compilation finished at Tue May 20 11:32:34
And this is the image produced:
<html> <img src ="http://geocities.com/racbhat13/Lab8-task2.jpg"></html>
Task 3 & 4
Holy ****, damn this is long. Neway getting to work now.
Ok after 30 minutes of working and re-working with trial and error, i finally got the code:
int Task3(){ ParseTree* t2 = 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); prefix_tree(t2); return 0; }
Here's the Output:
gcc parsetree.c -o parsetree && parsetree.exe ?(>(+(a b) c) *(z +(y b)) ?(=(a 2) -(x y) -(y x))) Compilation finished at Tue May 20 12:33:25
This was mind-boggling enough, couldn't figure out the diagram, but here's the image: <html><img src = "http://www.geocities.com/racbhat13/lab8-task4.jpg"></html>
Task 5
Huh?!!!