Parser implementation 'in the wild'

19 views
Skip to first unread message

aarongough

unread,
Oct 5, 2010, 12:11:39 AM10/5/10
to Treetop Development
I recently used Treetop to create the full parser for an experimental
language I was working on. Someone pointed out to me that they hadn't
seen any other examples of full Treetop grammars in the wild, so with
that in mind I thought I should let you guys know about it.
The implementation is here:

http://github.com/aarongough/koi-reference-parser

I've tried to point as many people as possible toward Treetop by
mentioning it multiple times in my docs, hopefully that generates some
traffic!

I'm also happy to answer any question, or hear any feedback on the
grammar.

Thanks for the great work!
Regards,
Aaron

Jasim

unread,
Oct 23, 2010, 1:28:45 AM10/23/10
to Treetop Development, aa...@aarongough.com
Hello Aaron,

I'm trying to implement a simple DSL for transforming matrices (http://
github.com/jasim/matrix_transformations) based on Treetop. Went
through your code and learned a few things:

-> clean_tree. The thought had not crossed me.
-> to_hash. Nice one there.
-> rule comment and end_of_file.

Thanks for sharing!

Regards,
Jasim.

aarongough

unread,
Oct 23, 2010, 1:16:37 PM10/23/10
to Treetop Development
Glad you found it useful Jasim!

I'm actually curious how other people treat the trees produced by
Treetop. Is there some common-sense way of handling the tree that
doesn't require the intermediate step of cleaning out all the cruft?

-A

Jonathan Stott

unread,
Oct 23, 2010, 2:20:48 PM10/23/10
to treet...@googlegroups.com
For the exalted math gem (http://github.com/namelessjon/exalted_math)
I just go straight to an AST representation. Each Treetop node knows
how to transform itself into an (array based) AST node. Though I'm
thinking of cleaning up my treetop grammer using the <Class> trick you
use in the koi parser. I suppose it's about the same as yours, in
that the AST transformation drops the cruft.

Regards
Jon

> --
> You received this message because you are subscribed to the Google Groups "Treetop Development" group.
> To post to this group, send email to treet...@googlegroups.com.
> To unsubscribe from this group, send email to treetop-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/treetop-dev?hl=en.
>
>

aarongough

unread,
Oct 23, 2010, 8:39:58 PM10/23/10
to Treetop Development
Just had a look through your grammar, it makes total sense. We're
basically doing the same thing I guess.

Using an array based AST makes like you suggests makes lots of sense,
the main reason I went with hashes originally was so I could preserve
information about line-numbers for error reporting, but that wasn't
used in the end anyway.

On Oct 23, 2:20 pm, Jonathan Stott <jonathan.st...@gmail.com> wrote:
> For the exalted math gem (http://github.com/namelessjon/exalted_math)
> I just go straight to an AST representation.  Each Treetop node knows
> how to transform itself into an (array based) AST node.  Though I'm
> thinking of cleaning up my treetop grammer using the <Class> trick you
> use in the koi parser.  I suppose it's about the same as yours, in
> that the AST transformation drops the cruft.
>
> Regards
> Jon
>

Jasim

unread,
Nov 5, 2010, 2:40:50 PM11/5/10
to Treetop Development
Adding to the list of Treetop grammar's 'in the wild':

I've rounded up my tiny learning experiment, matrix_transformation
DSL. This implementation parses and executes Matrix transformation
statements and arithmetic expressions.

http://github.com/jasim/matrix_transformations

Unlike Aaron's example which cleanly separates parsing from
execution, this one attaches ruby code to the AST nodes.
Reply all
Reply to author
Forward
0 new messages