[antlr-interest] Python target @members problem

Henrique hjrnunes at student.dei.uc.pt
Wed Sep 17 19:35:28 PDT 2008


Hi everyone!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.
Thanks in advance.

Henrique Nunes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080918/70362aba/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cfdg_py.g
Type: application/octet-stream
Size: 3143 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080918/70362aba/attachment.obj 


More information about the antlr-interest mailing list