Hopefully updating the tokenizer and parser should be fairly obvious.  Once 
you've done that you'll need to actually implement the operators themselves.  
If the implementation of these operators is effectively exactly the same as the 
normal binary operators it should be pretty easy - you just need to add a new 
value to PythonOperationKind and PythonOperator, update Symbols.Generated.cs so 
it maps to the __*__ methods, and update BinaryExpression so 
PythonOperatorToAction maps between PythonOperator and PythonOperationKind.  By 
"exactly the same" I mean try __*__ on the LHS if RHS is not a subclass of RHS, 
__r*__ on the RHS, check for not-implemented, support coercion, etc...

If you wanted to define your unique behavior for the operations you could just 
change BinaryExpression.cs to generate whatever code you want.  That could even 
be as simple as calling into a method in PythonOps that figures out what to do. 
 Or you could create a new DynamicMetaObjectBinder subclass which does some 
custom binding which gets cached and runs fast.  If you want to go that for you 
should take a look at some of the existing binders in 
IronPython.Runtime.Binding.  The PythonProtocol class has the implementation of 
binary operators, unary operators, and indexing - I'd suggest looking at unary 
as they're the simplest (binary's quite complex, but hopefully you don't need 
to go this far).

From: [email protected] 
[mailto:[email protected]] On Behalf Of Tristan Zajonc
Sent: Monday, February 15, 2010 11:24 AM
To: [email protected]
Subject: [IronPython] Adding new infix operators to IronPython

Hi,

I'm interested in experimenting with adding new infix operators to IronPython 
to support objectwise and elementwise operators. PEP 225
(http://www.python.org/dev/peps/pep-0225/) describes the potential use cases 
for such operators. Matlab style matrix operations are the chief example.  
Clearly new operators won't be added to Python any time soon, but I am 
interested in exploring the issue nonetheless.

Before diving in, I am wondering if there are any helpful pointers more 
experienced IronPython developers can offer about adding new syntax to 
IronPython.  Is there an overall strategy I should obviously be following?

Tristan
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to