[antlr-interest] Allow empty file/input

Rui Vilão rpvilao at gmail.com
Tue Nov 23 06:28:20 PST 2010


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 <jimi at temporal-wave.com> 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: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Rui Vilão
> > Sent: Monday, November 22, 2010 11:03 AM
> > To: antlr-interest at antlr.org
> > 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
>


More information about the antlr-interest mailing list