<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6192660969907940943</id><updated>2011-07-31T00:31:59.664-04:00</updated><category term='command-line arguments'/><category term='ruby'/><category term='pir'/><category term='arithmetic'/><category term='antlr'/><category term='haskell'/><category term='ciat'/><category term='agile development'/><category term='constant folding'/><category term='yagni'/><category term='nrhc'/><category term='tdd'/><category term='parsing'/><category term='lexer'/><title type='text'>Compiler Club</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-6806523306318572523</id><published>2009-09-13T17:01:00.003-04:00</published><updated>2009-09-13T17:17:36.214-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><category scheme='http://www.blogger.com/atom/ns#' term='agile development'/><title type='text'>Interpreter, Going Open, and Milestones</title><content type='html'>&lt;p&gt;As I mentioned in my previous post, I've made my compiler available on github: &lt;a href="http://github.com/jdfrens/hobbes"&gt;jdfrens/hobbes&lt;/a&gt;.  I haven't officially put a license on it yet, but it'll be a "don't blame me for bad things, yet give me credit if you use it".&lt;/p&gt;

&lt;p&gt;I thought it would be interesting to start working on a interpreter as well.  I've written many interpreters the last couple of years (since "Programming Languages" had been &lt;em&gt;my&lt;/em&gt; course), but getting it to coexist with my compiler might be interesting.  I'm also curious what re-use I might find in my code.  (The interpreter could be used for constant folding.)  Plus, I want to see how well CIAT can deal with two different sets of processors.  (Short answer: quite well!  More on this later.)&lt;/p&gt;

&lt;p&gt;Finally, I'm trying out &lt;a href="http://www.pivotaltracker.com/"&gt;Pivotal Tracker&lt;/a&gt; to keep track of the &lt;a href="http://www.pivotaltracker.com/projects/29393"&gt;stories for my interpreter and compiler&lt;/a&gt;.  I'm thinking that I might post summaries for each true iteration there (i.e., once a week).  I'll have to have another post on how I've abused the term "iteration" here in the past.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-6806523306318572523?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/6806523306318572523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=6806523306318572523' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/6806523306318572523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/6806523306318572523'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2009/09/interpreter-going-open-and-milestones.html' title='Interpreter, Going Open, and Milestones'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-3223517340961420495</id><published>2009-09-11T16:42:00.003-04:00</published><updated>2009-09-11T16:49:43.071-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><title type='text'>Long time, no post!</title><content type='html'>&lt;p&gt;Since my life has settled down into merely "finding a job" (since I completed "frantically packing and moving"), I thought it would be a good idea to resurrect some of my old projects to keep and improve my programming skills.  I've picked up some new ideas for interpreting and compiling since I posted last (nine months ago), so this blog gets resurrected along with my NRHC.&lt;/p&gt;

&lt;p&gt;I accomplished two things today: I finished iteration #5 for the NRHC, and I moved my code to github!  Check out &lt;a href="http://github.com/jdfrens/hobbes/"&gt;my hobbes repository&lt;/a&gt;.  Soon I'll post a blog entry about iteration #5.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-3223517340961420495?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/3223517340961420495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=3223517340961420495' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/3223517340961420495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/3223517340961420495'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2009/09/long-time-no-post.html' title='Long time, no post!'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-8673595493312934858</id><published>2008-12-27T17:00:00.000-05:00</published><updated>2008-12-27T17:00:00.805-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='arithmetic'/><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><title type='text'>NRHC Story #4: Multiplication</title><content type='html'>&lt;h4&gt;User Story&lt;/h4&gt;

&lt;blockquote&gt;
 &lt;p&gt;A Hobbes program can be a single multiplication of integers or command-line arguments.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;Analysis&lt;/h4&gt;

&lt;p&gt;My NRHC compiler could already &lt;a
href="http://compilerclub.blogspot.com/2008/09/nrhc-story-2-integer-or-addition.html"&gt;add
two integers&lt;/a&gt;, so adding the ability to multiply two numbers should be pretty easy.  Just make the addition-generating code more generic, right?&lt;/p&gt;

&lt;h4&gt;Implementation&lt;/h4&gt;

&lt;p&gt;Mostly right. In terms of generating PIR code, yes, all I had to do was
make the code a bit more generic. I was surprised, though, that the additional
token type &lt;code&gt;MULTIPLY&lt;/code&gt; complicated the back end. It felt to me like
I was worrying about this extra token type more often than I should have
to.&lt;/p&gt;

&lt;p&gt;Now, granted, I'm using ASTs like (+ 1 2) and (* 3 4).  I don't have generic &lt;code&gt;OP&lt;/code&gt; ASTs: (OP + 1 2) and (OP * 3 4).  I suspect that this would make my code just a little bit simpler.  However, I'm sure I'll be better off moving to a tree intermediate representation.&lt;/p&gt;

&lt;h4&gt;Next Story&lt;/h4&gt;

&lt;p&gt;My next story will be to allow any number of additions and multiplications.
But first, I'm going to refactor my code to use TIRs in the back end. I'll say
more about TIRs in a future entry.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-8673595493312934858?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/8673595493312934858/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=8673595493312934858' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/8673595493312934858'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/8673595493312934858'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/12/nrhc-story-4-multiplication.html' title='NRHC Story #4: Multiplication'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-4324190248292623379</id><published>2008-12-26T15:40:00.001-05:00</published><updated>2008-12-26T17:05:03.691-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ciat'/><title type='text'>CIAT version 0.3.0</title><content type='html'>&lt;p&gt;I released &lt;a href="http://github.com/jdfrens/ciat/"&gt;CIAT 0.3.0&lt;/a&gt; today; it is almost all internal and API changes.&lt;/p&gt;

&lt;p&gt;The only output change is displaying standard error messages from a
Java-implemented compiler. This is useful (necessary even) for debugging.&lt;/p&gt;

&lt;p&gt;The input format didn't change at all.&lt;/p&gt;

&lt;p&gt;The biggest internal change is to make each processor responsible for its
own processing. (A processor is something like "a compiler implemented in
Java" or "the Parrot Virtual Machine".) Each processor is also responsible for
reporting whatever it finds important, like source code, compiled code,
generated code, execution, error messages, etc. As I expected, this led to
some code duplication, but for the time being I'm okay with that. Eventually,
I suspect the duplicated code will end up in a Ruby module for a mix-in.&lt;/p&gt;

&lt;p&gt;I feel a lot better about the design, and as I add new features, I'll be
trimming away the duplicated code and unnecessary abstractions I have now.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-4324190248292623379?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/4324190248292623379/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=4324190248292623379' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/4324190248292623379'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/4324190248292623379'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/12/ciat-version-030.html' title='CIAT version 0.3.0'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-8161225179548501001</id><published>2008-11-02T19:32:00.002-05:00</published><updated>2008-11-02T19:43:10.345-05:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='parsing'/><title type='text'>A Parsing DSL in Ruby</title><content type='html'>&lt;p&gt;I watched about half of a video about a parsing library written in Ruby, entitled (appropriately enough) &lt;a href="http://lsrc2008.confreaks.com/05-eric-mahurin-grammar-a-bnf-like-ruby-dsl-for-parsing.html"&gt;Grammar: A BNF-like Ruby DSL for Parsing&lt;/a&gt; (&lt;a href="http://rubyforge.org/projects/grammar/"&gt;project on RubyForge&lt;/a&gt;).  It seems kind of interesting, but it lacks a certain elegance.  I'd argue that &lt;a href="http://www.antlr.org/"&gt;ANTLR&lt;/a&gt; is a bit more elegant, but as I understand it &lt;a href="http://www.haskell.org/haskellwiki/Parsec"&gt;Parsec&lt;/a&gt; for Haskell is sheer elegance.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-8161225179548501001?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/8161225179548501001/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=8161225179548501001' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/8161225179548501001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/8161225179548501001'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/11/parsing-dsl-in-ruby.html' title='A Parsing DSL in Ruby'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-7295751880817912828</id><published>2008-10-30T16:23:00.003-04:00</published><updated>2008-10-30T16:57:24.505-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='command-line arguments'/><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><category scheme='http://www.blogger.com/atom/ns#' term='ciat'/><title type='text'>NRHC Story #3: command-line arguments (again, again!)</title><content type='html'>&lt;p&gt;So I'm done with Story #3 (started &lt;a href="http://compilerclub.blogspot.com/2008/09/nrhc-story-3-command-line-arguments.html"&gt;here&lt;/a&gt; and continued &lt;a href="http://compilerclub.blogspot.com/2008/10/nrhc-story-3-command-line-arguments.html"&gt;here&lt;/a&gt;).  Fixing my "problems" from the last time were not as difficult as I had at first anticipated.  (This is most evident since I'm posting this final follow-up the same afternoon!)&lt;/p&gt;

&lt;h3&gt;Implementation (again)&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The Parser.&lt;/strong&gt;  I had to tweak the parser so that ARGV references could appear in an addition expression.  The trick here was that I &lt;em&gt;couldn't &lt;/em&gt; just make the addition expression recursive since that would allow addition expressions in addition expressions.  I don't have a story for that feature yet, and there are too many other issues (associativity for one) that come up, so I couldn't easily add it.&lt;/p&gt;

&lt;p&gt;But this lead me down an interesting and good path.  A literal integer and an ARGV reference are both &lt;em&gt;simple&lt;/em&gt; expressions.  It's &lt;em&gt;simple&lt;/em&gt; expressions that can appear in an addition expression.  So a little bit of refactoring, and the grammar was whipped into shape.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Generation.&lt;/strong&gt;  Not much had to change with code generation.  I was already putting the value of an ARGV reference into a PIR register, the only trick was getting rid of extra &lt;code&gt;argv&lt;/code&gt; declarations.  As I described in my previous post, I need this directive in my PIR code when I want to use command-line arguments:&lt;/p&gt;
&lt;pre&gt;
.param pmc argv
&lt;/pre&gt;
&lt;p&gt;Originally, this directive was spit out &lt;em&gt;each&lt;/em&gt; time there was an ARGV reference, and it was spit out just before each ARGV reference.  So I'd end up with code like this:&lt;/p&gt;
&lt;pre&gt;
.param pmc argv
$I0 = argv[1]
.param pmc argv
$I1 = argv[2]
&lt;/pre&gt;
&lt;p&gt;The first change I made was to make a separate pass on the AST to generate the directive (and in the future any other directives for a function prolog).  So I had this:&lt;/p&gt;
&lt;pre&gt;
.param pmc argv
.param pmc argv
$I0 = argv[1]
$I1 = argv[2]
&lt;/pre&gt;
&lt;p&gt;My idea at this point was &lt;em&gt;to leave the extra directive in the code from this phase of the compiler&lt;/em&gt;.  It's not necessary for me to clean this up (or prevent it) right away; that would be giving the code generator too much responsibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linear-Code Analysis.&lt;/strong&gt;  I broke out the linear-code analysis into a separate phase from the actual writing-code phase, and I suspect this will become an official linear-code analysis and optimization module.&lt;/p&gt;

&lt;p&gt;So far, my linear-code analysis and processing consists of inserting tabs when needed and removing unnecessarily duplicated instructions.  I've taken the approach that duplicated instructions are by default acceptable (e.g., two instructions that increment $I0).  So I remove instructions that I know should not be duplicated, and so far that's just the &lt;code&gt;argv&lt;/code&gt; directive.&lt;/p&gt;

&lt;h3&gt;Other Observations&lt;/h3&gt;

&lt;p&gt;I'm quite surprised that I haven't felt a burning need to switch to a tree intermediate representation, just processing from the ANTLR AST I get back from the parser.  I'm certain, though, that one more language structure that requires a new &lt;code&gt;case&lt;/code&gt; in one of my switch statements will put me over the edge.  However, I think my next phase might be to add multiplication to the mix.  This should &lt;em&gt;not&lt;/em&gt; require a switch to a TIR.&lt;/p&gt;

&lt;p&gt;I also discovered a slight annoyance with CIAT.  Somewhat at the last minute when releasing v0.2.0, I tweaked the way it handles standard error, by dumping it into a file.  Unfortunately, this means the standard error does not appear on the console, and I have no reference to it in the report.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-7295751880817912828?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/7295751880817912828/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=7295751880817912828' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/7295751880817912828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/7295751880817912828'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/10/nrhc-story-3-command-line-arguments_30.html' title='NRHC Story #3: command-line arguments (again, again!)'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-3872470931588536213</id><published>2008-10-30T11:18:00.005-04:00</published><updated>2008-10-30T12:32:39.992-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='lexer'/><category scheme='http://www.blogger.com/atom/ns#' term='command-line arguments'/><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><title type='text'>NRHC Story #3: command-line arguments (again)</title><content type='html'>&lt;p&gt;I write this blog entry while I work on this story.  If you need to refresh your memory about Story #3, check &lt;a href="http://compilerclub.blogspot.com/2008/09/nrhc-story-3-command-line-arguments.html"&gt;the analysis post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I've decided to roughly time my process for this implementation.  However, I have many distractions: several of my students are going through mock interviews today, and I have to be on hand to handle fires; other students email me with questions and requests (like getting access to a subversion repository); and I'm trying to rip three versions of &lt;i&gt;The Wall&lt;/i&gt; to my computer today.  And I'm writing this blog post as I go (although I'm not counting those minutes).&lt;/p&gt;

&lt;h3&gt;The Implementation&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The Lexer.&lt;/strong&gt;  I started with the lexer.  To fully parse &lt;code&gt;ARGV[1]&lt;/code&gt;, I figured I could do it all in the lexer &lt;em&gt;or&lt;/em&gt; break it apart in the lexer and parse out integer in the parser.  Doing everything in the lexer &lt;em&gt;seems&lt;/em&gt; simpler since it's done in one place, but in thinking about it some more, I realized that it puts too much responsibility on the lexer, making it &lt;em&gt;more&lt;/em&gt; complicated.  It doesn't hurt that this will mostly be handled by the parser anyway in the future!&lt;/p&gt;

&lt;p&gt;So I needed to recognize &lt;code&gt;ARGV&lt;/code&gt;, &lt;code&gt;[&lt;/code&gt;, and &lt;code&gt;]&lt;/code&gt;.  (The compiler already recognizes integers.)  With a fair number of interruptions and distractions, this took me 40 elapsed minutes.  It was probably more like 10 or 15 minutes of real work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Parser.&lt;/strong&gt; So here's a surprise.  I did too much work for the lexer.  I finished the parser in about 10 minutes, and I didn't need to use the new tokens from my lexer.  This suffices in ANTLR:&lt;/p&gt;

&lt;pre&gt;
expression : 'ARGV[' INTEGER ']' -&gt; ^(ARGV INTEGER)
&lt;/pre&gt;

&lt;p&gt;I don't need the &lt;code&gt;ARGV&lt;/code&gt; for any reason after the parsing, so why bother to recognize it separately?  I &lt;em&gt;did&lt;/em&gt; however, create a temporary AST type named &lt;code&gt;"ARGV"&lt;/code&gt; as seen in the rewrite rule.&lt;/p&gt;

&lt;p&gt;So I took out the changes in my lexer, and I do the work in the parser.  I know it will change later, but since I'm not sure &lt;em&gt;how&lt;/em&gt; that will play out, I'll toss what I did now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Compilation.&lt;/strong&gt;  According to the clock, this took me around 40 minutes or so, but part of that time was spent talking to a delusional Packers fan about football.  (For the record, anyone &lt;em&gt;not&lt;/em&gt; a Bears fan is, by definition, delusional.)&lt;/p&gt;

&lt;p&gt;A couple things struck me while working on this.  First, my compiler is working with the raw ASTs from ANTLR.  They're not the nicest structures to work with since they're so generalized.  More importantly, they don't lead to good OO code at all; it's all &lt;code&gt;switch&lt;/code&gt; statements.  The thing is, I'm not sure when I should switch over to my "tree intermediate representation" that I've cooked over the last few years.  These TIR objects implement the visitor pattern, so the various compiler algorithms are nicely implemented in an OO way.&lt;/p&gt;

&lt;p&gt;Second, command-line arguments in PIR (that's "Parrot Intermediate Representation") required a compiler directive:&lt;/p&gt;
&lt;pre&gt;
.param pmc argv
&lt;/pre&gt;
&lt;p&gt;The thing is, this should be necessary only once in a PIR subroutine.  I'm not sure what the Parrot interpreter will do if I include it more than once.  In an addition expression, &lt;code&gt;ARGV[0] + ARGV[1]&lt;/code&gt;, it matters!  I could &lt;em&gt;always&lt;/em&gt; include the directive, but that would mean changing all of my previous acceptance tests.  I balk at that not because of the work involved (ten minutes, tops) but because it suggests I should be looking for a different solution.  So I need to figure a way to add that directive zero or one times as necessary.  This is going to require more thought.&lt;/p&gt;

&lt;p&gt;And this brings me to the third thing that I've discovered: I'm implementing only half the story!  I can use a command-line argument only in place of a single integer; I &lt;em&gt;cannot&lt;/em&gt; use them in an addition expression!   Ooops.&lt;/p&gt;

&lt;p&gt;I had to go back to see how I had phrased Story #3, and it does, in fact, promise the use of a command-line argument in place of any literal integer.&lt;/p&gt;

&lt;p&gt;There is this tension in writing a story between making it too trivial and too much.  Story #3 &lt;em&gt;is&lt;/em&gt; the right size in any practical situation.  However, it does &lt;em&gt;not&lt;/em&gt; mean I need to implement the whole story.  So this is a good place for me to break and to close out this blog entry.  I'll finish the rest of Story #3 and post a summary of the results.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-3872470931588536213?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/3872470931588536213/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=3872470931588536213' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/3872470931588536213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/3872470931588536213'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/10/nrhc-story-3-command-line-arguments.html' title='NRHC Story #3: command-line arguments (again)'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-5748192102000140261</id><published>2008-10-27T17:25:00.004-04:00</published><updated>2008-10-27T17:36:29.085-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tdd'/><category scheme='http://www.blogger.com/atom/ns#' term='ciat'/><title type='text'>CIAT version 0.2.0</title><content type='html'>&lt;p&gt;I &lt;em&gt;have&lt;/em&gt; been sort-of working on my compiler, just not on the compiler itself.  As I described &lt;a href="http://compilerclub.blogspot.com/2008/09/nrhc-story-3-command-line-arguments.html"&gt;in my last post&lt;/a&gt;, oh so long ago, I'm trying to add command-line arguments.  Unfortunately, my acceptance-testing framework &lt;a href="http://github.com/jdfrens/ciat/"&gt;CIAT&lt;/a&gt; (pronounced "dog") did not handle command-line arguments.  To get command-line arguments to work, CIAT would have to be reworked at a few levels.&lt;/p&gt;

&lt;p&gt;Fortunately, I know the guy in charge of the project (myself!), and it just meant pestering him in between other obligations.&lt;/p&gt;

&lt;p&gt;So that's mostly what I've worked on for the past month.  CIAT itself is written in Ruby, and I got sidetracked by cleaning up some of the HTML-generating code.  But I have a system that will handle (optional) command-line arguments!&lt;/p&gt;

&lt;p&gt;I haven't though much about the actual implementation of command-line arguments in Hobbes, so it'll be interesting to see how long it takes me to get back up to speed and finish the story.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-5748192102000140261?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/5748192102000140261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=5748192102000140261' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/5748192102000140261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/5748192102000140261'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/10/ciat-version-020.html' title='CIAT version 0.2.0'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-3693313736592615224</id><published>2008-09-02T13:25:00.004-04:00</published><updated>2008-09-02T13:57:12.734-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='command-line arguments'/><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><title type='text'>NRHC Story #3: command-line arguments</title><content type='html'>&lt;h3&gt;User Story&lt;/h3&gt;

&lt;blockquote class="user-story"&gt;
&lt;p&gt;A Hobbes program can refer to command-line arguments in place of a literal integer.  The syntax is array-like: &lt;code&gt;ARGV[&lt;i&gt;i&lt;/i&gt;]&lt;/code&gt;, where &lt;code&gt;&lt;i&gt;i&lt;/i&gt;&lt;/code&gt; is an integer.  Command-line arguments are assumed to be integers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;Analysis&lt;/h3&gt;

&lt;p&gt;As I mentioned in my writeup of Story #2, it bothers me that a constant folder might satisfy that story better.  I &lt;em&gt;want&lt;/em&gt; to write a constant folder, but I &lt;em&gt;also&lt;/em&gt; want to be required to generate interesting PIR code.&lt;/p&gt;

&lt;p&gt;To force the issue, I need some way to get outside information into the running program.  I could have gone with file or keyboard input, but I hate keyboard input, and I have no love for file input.  It also seems like a &lt;em&gt;lot&lt;/em&gt; to pull into Hobbes at this point.  Grabbing input from command-line arguments is fairly easy to do in PIR, and it extends the language very simply at this point.&lt;/p&gt;

&lt;p&gt;My first thought was to use a syntax like &lt;code&gt;$0&lt;/code&gt;, &lt;code&gt;$1&lt;/code&gt;, &lt;code&gt;$2&lt;/code&gt; to refer to specific command-line arguments.  This feels a little too much like bash or Perl to me, and it's not the syntax that I'll use eventually.  In talking about this story with my Compiler Club cohorts, we brainstormed that it might be useful to start using the ultimate syntax right now: &lt;code&gt;ARGV[0]&lt;/code&gt;, &lt;code&gt;ARGV[1]&lt;/code&gt;, &lt;code&gt;ARGV[2]&lt;/code&gt;.  There are two reasons why I like this:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;I won't have to change acceptance tests later on.&lt;/li&gt;
  &lt;li&gt;It won't be a difficult thing to do in the compiler right now.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If it was harder to implement, then my first reason wouldn't matter at all.  I love having my cake and eating it, too!&lt;/p&gt;

&lt;p&gt;If this goes well, I suspect Story #4 will be to add &lt;code&gt;print()&lt;/code&gt; as special syntax.  Using the &lt;code&gt;print()&lt;/code&gt; function will be required eventually, and it would be useful to get used to this syntax and to upgrade my acceptance tests sooner rather than later.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-3693313736592615224?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/3693313736592615224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=3693313736592615224' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/3693313736592615224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/3693313736592615224'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/09/nrhc-story-3-command-line-arguments.html' title='NRHC Story #3: command-line arguments'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-838393556231092965</id><published>2008-09-01T19:32:00.003-04:00</published><updated>2008-09-01T20:04:07.424-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='parsing'/><category scheme='http://www.blogger.com/atom/ns#' term='lexer'/><category scheme='http://www.blogger.com/atom/ns#' term='yagni'/><title type='text'>YAGNI ANTLR?</title><content type='html'>&lt;p&gt;As soon as I posted my last entry, I feared I was a little too coy or defensive about using ANTLR.  There &lt;em&gt;is&lt;/em&gt; a part of me that thinks I jumped to ANTLR too soon.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It"&gt;YAGNI!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's what I hear when I go to sleep at night.  Well, maybe only when I write these blog posts about using ANTLR.&lt;/p&gt;

&lt;p&gt;"You Ain't Gonna Need It" (YAGNI) is about implementing the simplest thing that will work.  If you don't need it &lt;em&gt;now&lt;/em&gt;, don't use or implement it.&lt;/p&gt;

&lt;p&gt;When I was searching for a good reference for "YAGNI", I came across &lt;a href="http://www.artima.com/weblogs/viewpost.jsp?thread=36529"&gt;this essay&lt;/a&gt; from "Uncle Bob" Martin.  He describes how they developed FitNesse for &lt;em&gt;months&lt;/em&gt; without writing pages to disk; everything ran in memory!  They just didn't need the write-pages-to-disk feature right away.&lt;/p&gt;

&lt;p&gt;A fairly good argument could be made for delaying ANTLR in my compiler, although maybe not as good as the pages-in-memory argument for FitNesse.  The FitNesse developers got a great "page storage" interface, but there's already a natural interface between the front end and back end of a compiler.  If this natural interface didn't already exist, I'd consider this a strong argument in favor of delaying ANTLR.&lt;/p&gt;

&lt;p&gt;There's a consideration of expertise.  I already know ANTLR, and I know it better than I know regular expressions in Java.  ANTLR wins.&lt;/p&gt;

&lt;p&gt;There's a consideration of code size.  If I were to go &lt;em&gt;truly&lt;/em&gt; with the simplest thing that could work, the plain Java version could be done with a &lt;code&gt;StringTokenizer&lt;/code&gt; and a regular expression.  However, you'd lose most (if not all) of the interface between the front and back ends.  The stronger you try to make that interface, the more code you have to write for the plain Java version.  ANTLR provides the interface, and it's really not that much code at all.&lt;/p&gt;

&lt;p&gt;So, I won't say it's completely obvious that ANTLR is &lt;em&gt;the&lt;/em&gt; right step to take this soon, but it's also not obvious that ANTLR should be delayed.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-838393556231092965?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/838393556231092965/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=838393556231092965' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/838393556231092965'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/838393556231092965'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/09/yagni-antlr.html' title='YAGNI ANTLR?'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-1613313859544364635</id><published>2008-09-01T18:20:00.004-04:00</published><updated>2008-09-01T19:32:43.406-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='constant folding'/><category scheme='http://www.blogger.com/atom/ns#' term='parsing'/><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><title type='text'>NRHC Story #2: integer or addition</title><content type='html'>&lt;p&gt;I just can't start working on Story #3 when I "have" to get caught up writing these blog entries...&lt;/p&gt;

&lt;h3&gt;User Story&lt;/h3&gt;

&lt;blockquote class="user-story"&gt;
&lt;p&gt;A program of the form &lt;code&gt;n+m&lt;/code&gt; is a valid Hobbes program, for integers &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;m&lt;/code&gt;.  The PIR code should perform the addition and print the result.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;Analysis&lt;/h3&gt;

&lt;p&gt;One of the lessons I've learned about iterative development is that the stories should be small.  For some reason, I had the idea that "story" equals "iteration" when it came to compiler writing, but that's very, very wrong.  So while you might like to get all arithmetic implemented in one &lt;em&gt;iteration&lt;/em&gt;, you should &lt;strong&gt;not&lt;/strong&gt; write that up as one &lt;em&gt;story&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Having erred that way in the past, I might be going in the other direction now, making the story &lt;em&gt;too&lt;/em&gt; small.  However, I don't (for now at least) see "too small" as an error.  It just means writing more stories.  Tentatively, I see these stories (in a mostly strict order):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Implement addition of &lt;em&gt;only&lt;/em&gt; two integers&lt;/li&gt;
  &lt;li&gt;Implement multiplication&lt;/li&gt;
  &lt;li&gt;Implement subtraction, division, modulus, exponentiation, and other binary operators&lt;/li&gt;
  &lt;li&gt;Implement two-operator expressions &lt;em&gt;without&lt;/em&gt; precedence and with only left associativity&lt;/li&gt;
  &lt;li&gt;Implement multiple-operator expressions&lt;/li&gt;
  &lt;li&gt;Implement precedence&lt;/li&gt;
  &lt;li&gt;Implement right associativity (for exponentiation)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We'll revisit this list as I implement the other stories.&lt;/p&gt;

&lt;p&gt;One really cool thing about breaking them down this small, I can implement other features in between.  For example, Story #3 is implementing command-line arguments.  That will bring extra considerations for this story as well as the other arithmetic stories.&lt;/p&gt;

&lt;h3&gt;Implementation&lt;/h3&gt;

&lt;p&gt;The front end now benefits from a parser.  Previously, a Hobbes program could only be a single integer, so a lexer was fine (assume that the lexer spits out an integer token).  But now there's an alternative (integer &lt;em&gt;or&lt;/em&gt; integer addition), and this can be implemented in an ANTLR parser quite easily.&lt;/p&gt;

&lt;p&gt;Since I started using a parser, my acceptance tests started complaining about a newline at the end of the input.  (This is a slight drawback of CIAT: all files end with a newline.)  So I also had to add the ability to ignore whitespace to my lexer.&lt;/p&gt;

&lt;p&gt;As for the back end, the front end will give me an ANTLR abstract syntax tree which is a pretty plain data structure.  I do a &lt;code&gt;switch&lt;/code&gt; over that type of the AST and spit out the appropriate PIR code.&lt;/p&gt;

&lt;p&gt;In between the first and second stories, I tweaked the way I collect, store, and print PIR instructions.  In the compiler itself, I don't want to have to worry about &lt;em&gt;all&lt;/em&gt; of the PIR formatting rules with tabs and newlines.  Here's an example of a complete program:&lt;/p&gt;
&lt;pre&gt;
.sub main
 $I0 = 100
 $I1 = -36
 $I0 += $I1
 print $I0
 print "\n"
.end
&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;.&lt;/code&gt; directives are not indented; the executable code is indented.  From what I can tell, the difference is that initial &lt;code&gt;.&lt;/code&gt;, so that's what I follow for indentation.&lt;/p&gt;

&lt;p&gt;Actually, there's a serious temptation at this stage to write a constant folder.  Since the two values in an addition expression are going to be constants, why doesn't my compiler do the addition for me?  This would be perfectly acceptable for this story, appropriately following YAGNI.  However, Story #3 will request command-line arguments; the general code will have to be generated then at least some of the time, and the constant folder will be of less use.  I might implement a constant folder as Story #4; I haven't decided yet.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-1613313859544364635?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/1613313859544364635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=1613313859544364635' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/1613313859544364635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/1613313859544364635'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/09/nrhc-story-2-integer-or-addition.html' title='NRHC Story #2: integer or addition'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-6859499843799507327</id><published>2008-09-01T16:48:00.004-04:00</published><updated>2008-09-01T17:35:37.226-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='antlr'/><category scheme='http://www.blogger.com/atom/ns#' term='pir'/><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><category scheme='http://www.blogger.com/atom/ns#' term='ciat'/><title type='text'>NRHC Story #1: a single integer</title><content type='html'>&lt;h3&gt;User Story&lt;/h3&gt;

&lt;blockquote class="user-story"&gt;
&lt;p&gt;A valid Hobbes program consists of a single integer (positive or negative).  The compiler should generate a PIR program which, when executed, the single integer will be printed to standard output.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;Analysis and Implementation&lt;/h3&gt;

&lt;p&gt;In the future, I plan to post something before I start a story and after I complete it.  Many things change along the way.  But since I'm getting ready to start Story #3, I'll do just this one post for Story #1.&lt;/p&gt;

&lt;p&gt;There's a tempting option for this story: write a single Java program that reads from &lt;code&gt;System.in&lt;/code&gt; and writes to &lt;code&gt;System.out&lt;/code&gt; to satisfy the story.  (I should at least try this sometime.)  Instead, I pulled in &lt;a href="http://www.antlr.org"&gt;ANTLR&lt;/a&gt; right away to use its regular expressions to recognize valid integers.  This also let me start unit testing with my own &lt;a href="http://antlr-testing.sourceforge.net/"&gt;ANTLR Testing library&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I had to write a very minimal parser in ANTLR so that it could figure out some follow sets.  But I only used the lexer in the back end: read the integer from ANTLR, and print &lt;a href="http://www.parrotcode.org/"&gt;PIR code&lt;/a&gt; to display that number.&lt;/p&gt;

&lt;p&gt;I've toyed around with PASM (the assembly-level version of Parrot code) in the past, but it appears the Parrot people are more interested in PIR, which works at a slightly higher level.  It's still a linear code, but you get to use your own variable names (not have to worry about registers), the syntax for declaring and calling procedures is &lt;em&gt;greatly&lt;/em&gt; simplified, and conditional branching is done with a readable &lt;code&gt;if...goto...&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;This story actually took me &lt;em&gt;quite&lt;/em&gt; a lot of time because I spent so much time working on a framework for writing acceptance tests.  I use &lt;a href="http://www.fitnesse.org/"&gt;FitNesse&lt;/a&gt; for my &lt;a href="http://nolatte.sourceforge.net/"&gt;No Latte interpreter&lt;/a&gt;.  No Latte, as a language for writing web pages, is very sensitive to whitespace, and FitNesse tends to trim whitespace off your input and output.  Also, FitNesse's format is a bit annoying for multi-line input.  Hence, &lt;a href="http://github.com/jdfrens/ciat"&gt;CIAT&lt;/a&gt; (pronounced "dog") was born.  With a lot of help from Mark, we got a 0.1.0 version out that works quite well.&lt;/p&gt;

&lt;h3&gt;Lessons Learned&lt;/h3&gt;

&lt;p&gt;Most of the lessons I learned on this iteration were learned on CIAT.  Most importantly, I had to figure out how to write acceptance tests for an acceptance tester!&lt;/p&gt;

&lt;p&gt;As for my Hobbes compiler, there wasn't anything particularly surprising to me on this iteration.  The front end was a rather simple lexer.  The back end assumed that the front end gave it an integer token which it turned into four or five lines of PIR code.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-6859499843799507327?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/6859499843799507327/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=6859499843799507327' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/6859499843799507327'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/6859499843799507327'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/09/nrhc-story-1-single-integer.html' title='NRHC Story #1: a single integer'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-6197665437031201324</id><published>2008-08-30T20:26:00.002-04:00</published><updated>2008-08-30T21:08:45.498-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tdd'/><category scheme='http://www.blogger.com/atom/ns#' term='nrhc'/><category scheme='http://www.blogger.com/atom/ns#' term='agile development'/><title type='text'>The NoRecess Hobbes Compiler</title><content type='html'>&lt;h3&gt;My Compiler&lt;/h3&gt;

&lt;p&gt;I'm calling my compiler the "NoRecess Hobbes Compiler".  "NoRecess" is a moniker I picked up years ago when I was in college.  I even bought up the domain for my website: &lt;a href="http://www.norecess.org/"&gt;NoRecess&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;"Hobbes" is the name of the language I'll be compiling.  It's based on the Tiger language from Andrew Appel's compiler books.  It looks and works a bit like ML.&lt;/p&gt;

&lt;h3&gt;My Approach&lt;/h3&gt;

&lt;p&gt;Agile.&lt;/p&gt;

&lt;p&gt;I'm tempted to leave it just at that, but I want to highlight two things.&lt;/p&gt;

&lt;p&gt;First, I believe strongly in test-first development.  I believe strongly in acceptance testing.  In short, I believe in &lt;a href="http://rubyhoedown2008.confreaks.com/05-bryan-liles-lightning-talk-tatft-test-all-the-f-in-time.html"&gt;TATFT&lt;/a&gt; ("Test All The Freakin' Time", video NSFW!).&lt;/p&gt;

&lt;p&gt;Second, over the last few years, I've come to appreciate incremental development in &lt;em&gt;educational&lt;/em&gt; settings.  A former student and I tried this very thing and wrote a &lt;a href="http://doi.acm.org/10.1145/1121341.1121372"&gt;paper about it&lt;/a&gt;.  It's become clear to me that the real key is to work with &lt;em&gt;really&lt;/em&gt; small iterations.&lt;/p&gt;

&lt;h3&gt;Technologies&lt;/h3&gt;

&lt;p&gt;I'm using &lt;a href="http://java.sun.com/"&gt;Java&lt;/a&gt; and &lt;a href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt; to implement my compiler.  The front end is being implemented with &lt;a href="http://www.antlr.org/"&gt;ANTLR&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For unit testing, I'm using &lt;a href="http://www.junit.org/"&gt;JUnit&lt;/a&gt; and my own &lt;a href="http://antlr-testing.sourceforge.net/"&gt;ANTLR Testing&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For acceptance testing, I've used &lt;a href="http://www.fitnesse.org/"&gt;FitNesse&lt;/a&gt; in the past for both compilers and interpreters, and the biggest problem I've had is in whitespace processing.  Programs are usually multi-line affairs, and it's annoying entering them into FitNesse tables.  Even worse, FitNesse strips the initial and trailing whitespace, and many times indentation matters a lot!&lt;/p&gt;

&lt;p&gt;So I wrote my own acceptance tester: &lt;a href="http://github.com/jdfrens/ciat/tree/master"&gt;CIAT&lt;/a&gt; ("Compiler and Interpreter Acceptance Tester", pronounced "dog").  So far I'm really liking the way it's evolving.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-6197665437031201324?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/6197665437031201324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=6197665437031201324' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/6197665437031201324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/6197665437031201324'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/08/norecess-hobbes-compiler.html' title='The NoRecess Hobbes Compiler'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6192660969907940943.post-7602557445655706967</id><published>2008-08-30T20:11:00.003-04:00</published><updated>2008-08-30T20:23:48.810-04:00</updated><title type='text'>Welcome!</title><content type='html'>&lt;p&gt;As you might guess from the title of this blog, it's focused on compilers.  I am one of those strange software developers who is utterly fascinated by interpeters and compilers.  Two former students convinced me to start an informal compiler course (it took all of ten seconds).  The result is that we've met for a couple weeks this summer, and we've made decent progress (considering that all but me are full-time employees in the summer).&lt;/p&gt;

&lt;p&gt;The purpose of this blog is to record some of the interesting compiler things we stumble upon.  I plan to record the iterations I go through building my compiler.  I suspect most of us will post interesting links.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6192660969907940943-7602557445655706967?l=compilerclub.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://compilerclub.blogspot.com/feeds/7602557445655706967/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6192660969907940943&amp;postID=7602557445655706967' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/7602557445655706967'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6192660969907940943/posts/default/7602557445655706967'/><link rel='alternate' type='text/html' href='http://compilerclub.blogspot.com/2008/08/welcome.html' title='Welcome!'/><author><name>Jeremy D. Frens</name><uri>http://www.blogger.com/profile/13179698525098485533</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp3.blogger.com/_7fOA1sUkarU/SFvGdEzS1-I/AAAAAAAAAAM/51V3Y4gGrwg/S220/me.jpg'/></author><thr:total>0</thr:total></entry></feed>
