home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.edu:1639 comp.lang.fortran:3536 comp.lang.misc:3047 comp.arch:9385 sci.math:11336
- Path: sparky!uunet!usc!sdd.hp.com!uakari.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!ogicse!orstcs!orstcs!usenetusenet
- From: crowl@jade.CS.ORST.EDU (Lawrence Crowl)
- Newsgroups: comp.edu,comp.lang.fortran,comp.lang.misc,comp.arch,sci.math
- Subject: User-Defined Operators (was: Scientists as Programmers (was: Small Language Wanted))
- Message-ID: <1992Sep13.022830.2046@CS.ORST.EDU>
- Date: 13 Sep 92 02:28:30 GMT
- Article-I.D.: CS.1992Sep13.022830.2046
- References: <Bu08uF.HBC@mentor.cc.purdue <KERS.92Sep4154056@cdollin.hpl.hp.com> <135691@lll-winken.LLNL.GOV>
- Sender: usenet@CS.ORST.EDU
- Distribution: na
- Organization: Oregon State University, Corvallis Oregon
- Lines: 45
- Nntp-Posting-Host: jade.cs.orst.edu
-
- In article <135691@lll-winken.LLNL.GOV>
- blair@lll-crg.llnl.gov (Gary Blair) writes:
- >In article <KERS.92Sep4154056@cdollin.hpl.hp.com>
- kers@hplb.hpl.hp.com (Chris Dollin) writes:
- >>In article ... fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- >>
- >> C++ allows you to overload existing operators, although to make compiler
- >> writer's jobs easier, it does not allow you to introduce new operators.
- >>
- >>Make that ``trivially easier''. So far as I am able to tell, the difficulty of
- >>allowing the user to add new operator definitions is rather close to zero, so
- >>long as this is taken into account *before* designing the language and
- >>compiler. (C++ has the problem of trying to incorporate the lexical structure
- >>of C.)
- >
- >Wrong. If your compiler uses ANY kind of table-driven parsing scheme, it is
- >next to impossible to allow programmer-defined operators. The parser must
- >know what an operator looks like, and what precedence it has with respect
- >to all other operators. This is usually predetermined, at
- >compiler-generation time.
-
- That last statement is _wrong_. It is _easy_ to add user-defined operators to
- a language. The attributes sufficient to make it easy are:
-
- operators must be lexically distinct
- just like identifiers are not predefined, but are lexically distinct,
- so too can operators be lexically distinct
- the operator precedence relationships must be static
- this is true in languages like C where all the operators are fixed,
- and therefore all the precedences are fixed
- the operator precedence must be lexically determined
- this is easy if you incorporate symbol table information into the
- lexer so that on finding an operator, it looks up the precedence
-
- I designed and implemented a simple language that permits user-defined
- infix and postfix operators and built the parser with lex and yacc. My job
- was a little simpler than the above in that all operators had equal
- precedence, which meant that my symbol table only had to identify the operator
- as defined (like an identifier) and did not have to provide a precedence.
- Adding a precedence is simple.
-
- --
- Lawrence Crowl 503-737-2554 Computer Science Department
- crowl@cs.orst.edu Oregon State University
- ...!hplabs!hp-pcd!orstcs!crowl Corvallis, Oregon, 97331-3202
-