Syntax

andy@SAIL.Stanford.EDU (Andy Freeman)
Wed, 27 Nov 1991 23:12:16 GMT

          From comp.compilers

Related articles
Current work in compiler/language design. hackeron@Athena.MIT.EDU (Harris L. Gilliam - MIT Project Athena) (1991-11-10)
Re: Current work in compiler/language design. objsys@netcom.com (1991-11-20)
Syntax andy@SAIL.Stanford.EDU (1991-11-27)
Re: Syntax drw@cantor.mit.edu (1991-12-03)
Re: Syntax salomon@silver.cs.umanitoba.ca (1991-12-04)
Re: Syntax rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell) (1991-12-05)
Re: Syntax buzzard@eng.umd.edu (1991-12-05)
Re: Syntax ea08+@andrew.cmu.edu (Eric A. Anderson) (1991-12-05)
Re: Syntax gaynor@remus.rutgers.edu (1991-12-05)
[1 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: andy@SAIL.Stanford.EDU (Andy Freeman)
Keywords: syntax, design
Organization: Computer Science Department, Stanford University.
References: 91-11-030 91-11-081
Date: Wed, 27 Nov 1991 23:12:16 GMT

In article 91-11-081 objsys@netcom.com (Bob Hathaway) writes:
>Natural syntax : if a plus b times c equals zero ...
>Typical syntax : if a + b * c == 0 then ...
>Unnatural syntax : (if (== (+ a (* b d)) 0 ) ... )
>
>Unnatural means that for this trivial last example I first drew the tree
>(wheh, first time) then after 3 attempts at polish prefix notation (opps,
>a little slippage there) and matching lots of parenthesis (thank god for
>vi:%), I got it. Like this syntax or not it is not natural, most people
>do expressions infix.


Summary: maybe you wrote the first two expressions more quickly, but I
don't know what they mean, and that problem has nothing to do with the
meaning of the operators involved.


Actually, people don't do expressions infix. At the very most, they use
infix for small expressions involving *, +, -, and /. Bigger expressions,
or those with other operators, are done with parentheses and/or
temporaries. Moreover, non-binary expressions require some other tool;
prefix with parentheses is the most common and postfix, with parentheses,
is the only other one that makes any sense. (Sure, you can split the
operator into pieces if it requires a small and fixed number of arguments,
as is done with C's conditional expression, but that's neither natural nor
adequate.)


Both the "natural" and "typical" expressions above are ambiguous. There
is no "natural" parse of either; the "infix" languages don't agree on
precedence because people don't, at least for operators other than *, +,
-, and /. (BTW - There isn't even agreement on how consecutive - and /s
are grouped.)


-andy
--
UUCP: {arpa gateways, sun, decwrl, uunet, rutgers}!neon.stanford.edu!andy
ARPA: andy@neon.stanford.edu
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.