[antlr-interest] Why and how exactly does ANTLR manage to fail on non recursive grammar for finite language?

Sam Barnett-Cormack s.barnett-cormack at lancaster.ac.uk
Thu Aug 13 02:34:32 PDT 2009


Nikolay Ognyanov wrote:
> Well, there is nothing else that the extra SUFFIX can belong to 
> according to the
> grammar so this is not derivation/parsing of the statement per the grammar.

ANTLR makes no assumptions where to stop, as when it is in a "deeper" 
rule, it does not know what path it took. The generated code for expr2 
can't tell whether it's possible that it will be followed by a SUFFIX 
(it's 'follow set' is undetermined). There's no real concept of a "start 
rule" definable in a grammar, although inclusion of EOF makes some 
improvements.

> Loring Craymer wrote:
>> Not true; your example can be interpreted either as
>>
>> (expr1:  PREFIX_1 (expr2:  PREFIX_2 SUFFIX) SUFFIX )
>>
>> or as
>>
>> (expr1:  PREFIX_1 (expr2:  PREFIX_2) SUFFIX) SUFFIX
>>
>> with the extra SUFFIX belonging to something else
>>
>> --Loring

-- 
Sam Barnett-Cormack


More information about the antlr-interest mailing list