SE250:lab-8:apra102

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

Task 2

Hmmm first i downloaded the wrong code and struggled for some time. After I realized and get the actual one i tried creating the new function and running it but then it came up with so many errors. I showed my errors to the tutor she said that the error function code should be before the expect function. And the other one is to delete the i from strcimp. Finally it worked. When i used Visual Studio by creating my main construct,it did not work in the Visual Studio then i used Cygwin Drive it worked. My main function is as follows.

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

Output:

-(-(a b))

Task 3

First thing to know in this task is to know what is ? means? That is ternary node. Means which has 3 nodes. I drew the tree in my book first. I felt a bit hard to figure out that we should go from end. Once i figure out how the first part i felt little comfort and then i continued to code. First i coded for small part ?(>(+(a b) c) same way i coded for *(z +(y b)) then i combined both of them. By breaking the whole thing in to parts and combining them finally is easy than trying to code for the whole thing. code i made is:

int main(void){
	ParseTree* t= mkNode('-', mkNode('-', mkNode('a',0),mkNode('b',0),0),0);
	ParseTree* n= 
		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),
		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),0);
	prefix_tree(n);
	tree_to_graph(n,"new_tree_to_graph.jpg");
	return 0;
}

Out put: Which I got

?(>(+(a b) c) *(z +(y b) ? (=(a 2) -(x y) -(y x))))

It suppose it be

?(>(+(a b) c) *(z +(y b)) ?(=(a 2) -(x y) -(y x)))

I have no idea why there is an extra bracket. I dont know where should change my code to get that correct. I came up to here. But the out put of this code is not the one which it suppose to be. I worked on it for a long time but could not figure it out. Will be happy if some one help me knowing what is wrong with the code.


ParsingTree

Yay... Later when i worked on that i just chalged them around and it works. Present code is

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

Out Put:

?(>(+(a b) c) *(z +(y b)) ?(=(a 2) -(x y) -(y x)))

NewParsingTree

Task 4

I drew the tree before coding.