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 AAA07696; Sun, 15 Aug 2004 00:14:03 +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 AAA07995 for ; Sun, 15 Aug 2004 00:14:02 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i7EMDxRM019186 for ; Sun, 15 Aug 2004 00:14:00 +0200 Received: from [192.168.1.200] (ppp197-3.lns1.syd2.internode.on.net [203.122.197.3]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i7EMDu4Y052406; Sun, 15 Aug 2004 07:43:57 +0930 (CST) Subject: Re: [Caml-list] CFG's and OCaml From: skaller Reply-To: skaller@users.sourceforge.net To: Jon Harrop Cc: Ocaml Mailing List In-Reply-To: <200408142119.11234.jon@jdh30.plus.com> References: <200408140125.59473.jon@jdh30.plus.com> <1092470117.29139.582.camel@pelican.wigram> <200408142119.11234.jon@jdh30.plus.com> Content-Type: text/plain Message-Id: <1092521636.29139.808.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 15 Aug 2004 08:13:56 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 411E8EA7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 2004:99 n-ary:01 inequality:01 operand:01 tradeoff:01 9660:01 glebe:01 compiler:01 bool:01 bool:01 ocaml:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 2004-08-15 at 06:19, Jon Harrop wrote: > On Saturday 14 August 2004 04:33, Brian Hurt wrote: > > 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 > "+"? The actual grammar production is like: sum: difference sum | difference which looks right associative. But it isn't, because the real thing is: sum: difference sum { $1 :: $2 } | difference { [$1] } which you can see constructs a list -- I can interpret that as either left or right associative, or as an n-ary operator. I have cheated the parser by NOT building the parse tree you'd expect, but a list :) > 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 "(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 But making more use of lex and yacc is good because they detect conflicts or > ambiguities? Except that often they're unwanted, and an artefact of the grammar you have chosen, rather than the language you want to parse. As you said: there is a tradeoff. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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