Operators for matrix: current choices (Was Matlab vs Python ...)

Denys Duchier Denys.Duchier at ps.uni-sb.de
Wed Jul 19 15:00:55 EDT 2000


wtanksle at dolphin.openprojects.net (William Tanksley) writes:

> >1. Make a pure python way to introduce additional operators, like
> >   import NewOperator
> >   NewOperator.define(".+", "__dotadd__")
> >   NewOperator.define("+=", "__add_ab__")
> >   NewOperator.define(":=", "__copy__")
> 
> This isn't feasable -- it would require modifying the lexer and parser at
> runtime, which would be a MAJOR change and can have unpredictable results.
> (You know what I mean if and only if you've ever written a compiler with a
> grammar.)

I know what you mean, and it's simply not true.  What it takes is
simply to express the grammar in terms of operator precedence levels
rather than in terms of specific operators.  Thus your grammar has a
fixed number of predefined operator levels and corresponding rules
involving BINOP_LEVEL_1, BINOP_LEVEL_2, etc...  Only the lexer needs
to be able to be parametrized in terms of the operators that it needs
to recognize.  Typically this is done with a table and a greedy
algorithm which recognizes the largest operator present in the table.

I am, of course, not making any claims as to the
applicability/feasability/desirability of this approach for Python :-)

Sincerely,

-- 
Dr. Denys Duchier			Denys.Duchier at ps.uni-sb.de
Forschungsbereich Programmiersysteme	(Programming Systems Lab)
Universitaet des Saarlandes, Geb. 45	http://www.ps.uni-sb.de/~duchier
Postfach 15 11 50			Phone: +49 681 302 5618
66041 Saarbruecken, Germany		Fax:   +49 681 302 5615



More information about the Python-list mailing list