On Feb 25, 11:53 am, [EMAIL PROTECTED] wrote:
> > { '+': operator.add, '-': operator.sub, ... }
>
> Then EXPR OPER EXPR -> ops[ OPER ]( EXPR, EXPR ), right?
I think this is the most Pythonic idiom. You can even define your own
custom binary operators, such as '$' to convert dollars and cents to
> { '+': operator.add, '-': operator.sub, ... }
Then EXPR OPER EXPR -> ops[ OPER ]( EXPR, EXPR ), right?
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] a écrit :
> My parser has found an expression of the form CONSTANT_INTEGER
> OPERATOR CONSTANT_INTEGER. I want to fold this into a single
> CONSTANT_INTEGER.
>
> The OPERATOR token has an intValue attribute, '+' == 0, '-'== 1, etc.
> In C I'd put functions Add, Subtract, ... into
[EMAIL PROTECTED] wrote:
> My parser has found an expression of the form CONSTANT_INTEGER
> OPERATOR CONSTANT_INTEGER. I want to fold this into a single
> CONSTANT_INTEGER.
>
> The OPERATOR token has an intValue attribute, '+' == 0, '-'== 1, etc.
> In C I'd put functions Add, Subtract, ... into a