<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RedBrain @ $HOME : ~ $ &#187; tutorial</title>
	<atom:link href="http://redbrain.co.uk/index.php/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://redbrain.co.uk</link>
	<description>Frustrated Software Developer</description>
	<lastBuildDate>Sat, 19 May 2012 00:58:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Crules and Intermediate Representation</title>
		<link>http://redbrain.co.uk/index.php/quick-tips/crules-and-intermediate-representation/</link>
		<comments>http://redbrain.co.uk/index.php/quick-tips/crules-and-intermediate-representation/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 02:47:00 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[Compilers]]></category>
		<category><![CDATA[Crules]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Update!]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=491</guid>
		<description><![CDATA[<p>If you follow my blog you may have noticed i have been quiet and thats because i&#8217;ve been working on http://crules.org Its the new homepage for my project Crules, its got some good content on it but nothing really on the language yet. Though today i spend a very long time on the HACKING article [...]]]></description>
			<content:encoded><![CDATA[<p>If you follow my blog you may have noticed i have been quiet and thats because i&#8217;ve been working on <a href="http://crules.org">http://crules.org</a> Its the new homepage for my project Crules, its got some good content on it but nothing really on the language yet. Though today i spend a very long time on the<a href="http://crules.org/doku.php?id=hacking"> HACKING</a> article And i explain a lot on how Intermediate Representation&#8217;s work and <a href="http://en.wikipedia.org/wiki/Three_address_code">3-address code</a>.</p>
<p>So lets just take an extract since i am lazy: So in compilers or interpreters how do we represent:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#40;</span><span class="br0">&#40;</span> x + y <span class="br0">&#41;</span> -- <span class="br0">&#40;</span> <span class="br0">&#40;</span> x + y <span class="br0">&#41;</span> * <span class="br0">&#40;</span> x -- y <span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span> + <span class="br0">&#40;</span> <span class="br0">&#40;</span> x + y <span class="br0">&#41;</span> * <span class="br0">&#40;</span> x -- y <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>Lets see it in a diagram first then in IR code:</p>
<div class="wp-caption alignleft" style="width: 281px"><a href="http://farm3.static.flickr.com/2718/4153843445_7f33be00d2.jpg"><img title="Expression DAG" src="http://farm3.static.flickr.com/2718/4153843445_7f33be00d2.jpg" alt="Expression" width="271" height="202" /></a><p class="wp-caption-text">Expression</p></div>
<p>So what is this? Well early on when i was getting into compiler construction when doing semantic analysis you will need to find a way of representing these semantics for your language, and you will find generally that there are 3 things you need to know: <strong>DESTINATION OPERAND A and OPERAND B</strong>. This is what&#8217;s called <a title="http://en.wikipedia.org/wiki/Three_address_code" rel="nofollow" href="http://en.wikipedia.org/wiki/Three_address_code">3-address code</a>. This is what sets compilers apart and can make or break them! Its what gives implementations flexibility and the ability to &#8216;<strong>control the flow</strong>&#8216; of execution! Any good compiler book will give you more detailed discussion on this topic its my main interest in compilers since this is what gives an implementation its logic. So lets give it a syntax we can write down to illustrate how mine works: it just so happens a <a title="http://en.wikipedia.org /wiki/Lisp_%28programming_language%29" rel="nofollow" href="http://en.wikipedia.org%20/wiki/Lisp_%28programming_language%29">LISP</a> &#8216;ish syntax can show this very well!</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#40;</span> <span class="br0">&#40;</span> IDENTIFIER <span class="br0">&#40;</span> TYPE <span class="br0">&#41;</span> <span class="br0">&#41;</span> =&gt; <span class="br0">&#40;</span> OPERAND A <span class="br0">&#41;</span> =&gt; <span class="br0">&#40;</span> OPERAND B <span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="co1">;</span></div>
</li>
</ol>
</div>
<p>Since the parser is precedence aware it will construct the tree as shown in a symbol language which looks like this if it was output ( outputting the IR like this is a future TODO ); It may look a little like <a title="http://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html" rel="nofollow" href="http://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html">GIMPLE</a> but this IR I have as I will demonstrate more examples can encompass much much more..  ( this is a 3-address code by the way )</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_ADD <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_SUBTRACT <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_ADD <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span> <span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_MULTIPLY <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_ADD <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_SUBTRACT <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_MULTIPLY <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_ADD <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> OP_SUBTRACT <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;x&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#40;</span> SYMBOL_ACCESS <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> &#8216;y&#8217; <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; =&gt; <span class="br0">&#40;</span> <span class="kw1">NIL</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#41;</span><span class="co1">; )</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span><span class="co1">;</span></div>
</li>
</ol>
</div>
<div class="wp-caption alignright" style="width: 280px"><a href="http://icanhascheezburger.files.wordpress.com/2009/11/funny-pictures-cat-will-unroll-all-toilet-paper.jpg"><img title="Busy catz" src="http://icanhascheezburger.files.wordpress.com/2009/11/funny-pictures-cat-will-unroll-all-toilet-paper.jpg" alt="busy!" width="270" height="201" /></a><p class="wp-caption-text">busy!</p></div>
<p>Though one big note its is ok for me to leave the representation like this since in my interpreter i just evaluate this at run time but how does this affect things like code-generators like proper Compilers? Well its quite simple in a sane compiler like GCC ( although most compilers will follow this idiom i am sure) introduce another layer for IR called RTL ( <a href="http://en.wikipedia.org/wiki/Register_transfer_language">Register Transfer Language</a> ). The wikipedia article lacks and most compiler books overlook this section very much since, most books are written by the academics and generally stay away from the <a href="http://en.wikipedia.org/wiki/Compiler#Back_end">back-end of compilers</a> since that is the actual hard part since a code-gen is very specific to the instruction set your targeting and register allocation algorithms are very difficult and is a huge research project.  Its said in computer science the most difficult things to build software wise is a good JIT or any Code-Generator for that matter.  Anyways back to the problem lets take a smaller expression for sleep&#8217;s sake the expression:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">unsigned</span> <span class="kw4">int</span> retval = <span class="br0">&#40;</span> x * <span class="nu0">2</span> <span class="br0">&#41;</span> / <span class="br0">&#40;</span> <span class="nu0">7</span> + y <span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Will generate something like:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">t1 = x * <span class="nu0">2</span>;</div>
</li>
<li class="li1">
<div class="de1">t2 = <span class="nu0">7</span> + y;</div>
</li>
<li class="li1">
<div class="de1">t3 = t1 / t2;</div>
</li>
<li class="li2">
<div class="de2">retval = t3;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Anyways you&#8217;ll notice in my the IR keywords such as SYMBOL_ACCESS or SYMBOL_ITEM or OP_ADD etc, these are what&#8217;s called OP_Codes and are generally represented by some symbolic hex values since its cheap to check against for the implementation to figure out what to do with symbol &#8216;x&#8217;; So ok thats a quick and dirty intro to Intermediate Representation&#8217;s!</p>
<p>I think this lolcat will sum up your feelings at the end of reading this blog post:</p>
<p>And i started getting out my old grunge cd&#8217;s which include my <a href="http://www.last.fm/music/Silverchair">Silverchair</a> collection and this is on of my favourite bands of all time and this is a pretty good song!</p>
<p><!-- Smart Youtube --><span class="youtube"><object width="425" height="373"><param name="movie" value="http://www.youtube.com/v/fTM5cDIESrY&amp;rel=1&amp;color1=3a3a3a&amp;color2=999999&amp;border=1&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="http://www.youtube.com/v/fTM5cDIESrY&amp;rel=1&amp;color1=3a3a3a&amp;color2=999999&amp;border=1&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="373" ></embed><param name="wmode" value="transparent" /></object></span></p>
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/quick-tips/crules-and-intermediate-representation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update &#8211; Interpreter CRULES &amp; Jamedo</title>
		<link>http://redbrain.co.uk/index.php/update/update-interpreter-crules-jamedo/</link>
		<comments>http://redbrain.co.uk/index.php/update/update-interpreter-crules-jamedo/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 23:51:42 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[Crules]]></category>
		<category><![CDATA[Update!]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[BLUG]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=400</guid>
		<description><![CDATA[<p></p>
<p style="margin-bottom: 0cm;" align="justify">So hey, its been a little longer than i intended to update my blog! But i&#8217;ve been busy, so i have got rid of my personal work being on repositories all over the show. So I have made:</p>

http://code.redbrain.co.uk

<p style="margin-bottom: 0cm;" align="justify">There will be public git access soon, but you can download the [...]]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } 		A:link { so-language: zxx } --></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So hey, its been a little longer than i intended to update my blog! But i&#8217;ve been busy, so i have got rid of my personal work being on repositories all over the show. So I have made:</span></p>
<ul>
<li><span style="font-family: Arial,sans-serif;"><a href="http://code.redbrain.co.uk/">http://code.redbrain.co.uk</a></span></li>
</ul>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">There will be public git access soon, but you can download the snapshot tarballs of the branches. And I have a wiki too there isn&#8217;t anything on there yet but it will give me room to stop putting long tutorial article&#8217;s as pages on my blog to proper wiki article&#8217;s:</span></p>
<ul>
<li><span style="font-family: Arial,sans-serif;"><a href="http://wiki.redbrain.co.uk/">http://wiki.redbrain.co.uk</a></span></li>
</ul>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } 		A:link { so-language: zxx } --></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So Compilers, Interpreters and programming languages are my interests&#8230; *yawn! So let me show you my interpreter pipeline for my interpreted language &#8216;CRULES&#8217;: </span></p>
<div id="attachment_401" class="wp-caption alignleft" style="width: 310px"><a rel="attachment wp-att-401" href="http://redbrain.co.uk/?attachment_id=401"><img class="size-medium wp-image-401" title="Crules-arch-diagram" src="http://redbrain.co.uk/wp-content/uploads/2009/07/Crules-arch-diagram-300x253.png" alt="Crules" width="300" height="253" /></a><p class="wp-caption-text">Crules</p></div>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So I have to admit that&#8217;s the most impressive art I ever done (I know I&#8217;m lame <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ). Its my pipeline for my programming language, but I guess a lot of programming languages would follow this kind of model/architecture. So it got me thinking this is nearly the basics for any semi-serious interpreter or &#8216;a&#8217; language so lets talk though it. </span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">I am still not going to talk about the details of my language because its not ready yet. Other than I am doing fun things like, so far the only data-structure I let the developer have is lists, so if you do something like:</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<blockquote>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">% foo := { 2,3,4,5,6,67,7}</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">#is a list and strings are lists!</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">% str := “bla”</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">#is the same as</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">% str := { &#8216;b&#8217;, &#8216;l&#8217;, &#8216;a&#8217; }</span></p>
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">It works a lot around the shell so you can also do:</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">% foo := `ls`</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">#it produces a delimited list of strings with the delimited as carriage return or new line etc.</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p></blockquote>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">Though note I am going to implement an api for arrays. But not yet, because lists are going to cause problems unless I implemented a table/array of accessors to the elements in the list so you can do fast access to the elements because it doesn&#8217;t scale no matter what anyone says when say you are doing image processing on a 1024&#215;1024 list&#8230; accessing the elements isn&#8217;t going to scale.</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">Anyway so lets get back to looking into the pipeline of it: So first a user creates a program lets look at the helloworld.crl:</span></p>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></p>
<blockquote>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">rule main()</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">{</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"> echo “Hello World!”</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"> foo := 5 + 2 &#8211; 7</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">}</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">all := main;</span></p>
</blockquote>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So first my interpreter will start lexing this using LEX, into tokens like: rule, main &#8216;(&#8216; &#8216;)&#8217;&#8230;. and then the parser starts applying the grammar implemented using YACC. So I start producing symbols to build a symbol table the data-structure looks like this its basicly a more high-level 3 address code:</span></p>
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify">
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> symtab <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">const</span> <span class="kw4">char</span> *identifier;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; uint8_t symType;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; uint8_t op_a_t;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; uint8_t op_b_t;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">union</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; _SYM_LIST_ *list;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">float</span> flt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; int32_t integer;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">char</span> ch;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//sym link to function call</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">struct</span> symtab *syms;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span> op_a;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">union</span> <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; _SYM_LIST_ *list;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">float</span> flt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; int32_t integer;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//params to a func_call</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">struct</span> symstack *syms;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">struct</span> symtab *sy;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span> op_b;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">struct</span> symtab *next;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> __attribute__<span class="br0">&#40;</span><span class="br0">&#40;</span>aligned<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify">
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></p>
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So first it creates the rule definition! For now just think as rules as entry points to a program so you can add more identifiers to that &#8216;all&#8217; list not just main. It has a deeper meaning but I don&#8217;t want to talk or show this until I have the interpreter and language definitions more concrete!</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So the the rule &#8216;main&#8217; creates a new symbol like this:</span></p>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></p>
<blockquote>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">//the symbol takes the identifer of the rule identifier</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">symbol-&gt;identifer = &#8216;main&#8217;</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">//its a rule symbol</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">symbol-&gt;symType= _SYM _RULE _</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">symbol union_a is the link to the first symbol in that block of statements and union_b is NULL because I don&#8217;t need it until I have rule dependencies it needs to list.</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">symbol-&gt;next= NULL, because it is just a definition</span></p>
</blockquote>
<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } --></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">Then each expression like &#8216; echo “Hello World” &#8216;, creates a symbol and its next = the next expression like the &#8216; foo := 5 + 2 – 7 &#8216;. This creates an interesting one, because this can&#8217;t be reduced to a 3-address code until you split it up, for now I just assume the developer wants it to run as 5+2=7 then 7-7=0; But I am going to add precedence later. So you can be more expressive to have nested expressions in brackets to be executed first etc..</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">But yeah this expression is split up into 3 symbols for now, its an over all variable Assignment but it depends an expression of 5+2 as a temporary symbol then this temporary symbol – 7 then foo = this new temporary symbol and I can push these dead symbols to the garbage collector. </span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">When a symbol is allocated, it is allocated memory of a preallocated memory heap of default 32MB, it can be extended or shortened if needs be, but it allows me to control and see how much memory is being occupied at anyone time in the runtime of the interpreter. Any symbols to be kept such as rule definitions, function definitions or variables are kept on one massive stack. So ok, that&#8217;s a problem if you need to search for them, the answer I found was having 3 other tables that link to the symbols in the stack. When any link is broke it becomes garbage, so when I have a new variable re-assignment I can break that link and remove the entry in the variable table it still exists in the symbol stack but the <a href="http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)">Garbage collector</a> is always called on EXIT and the exit of any block statements like loops functions etc, so when you pop your way out of the stack you can have local variables instead of everything global and you have conflicts which will cause a lot of problems. Also the garbage collector is implemented as a <a href="http://en.wikipedia.org/wiki/POSIX_Threads">pthread</a> so you have have to pause for several seconds waiting for it to free the garbage. I haven&#8217;t done this yet because its going to be very awkward to keep the concurrency, the pthread mutex api should handle a lot for me but its still going to be complicated. I have thought I might like to try implementing a lot of different internal using OPEN/MP to make it even speedier, but that won&#8217;t be for a while.</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">And then I have been playing with<a href="http://llvm.org/"> LLVM</a> to create a <a href="http://llvm.org/docs/tutorial/index.html">JIT execution system</a>, you can see my posts on &#8216;Managing the JIT&#8217; on comp.compilers, I have posted there quite a few times before, its a great list of basically all programming language, compiler and interpreter experts in the world!</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So I have a variable table that links to the variables in the symbol stack and the same for the rules and functions. This speed up searching for specific identifiers.</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So that&#8217;s the basics of parsing into symbols I guess, it pains me to say but many people thing a programming language is mainly a parser is so wrong the parser just lets you build your symbols the execution and management of these symbols is much, much more complicated. That&#8217;s not to say implementing a simple programming language is difficult, the problem I see a lot is people are scared of doing it because the vocabulary is huge! I mean if you start working at an interpreter from first principle&#8217;s I&#8217;ll guarantee if you have half a brain you&#8217;ll come to a similar architecture as this. </span></p>
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">I found it difficult at the start when I knew anything in a programming language can always be brought to 3 things and I got really confused when people talked about symbol tables, 3 address code, IR (intermediate representation) and parse trees or syntax tree&#8217;s. I think a lot of developers have their own prefered meanings to them, but it is mainly a barrier of academics trying to make the subject more complicated than needs be, although when you go at this from first principle&#8217;s you&#8217;ll will soon learn <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</span></p>
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">So thats the main focus of my personal work but I am now also soon to be an approved <a href="http://gcc.gnu.org/">GNU/gcc</a> and <a href="http://www.gnu.org/software/automake/">GNU/automake</a> developer! Can&#8217;t wait, got my FSF paper work signed and sent back it may arrive in Boston soon I guess but yeah I am excited. I am updating the automake documentation to show the best way to handle multiple <a href="http://en.wikipedia.org/wiki/Lex_programming_tool">LEX</a> and <a href="http://en.wikipedia.org/wiki/Yacc">YACC</a> in one program. Its something only one of two people do but its a problem none the less and to make it portable is the actual problem. But I have the solutions to it now <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify">
<div class="wp-caption alignright" style="width: 262px"><a href="http://icanhascheezburger.files.wordpress.com/2009/07/funny-pictures-cat-has-pushed-in-face.jpg"><img title="Got your attention" src="http://icanhascheezburger.files.wordpress.com/2009/07/funny-pictures-cat-has-pushed-in-face.jpg" alt="Got your attention" width="252" height="188" /></a><p class="wp-caption-text">Got your attention</p></div>
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">Thing is I would really love it if I had an AIX/FreeBSD/Solaris machine to do more testing on because now that I am doing work on GCC it would be so helpful to have more machines to do testing. But i&#8217;m ok for now, so far in GCC I am doing regression testing to find a regression I can tackle, its extremely difficult some are defunct on the <a href="http://gcc.gnu.org/bugzilla/">bugzilla</a> some are ancient and not perused. And the rest is very active but for MIPS or SPARC, and I don&#8217;t have a <a href="http://www.scratchbox.org/">scratchbox</a> setup to even test that yet. Would just be great to get my hands on even an old ibook for a power-pc cpu or an old IBM p-server. If anyone knows of any available I would be really grateful!<br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<p style="margin-bottom: 0cm;" align="justify">
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;">Ok this has become a very long post so I&#8217;ll shut up! <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> . See you guys from <a href="http://www.belfastlinux.org/wiki/Main_Page">Beflast LUG</a> on Wednesday!</span><span style="font-family: Arial,sans-serif;"> One last thing i want to link you to 5 of my favourite bands and they are all off <a href="http://www.jamendo.com/en/">Jamendo</a>:</span></p>
<p style="margin-bottom: 0cm;" align="justify"><span style="font-family: Arial,sans-serif;"><br />
</span></p>
<ul>
<li><a href="http://www.jamendo.com/en/album/26656">http://www.jamendo.com/en/album/26656</a></li>
<li><a href="http://www.jamendo.com/en/album/34523">http://www.jamendo.com/en/album/34523</a></li>
<li><a href="http://www.jamendo.com/en/album/42122">http://www.jamendo.com/en/album/42122</a></li>
<li><a href="http://www.jamendo.com/en/album/34714">http://www.jamendo.com/en/album/34714</a></li>
<li><a href="http://www.jamendo.com/en/album/3661">http://www.jamendo.com/en/album/3661</a></li>
</ul>
<pre><span><span> </span></span></pre>
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/update/update-interpreter-crules-jamedo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tutorials and Pages on the go!</title>
		<link>http://redbrain.co.uk/index.php/about-me/tutorials-and-pages-on-the-go/</link>
		<comments>http://redbrain.co.uk/index.php/about-me/tutorials-and-pages-on-the-go/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 10:57:34 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[About Me]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Update!]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=270</guid>
		<description><![CDATA[<p>So i have been spending the last few days and nights trying to make an awesome tutorial on writing a c/c++ application with autoconf and automake + libtool, creating a library out of it with relevant headers and swig python bindings and then all the way to packaging to a PPA on launchpad which will [...]]]></description>
			<content:encoded><![CDATA[<p>So i have been spending the last few days and nights trying to make an awesome tutorial on writing a c/c++ application with autoconf and automake + libtool, creating a library out of it with relevant headers and swig python bindings and then all the way to packaging to a PPA on launchpad which will be debs no rpms here no idea how to make those!</p>
<p>So as you can see there is alot there!  So good wordpress is saving my stuff. When i am writing my tutorials now and articles i am starting to write them in OpenOffice first to make it much more professional of me. Posts are still quite spontaneous on me <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But i think for my pages etc.. it all has to take its time and be done right. On a plus things are going good now no more ranting from me anymores <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So yeah i am going to post updates of my OS work soon i am going to take it of gitorious probably because its too awkward to keep update because i spend so much time on launchpad now because of drizzle trying to merge my changes with the trunk there are a few problems but its because my tree was pretty old. And there was a good few autoconf updates since then for the project like more depandancies etc. So yeah i am working on it somtimes but drizzle is a little more important to me because it looks better on me i guess. But stay tunned and i will keep you up todate and more tutorials etc!</p>
<div class="wp-caption alignleft" style="width: 342px"><a href="http://icanhascheezburger.files.wordpress.com/2009/02/funny-pictures-kitten-realizes-his-friend-is-not-real.jpg"><img title="not real " src="http://icanhascheezburger.files.wordpress.com/2009/02/funny-pictures-kitten-realizes-his-friend-is-not-real.jpg" alt="not-real" width="332" height="221" /></a><p class="wp-caption-text">not-real</p></div>
<p>So next moving on here is something i am looking forward to: <a title="Terminator Salvation" href="http://www.imdb.com/title/tt0438488/" target="_blank">http://www.imdb.com/title/tt0438488/</a></p>
<p>There is a new trailer it looks sweet! Anyways follow me on identi.ca i keep it pretty uptodate <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/about-me/tutorials-and-pages-on-the-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autoconf for dummies :)</title>
		<link>http://redbrain.co.uk/index.php/quick-tips/autoconf-for-dummies/</link>
		<comments>http://redbrain.co.uk/index.php/quick-tips/autoconf-for-dummies/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 17:24:11 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[autoconf]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=188</guid>
		<description><![CDATA[<p>I have been making a projects up wth autoconf  recently and i intend to clean up all my projects here if its java to be with ant build file! And then on with c projects with autoconf etc..</p>
<p>Anyways yeah read it because it makes it so easy this tutorial!  </p>
<p>Whoops forgot to link: http://www.galassi.org/mark//mydocs/autoconf_tutorial_toc.html</p>
<p>ciao [...]]]></description>
			<content:encoded><![CDATA[<p>I have been making a projects up wth autoconf  recently and i intend to clean up all my projects here if its java to be with ant build file! And then on with c projects with autoconf etc..</p>
<p>Anyways yeah read it because it makes it so easy this tutorial! <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Whoops forgot to link: <a href="http://www.galassi.org/mark//mydocs/autoconf_tutorial_toc.html" target="_blank">http://www.galassi.org/mark//mydocs/autoconf_tutorial_toc.html</a></p>
<p>ciao for now!</p>
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/quick-tips/autoconf-for-dummies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String Matching algorithms?! This is my one :)</title>
		<link>http://redbrain.co.uk/index.php/quick-tips/string-matching-algorithms-this-is-my-one/</link>
		<comments>http://redbrain.co.uk/index.php/quick-tips/string-matching-algorithms-this-is-my-one/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 10:32:44 +0000</pubDate>
		<dc:creator>redbrain</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[c/c++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://redbrain.co.uk/?p=157</guid>
		<description><![CDATA[<p>Hoping wordpress can make this code look half decent! Its in C:
//it is like the Boyer Moore algorithm but i dont think its fully optimized 
</p>
/**
 * @eturn returns the postition of the comparison
 * returns -1 if it cannot be found else i
 * @param str is the string you want to search through!
 [...]]]></description>
			<content:encoded><![CDATA[<p>Hoping wordpress can make this code look half decent! Its in C:<br />
//it is like the <a href="http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm">Boyer Moore</a> algorithm but i dont think its fully optimized <img src='http://redbrain.co.uk/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
<script src="js/shCore.js"></script><script src="js/shBrushCSharp.js"></script><script src="js/shBrushXml.js"></script><script type="text/javascript"><!--
dp.SyntaxHighlighter.ClipboardSwf = 'js/clipboard.swf';
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code',true,true,true,1,true);
// --></script></p>
<pre class="c#">/**
 * @eturn returns the postition of the comparison
 * returns -1 if it cannot be found else i
 * @param str is the string you want to search through!
 * @param comp is the string you want to search for!
 **/
static size_t str_getPlace( char* str, char* comp ) {

  size_t i, counter, complen=strlen(comp), skip_counter=0;
  i=complen-1;

  for (;;) {
    //printf("no: %i - orig: %c - %c\n",i,str[i],comp[complen-1]);
    if( comp[complen-1] == str[i] ) {
      //reset counter = 1 as we found one char already
      counter=1;
      if(complen &gt; 1) {
	int j;
	for(j=complen-2; j&gt;-1; --j){
	  --i;
	  if( comp[j] == str[i] )
	    counter++;
	  else{
	    //skipping length + the counter of already checked
	    i+=complen+counter;
	    break;
	  }
	}
      }
      //printf("Counters: comp length: %i -counter %i\n",strlen(comp),counter);
      if ( counter == strlen(comp) )
	return i;
    } else {
      //if i is bigger than length of string or the remaining
      //length is less than the length of the search
      if (i &gt;= strlen(str) || (strlen(str) -i) &lt;= complen ){
	skip_counter++;
	//if skipped more than the length of the search as there is no match!
	if( skip_counter &gt;= complen )
	  break;
	else
	  i=complen+skip_counter-1;
      } else
	i+=complen;
    }
  }
  return -1;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://redbrain.co.uk/index.php/quick-tips/string-matching-algorithms-this-is-my-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

