[antlr-interest] empty rule catches unthrown RecognitionException

Terence Parr parrt at cs.usfca.edu
Fri Jul 1 18:19:05 PDT 2011


confirmed. let me check.
Ter
On Jul 1, 2011, at 3:48 PM, Trevor John Thompson wrote:

> java -jar /Users/Local/antlr-master-3.4-beta3-completejar.jar Empty.g
> javac -cp /Users/Local/antlr-master-3.4-beta3-completejar.jar EmptyParser.java
> EmptyParser.java:167: exception org.antlr.runtime.RecognitionException is never thrown in body of corresponding try statement
>        catch (RecognitionException re) {
>        ^
> 1 error
> 
> Likewise "beta4".
> TJ
> 
> On 2011 Jul 1, at 15:35, Terence Parr wrote:
> 
>> should be a beta3 or seomthing there.
>> T
>> On Jul 1, 2011, at 3:34 PM, Trevor John Thompson wrote:
>> 
>>> Presuming that "latest beta" is antlr-3.4rc2-complete.jar, i get:
>>> 
>>> java -jar /Users/Local/antlr-3.4rc2-complete.jar Empty.g
>>> javac -cp /Users/Local/antlr-3.4rc2-complete.jar EmptyParser.java
>>> EmptyParser.java:167: exception org.antlr.runtime.RecognitionException is never thrown in body of corresponding try statement
>>>      catch (RecognitionException re) {
>>>      ^
>>> 1 error
>>> 
>>> On 2011 Jul 1, at 15:12, Terence Parr wrote:
>>> 
>>>> i fixed this in latest beta for 3.4...can you try that?
>>>> Ter
>>>> On Jul 1, 2011, at 3:10 PM, Trevor John Thompson wrote:
>>>> 
>>>>> I have a grammar in which i wish to create an imaginary AST node, and then have an action treat that node. The most straightforward expression i have devised is:
>>>>> grammar Empty;
>>>>> options {output=AST;}
>>>>> tokens {Imaginary;}
>>>>> @members {void treat(Object t){}}
>>>>> 
>>>>> parse: empty EOF! {treat($empty.tree);};
>>>>> empty: ->^(Imaginary);
>>>>> 
>>>>> However, the generated EmptyParser.java fails to compile because empty() catches RecognitionException, which is never thrown.
>>>>> 
>>>>> I am working around this by:
>>>>> empty: ->^(Imaginary)|Imaginary;
>>>>> which works because the imaginary token can never be produced by the lexer.
>>>>> 
>>>>> Is there some other way i should be going about this?
>>>>> --
>>>>> Trevor John Thompson    (425) 246-4023
>>>>> net: tijet at me.com
>>>>> Quidquid Latine scriptum sit, altum videtur.
> 
> 



More information about the antlr-interest mailing list