[antlr-interest] Crash on rewrite
Terence Parr
parrt at cs.usfca.edu
Wed Mar 14 10:48:16 PDT 2007
Hi. I added a bug for this:
http://www.antlr.org:8888/browse/ANTLR-92
Ter
On Mar 10, 2007, at 10:18 AM, Mark Bednarczyk wrote:
> I've stumbled onto the fact that if I assign a label to the option
> productions, it works:
>
> number
> : h=Hex (s='l' | s='L') -> ^(INT64)
> ;
>
> With the labels in place ANTLR compiles the expression, and it works
> correctly.
>
> The above expression was greatly simplified to make a point, the
> actual
> rewrite is much more complex. But it all works correctly:
>
> snip...
> | h=Hex (s='l' | s='L')? il32=isuLarge32
> -> ^({adaptor.create(($s != null?INT64:INT32),
> NplUtils.toDec($h.text, $il32.text))})
>
> | h=Hex (s='l' | s='L')? il64=isuLarge64
> -> ^({adaptor.create(($s != null?INT64:INT32),
> NplUtils.toDec($h.text, $il64.text))})
>
> // Hexadecimal form 0x<VALUE>
> | h=HexLiteral (s='l' | s='L')?
> -> ^({adaptor.create(($s != null?INT64:INT32),
> NplUtils.toDec($h.text, 16, 2))})
>
> // Anybase form of <BASE>_<VALUE>
> | a=AnyBase (s='l' | s='L')? il32=isuLarge32
> -> ^({adaptor.create(($s != null?INT64:INT32),
> NplUtils.toDec($a.text, $il32.text))})
>
> | a=AnyBase (s='l' | s='L')? il64=isuLarge64
> -> ^({adaptor.create(INT64, NplUtils.toDec($a.text,
> $il64.text))})
> snip...
> isuLarge32
> : 'bit' | 'bits' // 1
> | 'nibble'| 'nibbles'// 4
> | 'byte' | 'bytes' // 10e1
> | 'deca' // 10e1
> | 'hecto' // 10e2
> | 'kilo' | 'Kibit' // 10e3 & IEC kibibit
> | 'mega' | 'Mibit' // 10e6 & IEC mebibit
> ;
> isuLarge64
> : 'giga' | 'Gibit' // 10e9 & IEC gibibit
> | 'tera' | 'Tibit' // 10e12 & IEC tebibit
> | 'peta' | 'Pibit' // 10e15 & IEC pebibit
> | 'exa' | 'Eibit' // 10e18 & IEC exbibit
> | 'zetta'| 'Zibit' // 10e21 & IEC zebibit
> | 'yotta'| 'Yobit' // 10e24 & IEC yobibit
> ;
>
> Cheers,
> mark....
>
>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org
>> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Mark
>> Bednarczyk
>> Sent: Saturday, March 10, 2007 7:57 AM
>> To: 'ANTLR Interest'
>> Subject: [antlr-interest] Crash on rewrite
>>
>> Anyone know why this throws an exception everytime:
>>
>> [antlr:antlr3] ANTLR Parser Generator Version 3.0b6 (Jan 31, 2007)
>> 1989-2007
>> [antlr:antlr3] error(10): internal error:
>> C:\jnetstream\NplLanguage\src\antlr\Npl.g :
>> java.lang.IllegalArgumentException: Can't find template
>> matchSetTrack.st [antlr:antlr3]
>> org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(St
>> ringTemplateGr
>> oup.java:485)
>> [antlr:antlr3]
>> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(Str
>> ingTemplateGro
>> up.java:372)
>> [antlr:antlr3]
>> org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(Str
>> ingTemplateGro
>> up.java:384)
>> ...
>>
>> On the following PARSER rule::
>>
>> number
>> : h=Hex ('l'|'L') -> ^(INT64)
>> ;
>>
>>
>> When its broken out, it works fine::
>>
>> number
>> : h=Hex 'l' -> ^(INT64)
>> | h=Hex 'L' -> ^(INT64)
>> ;
>>
>> Without the rewrite part '->' the combined rule matches as
>> expected. Only throws exception when the rewrite is present.
>>
>> I've tried everything I know and started breaking all the
>> rules out in to sperate lines, but that produces a lot of
>> redundancy in the generated code.
>>
>> Cheers,
>> mark...
>>
>>
>>
>
>
More information about the antlr-interest
mailing list