Parser project

Huaiyu Zhu hzhu at localhost.localdomain
Mon Jul 17 16:37:59 EDT 2000


On Mon, 17 Jul 2000 14:43:01 -0500, Paul Prescod <paul at prescod.net> wrote:
>Here is a project for a parser hacker:

This is a good idea, although MatPy could not wait for it to happen, and I
do not foresee much additional syntax being requested. For the current
matrix issue, a limited parser might be easier and more useful.

The only bottleneck here is that the supply of binary infix operators is
very limited, unlike function or method names.  This forces people to write
latter when the former is much cleaner.  Why not write a parser that changes
nothing else but allows additional binary operators?  By definition, it
would put all the special symbols stuck together as operators, like +=, -=,
:=, @+, .*, @*=, etc.

Someone had proposed allowing general forms

a op b

but I would think limiting op to consisting only the symbols that are not in
other syntax constructs (like parenthesis, numbers, names, etc) is
warranted.  This would still give quite a few dozen operators, far more than
needed, imo.

I'm not sure if it can be made as easy as

import NewOperator
NewOperator.define(".+", "__dotadd__")
class A: def __dotadd__(self, other) ...
a=A(); b=A()
a.+b
NewOperator.define("compares", "__cmp__") 
 ------> Exception: "compares" contains characters not allowed in operator.

That would be useful in many domains.


Huaiyu



More information about the Python-list mailing list