SE250:lab-8:srag014

From Marks Wiki
Revision as of 05:20, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (1 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Lab 8

Lab 8 is all about parse trees.

Task 1

The first task was just to download the parsetree.c file...Quite an easy task!

Task 2

The second task was to cnstruct an expression (calling mkNode) that, when passed to prefix tree, produces the output. This task was not too bad, but it took me a while to figure out that the file had some errors in it which I fixed eventually.


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


Used the visual studio compiler

cl parsetree.c

then

parsetree.exe

whcih gives the desire output!

-(-(a b))

Graph was obtained by using the command:

  tree_to_graph( t, "output.dot" );

Had to use output.dot since I used da Visual studio compiler then I had to enter that output in graphviz!


Task 3

The third task was to construct a given expression.This task was a struggle, it took a while because I kept getting confused had to get some help....got there in the end though.

 int main() {
ParseTree* t3 = 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(t3);
				tree_to_graph( t3, "output3.dot" );
			return 0;
 }

Task 4

The fourth task was just to get the graph from task 3. Note:Graph to come soon

Task 5

Not sure...tried googling it but to no avail.