History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: ANTLR-46
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Kay Röpke
Reporter: Kay Röpke
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ANTLR v3

missing attribute translation when using rulerefs w/out labels

Created: 22/Nov/06 10:36 AM   Updated: 22/Nov/06 04:56 PM
Component/s: ANTLR Core
Affects Version/s: 3.0b5
Fix Version/s: 3.0b5


 Description  « Hide
grammar WrongTranslation;

rule1 returns [ Object obj ]
: rule2 { $obj = $rule2.obj; }
| rule3 { $obj = $rule3.obj; }
| rule4 { $obj = $rule4.obj; }
;

rule2 returns [ Object obj ]
: foo='foo' { $obj = $foo.text; }
;

rule3 returns [ Object obj ]
: bar='bar' { $obj = $bar.text; }
;

rule4 returns [ Object obj ]
: baz='baz' { $obj = $baz.text; }
;


results in

 case 2 :
                    // /Users/kroepke/test/WrongTranslation.g:5:4: rule3
                    {
                    pushFollow(FOLLOW_rule3_in_rule122);
                    rule3();
                    _fsp--;

                     obj = $rule3.obj;

                    }
                    break;

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Kay Röpke - 22/Nov/06 04:10 PM
There is a potential problem with rules like the above.

The CodeGenerator will make up a variable name for the rule refs in rule1.
It does this by simply appending a number to the rule name, which could result in doubly used vars in the generated code.
This is contrived, but is a potential pitfall that would be very hard to track.
See CodeGenerator.createUniqueLabel

Kay Röpke - 22/Nov/06 04:56 PM
fixed by change 3274