home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.edu
- Path: sparky!uunet!spool.mu.edu!caen!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
- From: jlg@cochiti.lanl.gov (Jim Giles)
- Subject: Re: Re: Scientists as Programmers (was Re: Small Language Wanted)
- Message-ID: <1992Sep8.194256.26243@newshost.lanl.gov>
- Sender: news@newshost.lanl.gov
- Organization: Los Alamos National Laboratory
- References: <1992Sep3.112944.20996@dbsun.uucp> <Bu08uF.HBC@mentor.cc.purdue <KERS.92Sep4154056@cdollin.hpl.hp.com> <135691@lll-winken.LLNL.GOV>
- Distribution: na
- Date: Tue, 8 Sep 1992 19:42:56 GMT
- Lines: 57
-
- 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.
-
- This is an example of the overlap between syntax and semantics. At the
- lexical level, the only issue is what constitutes an operator:
-
- op_char ::= @ | # | $ | % | ^ | & | `*' | - | `+' | `=' | / | \
- | < | > | `~' | ! | `|'
-
- operator ::= op_char+
-
- That is, an operator is defined as one or more characters from the
- set defined as `op_char'. Operators are delimited by anything not
- in the set. There is no ambiguity at the lexical level about this
- definition of operators. (Some characters quoted because they are
- part of the meta-syntax of the lexical scanner-generator).
-
- Once identified, the operator is looked up in a symbol table to determine
- part of its semantic properties - like its precedence, associativity, etc..
- There is no reason why this symbol table need be generated statically
- as part of the *built-in* properties of the compiler. Since *most*
- modern compilers use a split-level syntax (lexical being separate from
- the rest) and since most interpose a `screener' between the lexical
- level and the rest, most compilers could be enhanced in this way.
-
- The grammar for expressions would be like Haskell's:
-
- 0
- exp ::= exp
-
- i i+1 (n,i) i+1 i i
- exp ::= exp [op exp ] | lexp | rexp
-
- i i i+1 (l,i) i+1
- lexp ::= (lexp | exp ) op exp
-
- i i+1 (r,i) i i+1
- rexp ::= exp op (rexp | exp )
-
- Where `n' means non-assocaitive, `l' means left associative, `r' means
- right associative, and these rules are actually repeated for each
- precedence `i' that you allow. Prefix and prostix rules can also
- be added.
-
- Having said this, I would personally caution users not to define too
- many operators. There are very few for which a natural precedence
- and associativity (or even a natural notation) can be clearly identified.
- Overuse of user defined operators can lead to less legible code, not
- more legible.
-
- --
- J. Giles
-