SE250:lab-8:sshi080

From Marks Wiki
Jump to navigation Jump to search

Lab 8

Task 1

Downloading the code was simple enough :)

Task 2

Took me like 30 minutes just to get the freakin thing to compile, first of all the error function didn't work because it was declared AFTER expect() tries to call it. Also got an error from "strcimp", I googled it and it clearly was a typo, I didn't think there was a strcimp function in the library ~_~.

Here is the code:

ParseTree* t = mkNode('-', mkNode('-', mkNode('a', 0), mkNode('b', 0), 0), 0);
prefix_tree(t);

Output:

-(-(a b))

Graph:
<html> <img src="http://orlybird.com/SE250/graph1.png"></html>

Task 3

This task isn't hard if you split the expression into subgroups. It confused the hell out of me when I didn't split the expression into groups, I first ended up with this looooong line which totally buzzed me out, then I split the expression into subgroups and got the thing.

Code:

ParseTree* greaterthan = mkNode('>', mkNode('+', mkNode('a', 0), mkNode('b', 0), 0), mkNode('c', 0), 0);
ParseTree* multiply = mkNode('*', mkNode('z', 0), mkNode('+', mkNode('y', 0), mkNode('b', 0), 0), 0);
ParseTree* equals = mkNode('=', mkNode('a', 0), mkNode('2', 0), 0);
ParseTree* minus1 = mkNode('-', mkNode('x', 0), mkNode('y', 0), 0);
ParseTree* minus2 = mkNode('-', mkNode('y', 0), mkNode('x', 0), 0);
ParseTree* question2 = mkNode('?', equals, minus1, minus2, 0);
ParseTree* full = mkNode('?', greaterthan, multiply, question2, 0);

prefix_tree(full);

Graph:
<html> <img src="http://orlybird.com/SE250/graph2.png"></html>