<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-8%3Aklod004</id>
	<title>SE250:lab-8:klod004 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-8%3Aklod004"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-8:klod004&amp;action=history"/>
	<updated>2026-08-28T02:58:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-8:klod004&amp;diff=8216&amp;oldid=prev</id>
		<title>Mark: 8 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-8:klod004&amp;diff=8216&amp;oldid=prev"/>
		<updated>2008-11-03T05:20:28Z</updated>

		<summary type="html">&lt;p&gt;8 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=== Lab 8 ===&lt;br /&gt;
This lab deals with making parse trees. There was a lot of hassle trying to get this lab to run. The error was in the error function which was supposed to be placed earlier, so there was a little cut and paste there. And the other error was a typo, &amp;quot;&amp;quot;stricmp&amp;quot;&amp;quot; was supposed to be &amp;quot;&amp;quot;strcmp&amp;quot;&amp;quot;. After I got these rectified, the lab was compiling fine. &lt;br /&gt;
&lt;br /&gt;
=== Task 1 ===&lt;br /&gt;
The code needed for this task was &lt;br /&gt;
 &lt;br /&gt;
  ParseTree* t = mkNode(&amp;#039;-&amp;#039;, mkNode(&amp;#039;-&amp;#039;, mkNode(&amp;#039;a&amp;#039;,0),mkNode(&amp;#039;b&amp;#039;,0),0),0);&lt;br /&gt;
&lt;br /&gt;
Which spits out the output needed:&lt;br /&gt;
&lt;br /&gt;
 -(-(a b))&lt;br /&gt;
&lt;br /&gt;
This was relatively simple once I figured out that the brackets are inserted automatically.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Task 2 ===&lt;br /&gt;
This task was way harder, trying to figure out where the terms go and all.&lt;br /&gt;
&lt;br /&gt;
The easiest way I could do, use to manually draw out the tree on paper. Then for the code, make a separate parse tree for each branch, then in the end, combine them all into the one main tree:&lt;br /&gt;
&lt;br /&gt;
 ParseTree* t1 = mkNode(&amp;#039;+&amp;#039;, mkNode(&amp;#039;a&amp;#039;,0),mkNode(&amp;#039;b&amp;#039;, 0),0);&lt;br /&gt;
 ParseTree* t2 = mkNode(&amp;#039;&amp;gt;&amp;#039;, t1, mkNode(&amp;#039;c&amp;#039;,0),0);&lt;br /&gt;
 ParseTree* t3 = mkNode(&amp;#039;+&amp;#039;, mkNode(&amp;#039;y&amp;#039;, 0),mkNode(&amp;#039;b&amp;#039;,0),0);&lt;br /&gt;
 ParseTree* t4 = mkNode(&amp;#039;*&amp;#039;, mkNode(&amp;#039;z&amp;#039;,0),t3,0);&lt;br /&gt;
 ParseTree* t5 = mkNode(&amp;#039;=&amp;#039;, mkNode(&amp;#039;a&amp;#039;,0),mkNode(&amp;#039;2&amp;#039;,0),0);&lt;br /&gt;
 ParseTree* t6 = mkNode(&amp;#039;-&amp;#039;, mkNode(&amp;#039;x&amp;#039;,0),mkNode(&amp;#039;y&amp;#039;,0),0);&lt;br /&gt;
 ParseTree* t7 = mkNode(&amp;#039;-&amp;#039;, mkNode(&amp;#039;y&amp;#039;,0),mkNode(&amp;#039;x&amp;#039;,0),0);&lt;br /&gt;
 ParseTree* t8 = mkNode(&amp;#039;?&amp;#039;, t5, t6, t7,0);&lt;br /&gt;
 ParseTree* t9 = mkNode(&amp;#039;?&amp;#039;,t2,t4, t8, 0);&lt;br /&gt;
 prefix_tree(t9);&lt;br /&gt;
 tree_to_graph(t9, g2);&lt;br /&gt;
&lt;br /&gt;
Output given was:&lt;br /&gt;
&lt;br /&gt;
 ?(&amp;gt;(+(a b) c) *(z +(y b)) ?(=(a 2) -(x y) -(y x)))&lt;br /&gt;
&lt;br /&gt;
This is as far as I was able to reach in the lab, might go home and do more later.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>