[antlr-interest] Some bugs (or features?) in Honey Badger

Terence Parr parrt at cs.usfca.edu
Sun Feb 19 13:33:46 PST 2012


On Feb 19, 2012, at 7:52 AM, Jan Finis wrote:

> Hi folks, hi Ter,
> 
> I discovered the following things while using Honey Badger. They seem 
> like bugs to me but maybe they are features or I got something wrong:
> 
> 1. Alternative precedence:
> 
> Consider the following left recursive rule for expressions:
> 
> expr
>     : ID '=' expr;
>     | ID
>     | expr '+' expr;
> 
> ID : 'a' ;

Hi. this suprising me. It translates to:

expr[int _p]
    :   ( ID '=' expr[3] 
        | ID 
        )
        ( {1 >= $_p}? '+' expr[2]
        )*
    ;

(See -Xlog option).  Pretty hard for that to match as a=(a+a). are you sure?

> 
> the precedence should be from top to bottom, right? So, the input  a=a+a 
> should be parsed as (a=a)+a, since the assignment rule is on the top. 
> However, this is not the case, instead, it is parsed as a=(a+a). Bug, or 
> am I interpreting something wrong?
> 
> 2. Name binding
> 
> Consider this example:
> 
> expr returns [int r]
>     : '-' expr { $r = - $expr.r; }
> 
> In this example $expr should bind to the sub-expression in my opinion. 
> However, it does not. Since the rule is also named expr, $expr refers to 
> the rule context instead of the context of the sub-expression. I think 
> most of the time this is not what the user wants.

I think this is consistent with v3. i'll add to list to think about. thanks!
Ter


More information about the antlr-interest mailing list