>
> The stub seems to parse, but I don't know how to associate an action with a particular structure. I don't know how to tell derp that the top-level S-expression should begin "(program", or that it doesn't need to emit ENDMARKER into the actual output. In short, it is not clear to me what needs to be added to or changed in the stub to turn it into a compliant parser.
>
What I'm doing is something like this:
I take each of the langs that we're given and use the matcher (>--> …) function to look for particular patterns.
So for example factor becomes:
(define factor (lang (>--> (or (seq* (or "+" "-" "~") factor) power)
[(list op factor) `(,op ,factor)]
[(list factor) factor] ;just factor
[a a]))) ;power
I'm not sure if the above one is fully correct, but I hope you get the idea.
I also use the seq* seq! and other cool functions to pull out what I need and try to match with the given grammar. So, seq and rep always throws out a list, opt should usually be given a default '() to make it always throw out an sexp that can be consed. or always gives a single valid sexp. So in the above factor lang, I enumerate all the possible matches.
In the end I throw away parts of the Sexps that I don't need and make sure it matches grammar, so the parser spits out what I do need. You can also use @--> and $-->, but I found that the matcher was the easiest to grasp for most cases.
Srikanth