Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] CFG's and OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] CFG's and OCaml
On Sat, 14 Aug 2004, Jon Harrop wrote:

> On Saturday 14 August 2004 04:33, Brian Hurt wrote:
> > > 3. If so, is the fact that most languages disallow "a<b<c" due to this?
> > 
> > No.  "a<b<c" is parsed the same way as "a+b+c".
> 
> Sorry, I should have been more specific. With left- or right- or 
> non-associative, commuting, 'a->'a->'a operators (like + and *) you can get 
> away with parsing that way, e.g. "a+b+c" as:
> 
> either  (a+b)+c  or  a+(b+c)
> 
> But you can't do this with comparison 'a->'a->bool operators because it forces 
> you to deviate from conventional mathematical meaning, e.g. you get a type 
> error in OCaml on the "3" in "1<2<3" because it parses as "(1<2)<3" which 
> evaluates to "true<3" which just doesn't make any sense.
> 

The syntax of a language doesn't enforce a given meaning on the language 
being parsed.  "Colorless green ideas sleep furiously" is a syntactically 
correct English sentence, even if it is utterly meaningless.

The AST  of a<b<c has to be one of two ways:

       <                <
      / \              / \
    a    <      or    <   c
        / \          / \
       b   c        a   b

i.e. a < (b < c) or (a < b) < c.  What the meaning of these two 
expressions are is entirely up to the compiler- more spefically, up to the 
parts which are not lex or yacc based.

Although this does bring up one interesting question- is a<b<c 
syntactically different than (a<b)<c?  Generally, languages want to 
consider "extra" parenthesis to be harmless.

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners