From: | torbenm@diku.dk (Torben Ęgidius Mogensen) |
Newsgroups: | comp.compilers |
Date: | Wed, 21 Mar 2012 11:53:35 +0100 |
Organization: | SunSITE.dk - Supporting Open source |
References: | 12-03-012 12-03-013 12-03-038 12-03-046 |
Keywords: | design, history |
Posted-Date: | 22 Mar 2012 14:40:15 EDT |
Gene Wirchenko <genew@ocis.net> writes:
> On Wed, 14 Mar 2012 09:51:31 +0100, torbenm@diku.dk (Torben Fgidius
> Mogensen) wrote:
>
>>But intuitive syntax can also mean consistent, unambiguous and without
>>arbitrary restrictions, which certainly does not apply to C-style
>>syntax. In a way, APL syntax is very intuitive: Operators are single
>>characters, so you dont have problems parsing things like a+++b, where
>>it is not clear where one operator ends and the next begins, evaluation
>
> Greedy parsing. Fornm the longest token. That is
> a ++ + b
Indeed. But that requires knowledge of lexing/parsing methods, so it
is confusing to a newbie programmer, and even some not-so-newbie
programmers can get confused. A programming language should primarily
be easy to read (parse) by a human reader and only secondarily be easy
to parse by a computer. Ambiguity is a problem for both, but long
lookahead is usually not a problem for human readers, but may
challenge some parsing methods. Having a huge hierarchy of operator
precedences is no problem for most parsing methods (certainly not
LR-based methods), but it can make programs hard to read for humans.
C++ has (IMO) gone over the top with the number of predefined
operators and precedence levels.
Most programmers have no problem with the four arithmetic operators, and
can fairly easily also remember the precedences of comparison operators
and logical connectives. So an idea (employed by, IIRC, OCaml) is to
let operators have a precedence that is determined by their first
character. So +. has the same precedence as + and so on. That is a
fairly neat idea, and by allowing all combinations of characters from a
subset of the non-alphanumeric characters in operator names, you also
avoid C's problem of parsing +++: It is parsed as a single operator, and
if it is not defined in the program, that is reported as an error.
Torben
Return to the
comp.compilers page.
Search the
comp.compilers archives again.