home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!decwrl!deccrl!news.crl.dec.com!news!nntpd.lkg.dec.com!math.zko.dec.com!edp
- From: edp@math.zko.dec.com (Eric Postpischil)
- Newsgroups: comp.edu
- Subject: Re: Re: Scientists as Programmers (was Re: Small Language Wanted)
- Message-ID: <1992Sep9.132117.25608@nntpd.lkg.dec.com>
- Date: 9 Sep 92 13:21:17 GMT
- References: <1992Sep3.112944.20996@dbsun.uucp> <Bu08uF.HBC@mentor.cc.purdue <KERS.92Sep4154056@cdollin.hpl.hp.com> <135691@lll-winken.LLNL.GOV>
- Sender: usenet@nntpd.lkg.dec.com (USENET News System)
- Reply-To: edp@math.zko.dec.com (Eric Postpischil)
- Distribution: na
- Organization: Digital Equipment Corporation
- Lines: 36
-
- In article <135691@lll-winken.LLNL.GOV>, blair@lll-crg.llnl.gov (Gary
- Blair) writes:
-
- >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.
-
- Nah, it is trivial. The lexical analyzer just recognizes the operator
- and returns a token to the parser. Handling precedence is a bit
- trickier, but if you are willing to accept a fixed number of precedence
- levels determined at compiler-generation time, it is trivial too.
- Simply, when an operator is declared, the parser stores the name of the
- operator (the string of symbols that denote it) into a data structure,
- along with information about its precedence and meaning. When the
- lexical analyzer sees that string in the future, it returns a token
- appropriate to the precedence of the operator. That token is used in
- the parsing; it is part of the parse tables. When the parser sees that
- token, it takes a value from the token that points to the information
- about the operator and calls appropriate routines to implement the
- meaning.
-
- The principal requirement here be that legal strings for operators and
- other symbols be defined properly, so that whatever selection of
- declarations the user makes is unambiguous and can be recognized by the
- lexical analyzer. E.g., variables and types and similar things might be
- all alphanumeric, and operators might be all contiguous strings of
- symbols such as <, !, et cetera. But you could easily have named
- operators using the scheme I have described above, such as "a modulo_add
- b" to mean (a+b)%m.
-
-
- -- edp (Eric Postpischil)
- "Always mount a scratch monkey."
- edp@alien.enet.dec.com
-