Using PLY

Maurice LING mauriceling at acm.org
Mon Sep 20 01:10:40 CEST 2004


> 
> The tokenize module would definitely be simpler if it's Python code
> that he happens to be parsing.  If it's not Python code, then there's
> still a reason to use PLY..
>  
Thanks, I'm not parsing Python codes for sure and so, it is a good 
reason to use PLY.

Another thing that I am quite puzzled by is the yacc part of PLY. Most 
of the examples are showing calculators and the yacc part does the 
calculations such as,

    def p_expression_group(self, p):
         'expression : LPAREN expression RPAREN'
         p[0] = p[2]

this is a bad example, I know. But how do I get it to output some 
intermediate representations, like AST, or an intermediate code 
(byte-code type).

Is

    def p_expression_group(self, p):
         'expression : LPAREN expression RPAREN'
         p[0] = p[2]
	print "byte_x" + p[0]

or something like this legal?

I hope that I am clear about what I am trying to say.

Thanks in advanced
Maurice



More information about the Python-list mailing list