[Haskell-cafe] Minim interpreter
hughperkins at gmail.com
Sun Jul 22 17:56:00 EDT 2007
heh! well everyone was busy working on icfp or something, so the newsgroup
was pretty dead :-) And I played with opengl a little, which gave better
results than I thought, but not good enough to pursue, and the whole program
was in imperative "do"s anyway, so I couldnt quite see what was the point of
moving to a non-imperative language!
End of rant...
It looks like there's a huge amount of documentation on the parsing process,
but it's kindof more fun to just figure it out ourselves, I think?
Anyway, for handling loops, what I'm thinking is maybe the Map that holds
variables, rather than holding a "Double" type should hold a "variant" type,
data Variant = VDouble Double | VString String | ... etc...
then, to handle loops, which basically involves creating a "pointer"
variable, we simply add a variant type that holds a program:
data Variant = ... | VProgram Program
... and then we can just assign to the Variant type in the map corresponding
to the symbol the rest of the program that follows that symbol.
Note that we have to reverse the Program data type to get this to work
data Program = ProgramLeaf Statement | ProgramTree Statement Program
... errr... I think... because that way we can grab any part of the program
tree and store that as a Variant in the map.
How does that sound? That ought to get looping working? Then we just have
to handle conditionals, which I havent thought at all about yet.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe