[Haskell-cafe] Minim interpreter

Hugh Perkins 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,
something like:

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
effectively:

data Program = ProgramLeaf Statement | ProgramTree Statement Program
   deriving(Show)

... 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...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070722/f663930c/attachment.htm


More information about the Haskell-Cafe mailing list