SE250:lab-8:hals016
Jump to navigation
Jump to search
Lab 8 I used the parsetree.c source file.
Task 2
Code
int main() { //ParseTree* t = mkNode( '-', mkNode( '+',0), mkNode( 'a',0 ), mkNode( 'b',0 ), mkNode('b', mkNode('n', 0),0), 0); ParseTree* t = mkNode( '-', mkNode( '-', mkNode( 'a',0 ), mkNode( 'b',0 ),0),0); prefix_tree(t); printf("\n"); postfix_tree(t); printf("\n"); tree_to_graph(t, "graph.jpg"); return 0; }
pre -(-(a b)) post a b - -
Task 3
Code (I am asking for trouble ...)
int main() { 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('x',0),mkNode('y',0),0),0),0); prefix_tree(t); printf("\n"); postfix_tree(t); printf("\n"); tree_to_graph(t, "graph2.jpg"); return 0; }
pre ?(>(+(a b) c) *(z +(y b)) ?(=(a 2) -(x y) -(x y))) post a b + c > z y b + * a 2 = x y - x y - ? ?