[antlr-interest] Check if rule returns empty result
Jim Idle
jimi at temporal-wave.com
Fri Nov 4 09:30:05 PDT 2011
The information I gave you still applies though as it concerns the
structure of the tree.
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Christian
> Sent: Thursday, November 03, 2011 10:51 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Check if rule returns empty result
>
> Thank you for your hint, but I do not use tree grammars mainly because
> of Andy Tripp's article:
> http://www.antlr.org/article/1170602723163/treewalkers.html
>
> I walk through the tree by means of the visitor pattern instead. Main
> reasons for me to be against tree grammars:
>
> * Code/rule duplications, especially I have to know how the AST looks
> like.
> * No syntax check, code highlight, and code assistant in actions,
> especially the programming language is mixed with the tree grammar
> syntax.
>
>
> Christian
>
> Am 04.11.2011 00:22, schrieb Jim Idle:
> > Remember that your tree parser rule for the body should be:
> >
> > method_body
> > : ^(METHOD_BODY statement_list)
> > | METHOD_BODY // Empty body
> > ;
> >
> > Jim
> >
> >> -----Original Message-----
> >> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> >> bounces at antlr.org] On Behalf Of Christian
> >> Sent: Thursday, November 03, 2011 2:37 PM
> >> To: antlr-interest at antlr.org
> >> Subject: Re: [antlr-interest] Check if rule returns empty result
> >>
> >> Thank you for your explanation. And your solution works great, too.
> >>
> >> Christian
> >>
> >> Am 03.11.2011 21:31, schrieb Jim Idle:
> >>> You don't want that anyway as your nodes will not have token start
> >> and
> >>> stop information and you might need that.
> >>>
> >>> method_declaration
> >>> : method_header method_body
> >>> ;
> >>>
> >>> method_body
> >>> : (
> >>> ';'!
> >>> | '{'! statement_list? '}'!
> >>> )
> >>> -> ^(METHOD_BODY statement_list?)
> >>> ;
> >>>
> >>> method_header
> >>> : attributes ID etc
> >>>
> >>> ->^(METHOD_HEADER attributes ID )
> >>> ;
> >>>
> >>>
> >>> Jim
> >>>
> >>>> -----Original Message-----
> >>>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> >>>> bounces at antlr.org] On Behalf Of Christian
> >>>> Sent: Thursday, November 03, 2011 1:01 PM
> >>>> To: antlr-interest at antlr.org
> >>>> Subject: [antlr-interest] Check if rule returns empty result
> >>>>
> >>>> Hi at all,
> >>>>
> >>>> I have the following rules:
> >>>>
> >>>> method_declaration
> >>>> : method_header method_body -> ^(METHOD_HEADER method_header)
> >>>> ^(METHOD_BODY method_body)
> >>>> ;
> >>>>
> >>>> method_body:
> >>>> ';'!
> >>>> | '{'! statement_list? '}'!;
> >>>> ;
> >>>>
> >>>> Of course, method_body is executed because it has no question
> mark.
> >>>> However, introducing rewrite rules and operators cause a problem.
> >>>> By using ^(METHOD_BODY method_body), method_body must return a
> non-
> >> empty
> >>>> value. However, statement_list? is optional and thus may not match
> >> at
> >>>> all. In this case, method_body returns nothing anymore and I get
> an
> >>>> RewriteEmpty exception.
> >>>>
> >>>> How can I solve this problem by only changing rewrite rules?
> >>>>
> >>>> Regards,
> >>>> Christian
> >>>>
> >>>> 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
> >
>
>
> 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