using derp

58 views
Skip to first unread message

Lucas Paul

unread,
Feb 9, 2013, 9:19:11 PM2/9/13
to utah-compiler...@googlegroups.com
Thanks to the lectures, I have a healthy appreciation for parsing with derivatives, and I think I begin to grasp some of the principles involved. I wanted to get started on my parser, so I downloaded the derp stub (http://matt.might.net/apps/pyparse/stub.tar.gz) and started playing with it. But between it and the derp documentation (http://matt.might.net/teaching/compilers/spring-2013/derp.html) I am still at a loss as to how to really use derp.

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.

Will this be covered in lectures? Is there more thorough documentation or examples I could refer to?

Matt Might

unread,
Feb 9, 2013, 9:25:14 PM2/9/13
to Lucas Paul, utah-compiler...@googlegroups.com
I think I should give a lecture on using derp. :)

-Matt
> --
> You received this message because you are subscribed to the Google Groups
> "Utah Compilers, Spring 2013" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to utah-compilers-spri...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Colton Myers

unread,
Feb 9, 2013, 9:27:11 PM2/9/13
to Matt Might, utah-compiler...@googlegroups.com, Lucas Paul

Yes, please! =) 

--
Colton Myers

Parker Wightman

unread,
Feb 10, 2013, 12:17:39 AM2/10/13
to utah-compiler...@googlegroups.com
This is the same issue we ran into. Everything that was given to us is what I thought we had to write ourselves, so we're at a loss as to what needs doing and what will affect output. In short, exactly what Lucas said :-)

Parker

Srikanth Raju

unread,
Feb 10, 2013, 3:25:56 AM2/10/13
to utah-compiler...@googlegroups.com, Lucas Paul
>
> 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
Reply all
Reply to author
Forward
0 new messages