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 QAA31996; Fri, 12 Sep 2003 16:04:20 +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 QAA01501 for ; Fri, 12 Sep 2003 16:04:19 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from clusterB2.tfb.com (clusterb2.tfb.com [65.126.210.71]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8CE4Hf19059 for ; Fri, 12 Sep 2003 16:04:18 +0200 (MET DST) Received: from tfb.com (host-66-81-21-19.rev.o1.com [66.81.21.19]) by clusterB2.tfb.com (8.12.5/8.12.5) with ESMTP id h8CE4BHi020597; Fri, 12 Sep 2003 07:04:12 -0700 Message-ID: <3F61D25B.1040802@tfb.com> Date: Fri, 12 Sep 2003 07:04:11 -0700 From: Ken Rose Reply-To: rose@acm.org User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030703 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Rafael 'Dido' Sevilla" CC: caml-list@inria.fr Subject: Re: [Caml-list] eliminating shift/reduce conflicts References: <20030912082632.GA9048@imperium.ph> In-Reply-To: <20030912082632.GA9048@imperium.ph> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 rafael:01 'dido':01 foo:01 foo:01 baz:01 superset:01 baz:01 compiler:01 compilers:01 objects:02 excess:96 wrote:03 sevilla:03 textbook:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Rafael 'Dido' Sevilla wrote: > I have an ocamlyacc grammar that contains productions that look like: > > foo_list: FOO { [$1] } > | foo_list COMMA FOO { $3 :: $1 } > ; > > which creates a list of FOO objects. I however have some rules that > need to be prefixed by either a single FOO or a foo_list, like so: > > bar: foo_list COLON xyzzy { ... } > > and > > baz: FOO COLON yzzyx { ... } > > This of course produces a shift/reduce conflict, and shifting fails to > parse the 'bar' correctly. Perhaps I need to read a compiler > construction textbook more thoroughly to figure out this answer, but any > hints out there on getting rid of this shift/reduce. The general opinion on comp.compilers, which I agree with, is that the best way to deal with this is to parse a superset of what you "really" want and then use the semantic phase to reject the excess. In this case, that means you'd define baz: foo_list COLON yzzyx and later (or even in the semantic action right here) issue an error message if the foo_list is longer than 1. Good luck - ken ------------------- 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