Annnnnnnd done!

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Annnnnnnd done!

Foggerty
This post was updated on .
Well that was 'fun'.  I decided that this would be a good time to learn the Go language, and it was.  I also decided to go a bit overboard and implement an actual Lexer based off of Rob Pike's talk show here, which has the lexer and parser running concurrently, which I did, but it made the whole experice a tad frustrating at times.

The source code lives here.

But, using a lexer/parser combo instead of just a regex and straight substitution gives nice things like warnings (two statements like @123, @456 are legal, but the first will have no effect) and I'll be reusing some of the code in the compiler project:

matt assembler # assembler -in Fill.asm -out filler.hack
WARNING - redundant loading of A-Register on line 1
WARNING - redundant loading of A-Register on line 17

I want to go back and possibly re-write the lexer as it's looking way more ugly than the parser, mainly because I wrote it first while still learning.

matt stuff # time assembler -in ~/Google\ Drive/Development/Nand2Tetris/course/projects/06/pong/Pong.asm -out pong.hack

real	0m0.178s
user	0m0.135s
sys	0m0.082s

No idea how (comparatively) fast that it, but would be curious to compare it to other implementations, if folks want to start a competition?  (Bring on the language fights!)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Annnnnnnd done!

ybakos
Pretty cool!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Annnnnnnd done!

cadet1620
Administrator
In reply to this post by Foggerty
Foggerty wrote
No idea how (comparatively) fast that it, but would be curious to compare it to other implementations, if folks want to start a competition?  (Bring on the language fights!)
I have versions written in ANSI C, both 2-pass and 1-pass. If you want to try building and timing them on your system, shoot me an email.

--Mark
Loading...