Writing compilers is such an interesting topic. For some reason I want to implement a version of BASIC that targets multiple architectures. Why? Why not!
Being a Java guy, some fishing around brought me to ANTLR a while ago and I was able to implement a simple expression interpreter that handles multiple data types. Rather neat, really.
I'd like to extend this into the realm of a full fledged compiler. Not only a compiler, but a multiheaded beast that targets the 6502 (read: Apple II+), 65c02 (read: enhanced Apple IIe), 65816 (read: Apple IIgs), Java bytecode (read: easy application testing), and possibly PIC 16/18 (read: microcontroller goodness). Not to mention that I want to design and build a 65c02 or 65816 based computer from scratch. Talk about crazy and I appear to be it!
At any rate, I started this concept a number of times in the past year. Each one stumbled and I got interested in something else.
This time, I am starting very, very simple and then adding the complicated pieces on. I intend to get a compiler that is just a portion of the language but one that is the full depth back to the code generation.
I've got a grammar for which I'm actually generating pseudo-code. The grammar consists of only two data types, expressions only for addition and subtraction, variables must be declared, and a print statement. This should allow me to deal with tracking variable types, throwing errors, generating output, structuring the AST, and how to write unit tests for it.
Now, I need to figure out better error handling and how to construct unit tests to do a better job of verifying any progress I make. I think I'm actually almost to the point of actually generating target code.
Hopefully I'll have good news to report in a few weeks!
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment