Sorry for the late reply, but I was only able to get back to this today.
I manage to get it to work, but like this:
eat: bananas* EOF
->^(TRANSLATION_UNIT bananas*)
;
Then your tree rule is:
eat: ^(TRANSLATION_UNIT bananas*)
| TRANSLATION_UNIT
// Empty input
;
Once again thank you,
Rui Vilao
On Tue, Nov 23, 2010 at 6:33 PM, Jim Idle <[email protected]> wrote:
> The code below IS the example J The rule eat is the top level rule for the
> parser and the tree walker.
>
>
>
> Jim
>
>
>
> From: Rui Vilão [mailto:[email protected]]
> Sent: Tuesday, November 23, 2010 6:28 AM
> To: Jim Idle
> Cc: [email protected]
> Subject: Re: [antlr-interest] Allow empty file/input
>
>
>
> Hi,
>
> First of all thanks for the quick reply.
>
> I'm not quite following you. Designing the grammar like you said, I'm
> having
> troubles on the tree grammar side and how I can raise the root object that
> represents my whole language.
>
> Do you haven an example regarding this matter?
>
> Thanks again,
>
> --
> Rui
>
> On Mon, Nov 22, 2010 at 7:23 PM, Jim Idle <[email protected]> wrote:
>
> Looks like your tree grammar does not allow an empty input. I find it
> useful
> to always have a single base node:
>
> eat: b+=bananas+ EOF
>
> ->^(TRANSLATION_UNIT $b*)
> ;
>
> Then your tree rule is:
>
> eat: ^(TRANSLATION_UNIT bananas+)
> | TRANSLATION_UNIT
> // Empty input
> ;
>
>
> Jim
>
>
> > -----Original Message-----
> > From: [email protected] [mailto:antlr-interest-
> > [email protected]] On Behalf Of Rui Vilão
> > Sent: Monday, November 22, 2010 11:03 AM
> > To: [email protected]
> > Subject: [antlr-interest] Allow empty file/input
> >
> > Hi there,
> >
> > I implemented a simple grammar and I want to add support to allow empty
> > input. Empty input can be for example comments too. So I defined it
> > this way
> >
> > eat: (bananas)+
> > |
> > ;
> >
> > bananas: <lots of stuff here>
> >
> > LINE_COMMENT : '//' ~('\r' | '\n')* {skip(); };
> >
> > ETC...
> >
> > The thing is if I put anything that does not match the grammar, i.e.
> > empty string, comment, whatever I get the following error when I try to
> > get the object that will represent my DSL:
> >
> > java.lang.NullPointerException: null
> > at
> > org.antlr.runtime.tree.BaseTreeAdaptor.isNil(BaseTreeAdaptor.java:70)
> > ~[antlr-runtime-3.2.jar:na]
> > at
> > org.antlr.runtime.tree.CommonTreeNodeStream.nextElement(CommonTreeNodeS
> > tream.java:93)
> > ~[antlr-runtime-3.2.jar:na]
> > at
> > org.antlr.runtime.misc.LookaheadStream.fill(LookaheadStream.java:94)
> > ~[antlr-runtime-3.2.jar:na]
> > at
> > org.antlr.runtime.misc.LookaheadStream.sync(LookaheadStream.java:88)
> > ~[antlr-runtime-3.2.jar:na]
> > at
> > org.antlr.runtime.misc.LookaheadStream.LT(LookaheadStream.java:119)
> > ~[antlr-runtime-3.2.jar:na]
> > at
> > org.antlr.runtime.tree.CommonTreeNodeStream.LA(CommonTreeNodeStream.jav
> > a:116)
> > ~[antlr-runtime-3.2.jar:na]
> > at
> > com.feedzai.pulse.service.kpi.parser.KpiTree.script(KpiTree.java:85)
> > ~[classes/:na]
> >
> > Does anyone know how can I achieve this?
> >
> > Thank you in advance,
> >
> > Rui Vilao
> >
>
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> > email-address
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.