Elements of Computing Systems Chapter 11b

Paul Mucur edited this page Jul 2, 2015 · 5 revisions
Clone this wiki locally

## Exercises

We began the meeting by picking off where we were last time: completing the SymbolTable implementation and using it to decorate our XML output with the context necessary for eventual VM code output.

We decided to use a test to drive out the missing start_subroutine method on our SymbolTable: eschewing the book's advice to use two hash tables and instead opting for some good, old-fashioned state mutation:

With that complete, we could now go through the XML generating Parser and add attributes to each identifier with their type, kind and index:

This concluded our adventures with XML and we began the process of converting our XML output to VM code by implementing the book's suggested VMWriter API:

We then began a new Compilation Engine, combining our existing Tokenizer and VMWriter to actually compile Jack programs into VM code:

## Aside

There were quite a few entertaining asides this meeting:

  • Tom showed how Ruby's Enumerable#count can take an item as an argument for counting specific occurrences;

  • Paul relished using Ruby's rather odd heredoc syntax in a method call:

some_function(<<XML, <<YML, <<EOF)
<root/>
XML
foo:
  bar
YML
A really long string
EOF

Thanks

Thanks to Leo & Paul and Geckoboard for typing and hosting respectively.