I did some programming, and threw all code away again. I am gonna cheat a bit and represent integers, floats, and other literals by their text representation and write conversion routines for them to native words. It keeps the number of AST nodes small since it doesn't introduce a separate case for each literal (like int, long, float, double) at the expense of inspecting the text representation from time to time.
Without my hands in the guts of your implementation, my first response is to implement literals in the following manner. (using a generic ML/Haskell'ish syntax)
ReplyDeletedatatype litval = LInt int | LStr str | LChr char | LFlt real | LUnit unit | LBool bool;
datatype Term = ... | Lit litval | ...;
Now you can ignore literal values except in those cases where you need to further destructure Lit term constructors.
Just an idea, but certainly avoids relexing/parsing strings representing literal values.
- Scott