[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

TreeTop help?

Day

2/9/2008 8:26:00 PM

So I'm building a parser, and I thought I'd give TreeTop a go. I
recently got Practical Ruby Projects from Apress and worked through
the last chapter, so I feel like I have somewhat of an understanding
of what's going on, but I'm having a weird issue. It is apparent to me
that the order you define rules in TreeTop matters.

The stuff I'll be parsing (somewhat simplified) looks like this:

Item, name(value), name(value), name(value)...etc.

Here's my grammar and test script: http://pastie.caboo...

This fails. If I comment out the item and item_name rules and then
change the string to be parsed to just 'bar(1), baz(14)' it works. i
can't figure out what the order of the rules might imply (if I reorder
them, it breaks again). Any help or pointing at some documentation
more in-depth than that found on the TreeTop site would be much
appreciated. Thanks.


Ben

6 Answers

Daniel Brumbaugh Keeney

2/10/2008 2:27:00 AM

0

On Feb 9, 2008 2:25 PM, Day <iamday@gmail.com> wrote:

It looks like a simple typo to me

rule item_name
[a-zA-Z]+
end


Daniel Brumbaugh Keeney

Day

2/10/2008 5:02:00 AM

0

On Feb 9, 2008 8:27 PM, Daniel Brumbaugh Keeney
<devi.webmaster@gmail.com> wrote:
> It looks like a simple typo to me
>
> rule item_name
> [a-zA-Z]+
> end
>
>
> Daniel Brumbaugh Keeney

Wow. That's how awesome I am. At life. Heh. Thanks man. Good eye.

The ordering of things DOES matter, right? Or am I hallucinating?


Ben

Clifford Heath

2/10/2008 6:19:00 AM

0

Day wrote:
> The ordering of things DOES matter, right? Or am I hallucinating?

The ordering of rules in a grammar doesn't matter at all.
The compiler processes each rule into a method (and some
modules that extend objects created in that method), and
it does that without considering the existence of any other
rule. Just as order of def's in a class doesn't matter, the
order of rules in a grammar doesn't matter.

On the other hand, the order of alternatives within a rule
does matter. Once one alternative succeeds, even if it leaves
the input at a point where the calling rule cannot succeed,
no other alternative will ever be tried. You may need to use
lookahead to prevent this happening.

Finally, the success of one item in a sequence is final. If
the path chosen prevents following items in that sequence to
fail, the previous item will never be revisited, and the whole
sequence will fail. Again, you might need to use lookahead
to prevent this - especially to place limits on repetition.

This is looking like becoming an FAQ, and I hope I'm getting
better at stating it succinctly. I also hope Google starts
finding it, so I don't have to :-).

Clifford Heath.

Daniel Brumbaugh Keeney

2/10/2008 11:07:00 AM

0

On Feb 10, 2008 12:20 AM, Clifford Heath <no@spam.please.net> wrote:

> This is looking like becoming an FAQ, and I hope I'm getting
> better at stating it succinctly. I also hope Google starts
> finding it, so I don't have to :-).
>
> Clifford Heath.
>

There's been quite a bit of talk about Treetop on this list lately,
seeing as it has no mailing list, feel free to join
irc://irc.freenode.net/#treetop


Daniel Brumbaugh Keeney

Patrick

7/9/2011 9:25:00 PM

0

"The_Echo_Chamber" <echochamber26@yahoo.com> wrote

> >I studied the original texts, dook. And, they too are proof of faux
> >christian behavior such as yours.
>
> What "original texts" are those? And while you are fabricating your lies,
> why
> don't you reveal what "faux Christian behavior" I'm doing.
>

How many times must you be told about your sinning dookie??

+ There he goes again...
+ Talking out of his ass.
+ It is time for you to change your name again, and go hide
for a few months. Come back with a better whine when you do come back.


The_Echo_Chamber

7/10/2011 5:07:00 PM

0

On Jul 9, 5:24 pm, "Patrick" <barker...@erinot.com> wrote:
> "The_Echo_Chamber" <echochambe...@yahoo.com> wrote
>
> > >I studied the original texts, dook. And, they too are proof of faux
> > >christian behavior such as yours.
>
> > What "original texts" are those? And while you are fabricating your lies,
> > why
> > don't you reveal what "faux Christian behavior" I'm doing.
>
> How many times must you be told about your sinning dookie??
>
> + There he goes again...
> + Talking out of his ass.
> + It is time for you to change your name again

I don't play those childish games...