3 ms·
This is a technique I first came across in the code for lcc, as described in David R. Hanson's book "A Retargetable C Compiler: Design and Implementation". htt
by spatulon 12y ago
This is a technique I first came across in the code for lcc, as described in David R. Hanson's book "A Retargetable C Compiler: Design and Implementation".
https://sites.google.com/site/lccretargetablecompiler/ https://sites.google.com/site/lccretargetablecompiler/
The code in that book feels pretty dated in a lot of places, but this was a neat trick. Every piece of information related to a token is defined in one place:
https://github.com/drh/lcc/blob/master/src/token.h https://github.com/drh/lcc/blob/master/src/token.h
Then here's how it's used:
https://github.com/drh/lcc/blob/master/src/expr.c#L8 https://github.com/drh/lcc/blob/master/src/expr.c#L8
https://github.com/drh/lcc/blob/master/src/output.c#L107 https://github.com/drh/lcc/blob/master/src/output.c#L107