home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.edu:1612 comp.compilers:1534
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!udel!gvls1!faatcrl!iecc!compilers-sender
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Newsgroups: comp.edu,comp.compilers
- Subject: Introducing new operators (was: Re: Scientists as Programmers)
- Keywords: parse, design
- Message-ID: <92-09-053@comp.compilers>
- Date: 8 Sep 92 17:49:50 GMT
- References: <1992Sep3.112944.20996@dbsun.uucp> <135691@lll-winken.LLNL.GOV>
- Sender: compilers-sender@iecc.cambridge.ma.us
- Reply-To: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Followup-To: comp.compilers
- Organization: Computer Science, University of Melbourne, Australia
- Lines: 33
- Approved: compilers@iecc.cambridge.ma.us
-
- blair@lll-crg.llnl.gov (Gary Blair) writes:
-
- >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''. ...
- >
- >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.
-
- I think that "next to impossible" is perhaps overstating the case a
- little. If you have a small number of precedence levels (eg. Haskell has
- only 10 or 16 I think), then it is quite possible to code up each of these
- precedences as a production in the grammar. The difficulty with knowing
- what precedence a given operator has, or indeed exactly which characters
- constitute an operator, is then exactly analagous to the "typedef" problem
- in C (determining whether an identifier is a type name or not), and can be
- handled with the same sort of hack (feeding information from the parser
- back into the lexer).
-
- All the same, it is not trivial. If you also have to worry about backwards
- compatability with C, it becomes very difficult indeed, I suspect.
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- --
- Send compilers articles to compilers@iecc.cambridge.ma.us or
- {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.
-