Reflection
This tutorial was essentially my "intro to compilers" course.
It started at lexing, moved through parsing, onto optimization,
and finally ended with compilation of source files.
A mixture of articles and Matt Might's course page were used to
inform me of the topics, techniques, and choices when building a
compiler.
Racket was the main tool for exploring this topic due
to its huge repository of parsing and lexing tools
as well as s-expressions syntax naturally lending itself
to storing abstract syntax trees.
An overview of the three areas of compilers that were covered:
- Lexing:
- Basic tokenizing of text strings.
- Pre-lexer text alterations to make tokenizing more efficient.
- Data structures and pipelines to best hand off the token stream to a parser.
- Parsing:
- Techniques and families of parsers: LR, LL, LALR, SLR, and GLR.
- Abstract syntax trees (AST).
- BNF madness.
- Compiling:
- AST translation.
- post-parse optimizations.
- Unpacking compiled code from ASTs.
All of these topics were worked through with code examples
which can be seen by looking at early weeks on this
tutorials page.
The basic research into them was finished in early November.
After that I moved into getting a skeleton of my plan project
coded up given what I had learned.
The idea for my language is to by a more readable, syntactically
consistent option for programming Arduinos. My initial idea was
to make a compiled LISP for this project, but after some lessons
learned in teaching the Gadgets course and watching Rich Hickeys
"The Value of Values" talk, I realized LISP would be
a poor choice. Instead I went for more of an F#/Scala language
that considers the architectural difference between most
Arduinos and other computers (Harvard vs Von Neumann) in its
syntax. Something that is slightly more functional leaning, but
still understands its need to be stateful given the Arduinos
limited resources. The source code will be compiled to C and
from there GCC will take it down to AVR assembly.
I have finished a first draft of the lexer and parser as well
reasonable start to the transcompiler.
What next
- I need to fix some glaring holes in the parser and lexer.
- The transcompiler needs to be chipped away. It is not a complicated piece to write, just a tedious one.
- Docs and write-ups shall be started once the project is a little further along.
Feelings about the tutorial
I feel really good about the material I have covered and the
work I have produced. I had little-to-no experience in the
topic before this semester, but I feel like I have some good
foundational knowledge now. I did have the small interpreter
project last Spring, but that was done with zero research
and in the least advisable manner possible. It was a good exercise
for sure, but this tutorial feels like it gave me the knowledge to
make choices when programming a compiler, rather than coding it the
first way that comes to mind.
At the beginning of the semester I wanted to have the lexer and parser
drafted and the compiler started. That is exactly where I am, so I feel
pretty happy with with where I stand at the moment.