[antlr-interest] Weird StringTemplate error on building grammar

Johannes Luber jaluber at gmx.de
Mon Mar 23 08:55:12 PDT 2009


Sam Barnett-Cormack schrieb:
> Jim Idle wrote:
>> Sam Barnett-Cormack wrote:
>>> Terence Parr wrote:
>>>>       
>>>> term+=(~(RSQR|LSQR)))*
>>>>
>>>> is your problem. known bug :)  can't add sets to a list yet.
>>>>     
>>> The full rule is:
>>>
>>> encodingInstruction : (term+=(~(RSQR|LSQR)))* -> ^(ENCINS $term*);
>>>
>>> I read that as
>>>
>>> (
>>>    term+=(
>>>      ~(RSQR|LSQR)
>>>    )
>>> )*
>>>
>>> So the term+= is applying to the *single* (~(RSQR|LSQR)), and the whole 
>>> lot has cardinality zero-to-N. So each iteration adds one thing that is 
>>> anything-but-rsqr-or-lsqr to term, and this happens zero or more times.
>>>
>>> Is this not what it says?
>>>
>>>
>>>   
>> Try something like this:
>>
>> term+=someTerm* ....
>>
>>
>> someTerm
>>     : ~(RSQR|LSQR)
>>     ;
> 
> Ah, excellent, thanks. After resolving yet-another inherent ambiguity in
> the language ('tag' is a subset of 'encodingPrefix'), it now builds
> fine. I think I now have all of the inherent ambiguities sorted, and no
> disastrous shortcuts (like arbitrary backtracking) - until I try to add
> in support for "information objects" and parametrized types...
> 
> This has been a great learning experience, and thanks to all who've
> helped with my getting to grips with practical language implementation
> stuff. I'm sure I'll need more help when it comes to acting on the AST...
> 
> One question though - how come such effectively equivalent constructs
> produce such different results?

Because there are bugs hiding there.

Johannes

> 
> Sam
> 
> 
> 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