Hi everyone!Thanks Matt and Ben! I got it now! I've now finished my parser
and I can move on! Thank you!
Cheers!
Henrique Nunes
On Fri, Sep 19, 2008 at 9:38 PM, Henrique <[EMAIL PROTECTED]> wrote:
> Hi everyone!Thanks Matt and Ben! I got it now! I've now finished my parser
> and I can move on! Thank you!
> Cheers!
>
> Henrique Nunes
>
>
>
> On Fri, Sep 19, 2008 at 7:57 PM, Benjamin Niemann <[EMAIL PROTECTED]> wrote:
>
>> Hi Henrique,
>>
>> On Thu, Sep 18, 2008 at 4:35 AM, Henrique <[EMAIL PROTECTED]>
>> wrote:
>> > I'm building a parser that should generate python code. The problem is
>> that
>> > the variables that I define in the @members section are not recognized
>> in
>> > the rules themselves.
>> > For instance, I have this:
>> > grammar cfdg_py;
>> > options{
>> > language=Python;
>> > }
>> > ...
>> > @members {
>> > names=[]
>> > rule_name = []
>> > }
>> > ...
>> > rule
>> > @init{
>> > rule_name=[]
>> > print "NEW RULE"
>> > }
>> > @after{
>> > names.append(rule_name)
>> > print "END RULE: " + str(names)
>> > }
>> > : RULE USER_STRING (USER_RATIONAL)? LEFTBRACKET buncha_replacements?
>> > RIGHTBRACKET {rule_name.append($USER_STRING.text);}
>> > ;
>> > I get a NameError: global name 'names' is not defined in the first line
>> of
>> > the @after section.
>> > How do I make sure the variables are defined?
>> > I've tried inserting the semicolons as advised in the wiki but it didn't
>> > work. The antlr python documentation is really scarce so I can't figure
>> it
>> > out.
>> > I'm attaching the whole grammar with this. Using ANTLR 3.1 on Windows.
>>
>> Things are a little bit different in Python than for Java. For
>> instance attributes you have to use @init, e.g.
>>
>> @init {
>> self.name = []
>> self.rule_name = []
>> }
>>
>> And when referencing those, you have to use self.name etc.
>> @members can be used for class attributes and member functions.
>>
>> -Ben
>>
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address