[antlr-interest] Weird StringTemplate error on building grammar

Sam Barnett-Cormack s.barnett-cormack at lancaster.ac.uk
Mon Mar 23 05:19:14 PDT 2009


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?

Sam



More information about the antlr-interest mailing list