Languages, continued...
A while back, I wrote about how cool Lex is, well it is about time to write how cool, but painful if you don’t know it already, Yacc is. Yacc, or Yet Another Compiler-Compiler, takes tokens as input, and based on BNF rules you specify it executes bits of code. So the idea is, you give it:
- Grammar
- Code to execute when a match occurs
The code that gets executed can do anything and (almost) everything. So, one would probably want to create some kind of abstract syntax tree, which gets translated into intermediate representation, which in turn gets translated into assembly, which gets assembled by (usually) outside assembler. So, from 0 to full compiler in no time.
The thing that is painful about yacc is just the strangeness with which some things appear to be done. But at the end of the day, I don’t want to give yacc up for anything.