<?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-9%3Asdal039</id>
	<title>SE250:lab-9:sdal039 - 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-9%3Asdal039"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-9:sdal039&amp;action=history"/>
	<updated>2026-04-28T18:48:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-9:sdal039&amp;diff=8727&amp;oldid=prev</id>
		<title>Mark: 9 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-9:sdal039&amp;diff=8727&amp;oldid=prev"/>
		<updated>2008-11-03T05:20:39Z</updated>

		<summary type="html">&lt;p&gt;9 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;comiler...&lt;br /&gt;
ok so we need a different function (perhaps) for each thing we want to do. Load idents, strings, perform operations, evaluate statements.&lt;br /&gt;
&lt;br /&gt;
and now there&amp;#039;s a whole heap of undefined references&lt;br /&gt;
 cygdrive/c/Users/sdal039/AppData/Local/Temp/ccDd1mQd.o:parser.c:(.text+0x202): undefined reference  to `_end_of_tokens&amp;#039;&lt;br /&gt;
 /cygdrive/c/Users/sdal039/AppData/Local/Temp/ccDd1mQd.o:parser.c:(.text+0x212): undefined reference to `_error&amp;#039;&lt;br /&gt;
 /cygdrive/c/Users/sdal039/AppData/Local/Temp/ccDd1mQd.o:parser.c:(.text+0x240): undefined reference to `_current&amp;#039;&lt;br /&gt;
 /cygdrive/c/Users/sdal039/AppData/Local/Temp/ccDd1mQd.o:parser.c:(.text+0x2a6): undefined reference to `_advance&amp;#039;&lt;br /&gt;
&lt;br /&gt;
and so on...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
aha.. toy tokeniser is up now. errors gone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ok this is stupidly hard :P&lt;br /&gt;
code so far: &lt;br /&gt;
 static int strCount = 0;&lt;br /&gt;
 void identifiers( Tree* pTree )&lt;br /&gt;
  {&lt;br /&gt;
       if (pTree != 0) {&lt;br /&gt;
 	  if (isVariable( pTree-&amp;gt;name )) {    //variable assignment&lt;br /&gt;
 	      printf(&amp;quot;.globl %c\n\t%c .long 0\n&amp;quot;, pTree-&amp;gt;name, pTree-&amp;gt;name );&lt;br /&gt;
 	  }&lt;br /&gt;
 &lt;br /&gt;
 	  if (isConstant( pTree-&amp;gt;name )) {   //string assignment&lt;br /&gt;
 	      printf(&amp;quot;S%d:\n\t.ascii \&amp;quot;%c\&amp;quot;\n&amp;quot;, strCount, pTree-&amp;gt;name);&lt;br /&gt;
 	      strCount++;&lt;br /&gt;
 	  }&lt;br /&gt;
      }&lt;br /&gt;
 &lt;br /&gt;
      int i;&lt;br /&gt;
      for (i = 0; i &amp;lt; pTree-&amp;gt;arity ; i++)&lt;br /&gt;
 	  identifiers( pTree-&amp;gt;arg[i] );&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Well it does do something..&lt;br /&gt;
given the token stream &amp;#039;a=1&amp;#039; it outputs&lt;br /&gt;
 .globl a&lt;br /&gt;
 	a .long 0&lt;br /&gt;
 S0:&lt;br /&gt;
 	.ascii &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
adding two numbers... &lt;br /&gt;
 Tree* compile(Tree* t) &lt;br /&gt;
 {&lt;br /&gt;
    if (t != 0) {&lt;br /&gt;
 	if (eqToken( t-&amp;gt;name, TOK_ADD )) {//addition&lt;br /&gt;
 		Tree* left = compile( t-&amp;gt;arg[0] );//get first opperand&lt;br /&gt;
 		Tree* right = compile( t-&amp;gt;arg[1] );//get second opperand&lt;br /&gt;
 		printf(&amp;quot;pop\%%c\npop\%%c\nadd \%%c, \%%c\npush\%%c&amp;quot;, left-&amp;gt;name, right-&amp;gt;name,  right-&amp;gt;name, left-&amp;gt;name, left-&amp;gt;name);&lt;br /&gt;
 	    }&lt;br /&gt;
    }&lt;br /&gt;
 	return t;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
segmentation fault...yaaaayyyy.&lt;br /&gt;
&amp;gt;_&amp;lt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What makes this task hard is that without proper implementations of the tokeniser and parse tree it&amp;#039;s really hard to write. toy-tokeniser doesn&amp;#039;t really allow you to test things, similarly with the parse tree. for example, it can&amp;#039;t easily differentiate between a variable &amp;#039;i&amp;#039; and and if statement as it tokenises ifs to just &amp;#039;i&amp;#039;. Can&amp;#039;t represent quoted strings either as each token is simply 1 character.&lt;br /&gt;
&lt;br /&gt;
Mark suggested doing these three tasks (or at least the first two) over two/three separate labs, in the order than they are used. this would make it easier at each stage and at the end we&amp;#039;d have a pretty solid parser with everyone working on one bit at a time.&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>