Treetop hanging on parse of a simple grammar...

51 views
Skip to first unread message

Sonny Chee

unread,
Aug 23, 2016, 4:31:03 PM8/23/16
to Treetop Development
Hey Guys,

I've put together a simple grammar that appears to hang.  I'm new to PEGs, so I'm guessing I've violated some basic rule of well-formed PEG.... If someone can point me in the right direction, that would be greatly appreciated.

I've attached the three files that comprise my app.  I invoke the parser with:

ruby my_narp_parser.rb "INPUT myfile seq"

The issue appears to be the rule

rule
        'INPUT'i space f_identifier attribute* <Input>
end

When I remove the * quantifier on attribute (or replace it with ?), the parser completes successfully.
my_narp_parser.rb
narp.treetop
node_extensions.rb

markus

unread,
Aug 23, 2016, 4:43:48 PM8/23/16
to treet...@googlegroups.com
I'm not where I can test or look at it in detail, but at a glance I'd
suspect that the problem is that your definition of "attribute" accepts
empty strings. Thus the string you are trying to parse contains an
infinite number of valid attributes, all but the first of which are zero
characters long.

-- Markus


Sonny Chee

unread,
Aug 23, 2016, 5:53:55 PM8/23/16
to Treetop Development
 Hey Markus,

My defintion for attribute follows:

    rule attribute
        storage?       <Attribute>
    end

    rule storage
        'seq'i space? <Storage>
    end

So I think my grammar specifies that attribute may optionally consist of the string 'seq'.  I don't think there's anything in this specification that says accept empty string... is there?

markus

unread,
Aug 23, 2016, 6:17:22 PM8/23/16
to treet...@googlegroups.com

> My defintion for attribute follows:
>
> rule attribute
> storage? <Attribute>
> end
>
> rule storage
> 'seq'i space? <Storage>
> end
>
> So I think my grammar specifies that attribute may optionally consist
> of the string 'seq'. I don't think there's anything in this
> specification that says accept empty string... is there?

If the "seq" is optional, that means it's ok for it to be absent. And
if it's absent the attribute consists of the empty string. So that rule
says that an attribute can be an empty string.

You probably don't want or need the "?" after storage, and (unless you
plan to have other attributes) you may not even need the attribute
rule--if storage is the only possibility you may just want to specify
storage instead of attribute in the rule above.

-- Markus


Sonny Chee

unread,
Aug 23, 2016, 7:07:56 PM8/23/16
to Treetop Development
Thanks for the detailed explanation, Marcus.  Much appreciated.
Reply all
Reply to author
Forward
0 new messages