[antlr-interest] disabling portions of a rule?
Hill, Robert
rhill03 at eds.com
Mon Oct 30 23:13:50 PST 2006
Thanks Loring, I've already gone with the re-throwing of the
failedPredicate Exception, its not really nescessary that I continue,
since the problem with the parsed file is a fatal error at this point
anyway. I didn't think about using a predicate for 2 rules, one being
empty - neat another tool to remember!.
I see now why we cant skip nodes(I'd used that in V2 so wondered why,
but have been too busy using it to pay attention as to the reasons why
:) )
Thanks for the explanation, it all makes sense now!
Cheers!
Rob
Robert Hill
Information Engineer
EDS UKIMEA DWP ACU, Hallamshire Business Park, 100 Napier St,
Sheffield. S11 8HD
email: rhill03 at eds.com
Office: +44 114 291 1928
Mobile: +44 7903 185 516
>-----Original Message-----
>From: antlr-interest-bounces at antlr.org
>[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Loring Craymer
>Sent: 31 October 2006 02:12
>To: Robert Hill; 'ANTLR Interest'
>Subject: Re: [antlr-interest] disabling portions of a rule?
>
>ANTLR 3 does an inorder traversal of the tree being walked;
>shortcuts are not supported. This is different from ANTLR 2,
>where you could match a node and then ignore its children (and
>siblings). The big gain for the inorder traversal is that you
>can support
>k>1 for tree walkers. A secondary benefit is that you
>get strong checking of tree structure, but that is
>counterbalanced by the inability to do shortcutting.
>[I consider this a gain, but I start with automtically
>generated tree grammars.]
>
>The best you can do right now is to have two versions of the
>subrule--one with actions and one without--and use the sempred
>to pick which one to use.
>
>--Loring
>
>--- Robert Hill <rob.hill at blueyonder.co.uk> wrote:
>
>> Hi all,
>> I Have a rule like this
>>
>> exampleRule
>> @init {
>> Symbol s = null;
>> }
>> : ^(MAP Identifier { s =
>> Symbol.Resolve($Identifier.text);
>> if (s==null)
>> ShowError();
>> }
>> ({s==null}? Subrule[s]);
>> )
>>
>> So , basically if the identifier isn't in the symbol table we don't
>> call the subrule. The predicate does the job but when a symbol isn't
>> found I get a whole bunch of errors about mismatched tree nodes..
>> - how do I either
>>
>> a) exit the rule early without displaying the antlr errors, or
>> b) consume the tokens that follow even though I cant call
>the subrule
>> to get rid of them?
>>
>> The subrule assumes it will always be passed a valid symbol, and has
>> quite a few alts in it, so I don't want to add a if
>> (s!=null) before all of the code
>> in the subrule.
>> I'd like to prevent antlr from showing its mismatched tree errors,
>> whilst preferably not exiting with a null pointer exception from
>> within the subrule...
>>
>> Whats the neat/preferable way of handling this?
>> Cheers!
>>
>> Rob
>>
>>
>>
>>
>>
>
>
>
>
>_______________________________________________________________
>_____________________
>Cheap Talk? Check out Yahoo! Messenger's low PC-to-Phone call rates
>(http://voice.yahoo.com)
>
>
More information about the antlr-interest
mailing list