From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA03677; Sat, 14 Aug 2004 22:22:30 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA04464 for ; Sat, 14 Aug 2004 22:22:29 +0200 (MET DST) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i7EKMSRM008312 for ; Sat, 14 Aug 2004 22:22:29 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay03.plus.net with esmtp (Exim) id 1Bw52q-0003Xt-EJ for caml-list@inria.fr; Sat, 14 Aug 2004 20:22:28 +0000 From: Jon Harrop To: Ocaml Mailing List Subject: Re: [Caml-list] CFG's and OCaml Date: Sat, 14 Aug 2004 21:19:10 +0100 User-Agent: KMail/1.6.2 References: <200408140125.59473.jon@jdh30.plus.com> <1092470117.29139.582.camel@pelican.wigram> In-Reply-To: <1092470117.29139.582.camel@pelican.wigram> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200408142119.11234.jon@jdh30.plus.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 411E7484.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 disallow:01 'a-:01 'a-:01 parses:01 mimic:01 lalr:01 2004:99 inequality:01 operand:01 coercing:01 fiddle:01 trade-off:01 productive:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Saturday 14 August 2004 04:33, Brian Hurt wrote: > > 3. If so, is the fact that most languages disallow "a > No. "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. IMHO, being able to do "1<2 ... > It is possible to make < a chain operator instead, > ... I see. You don't just make (x + y) an expression in the grammar but a whole new rule "sum" which contains (x + y) or (x + sum) and has the precendence of "+"? So I want to take all comparison operators "'a -> 'a -> bool" and make a rule "inequality" for a (x op1 y) or (x op1 comparison) chain "operator" which, say, builds a list of operand and operators? Then you could do "x0 <= x < x1". Woohoo! Would this have to be a conflict in the grammar with "a > 4. Could that be added to OCaml? ;-) > > Not without breaking existing code... Right, because somebody somewhere is bound to have done the equivalent of "2<5 > 5. Is it productive to think in terms of coercing lex and yacc into doing > > as much of the work as possible > > I personally think you should do the opposite -- let lex/yacc > do the least possible work since they're fairly rigid. > You may need to fiddle with your grammar to get the language > you want -- and it is better if that has the minimum > impact on your semantic logic. IMHO. But making more use of lex and yacc is good because they detect conflicts or ambiguities? Not great in the sense that reduce-reduce conflicts can be a nightmare to get rid of though (especially if you don't own the grammar), but that's the trade-off. Cheers, Jon. ------------------- 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