Related articles |
---|
parsing with user defined operators rwg@exoterica.com (1999-08-12) |
Re: parsing with user defined operators torbenm@diku.dk (Torben Mogensen) (1999-08-13) |
Re: parsing with user defined operators mfinney@lynchburg.net (1999-08-15) |
Re: parsing with user defined operators Andrew.Walker@nottingham.ac.uk (Dr A. N. Walker) (1999-08-27) |
Re: parsing with user defined operators rspartan@my-deja.com (rspartan) (1999-08-27) |
Re: parsing with user defined operators darcy@moa.CS.Berkeley.EDU (1999-08-28) |
From: | darcy@moa.CS.Berkeley.EDU (Joseph D. Darcy) |
Newsgroups: | comp.compilers |
Date: | 28 Aug 1999 02:11:24 -0400 |
Organization: | University of California at Berkeley |
References: | 99-08-053 99-08-097 |
Keywords: | syntax, design |
>Our esteemed moderator writes:
>> [It shouldn't be hard to concoct an operator precedence parser that can
>> do that, but I don't think it's a very good idea. User extensible syntax
>> was fashionable 20 years ago but now nobody bothers because it's so
>> phenomenally confusing. [...]]
[snip]
"Dr A. N. Walker" <Andrew.Walker@nottingham.ac.uk> writes:
> User-defined and overloaded operators are *incredibly*
>useful to certain classes of users. In mathematics, if we invent
>some new class of object, and if two of those objects can
>plausibly be added, then we naturally use the "+" symbol to
>denote the addition: "A := B*C + D", not
>[I agree that overloading can be very useful, but if you start inventing
>new syntax with unpredictable precedence, your programs become completely
>unreadable. (I speak from experience here.) C++ for example lets you
>overload with wild abandon, but the syntax is utterly unchangable. -John]
My master's project, Borneo
(http://www.cs.berkeley.edu/~darcy/Borneo), contains a proposal for
allowing user-defined operators while trying to prevent the program
from becoming confusing. Briefly, if a prefix of a user-defined
operator matches a built-in operator, the user-defined operator has
the same precedence and associativity as the corresponding built-in
operator. For example, "+^" and "+_" would both have the precedence
and associativity of "+". Therefore, the compiler and the programmer
can parse expression without having to perform type-checking or see
the operator declarations. There are some restrictions to prevent
syntactic mishaps; for example, the strings delimiting comments can't
appear in user-defined operators and user-defined operators can't have
a suffix matching the text of a unary operator (this prevents
whitespace from affecting how operators are tokenzied).
-Joe Darcy
darcy@cs.berkeley.edu
Return to the
comp.compilers page.
Search the
comp.compilers archives again.