From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 7075ABB9C for ; Sun, 4 Dec 2005 16:04:23 +0100 (CET) Received: from mailout09.sul.t-online.com (mailout09.sul.t-online.com [194.25.134.84]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jB4F4NkR027540 for ; Sun, 4 Dec 2005 16:04:23 +0100 Received: from fwd30.aul.t-online.de by mailout09.sul.t-online.com with smtp id 1EivPa-0006xQ-01; Sun, 04 Dec 2005 16:04:22 +0100 Received: from fibonacci.home.krausn.de (EwP3KvZ-QeTHLl6Pz2R1dpwUsV25vN1rL5mC9L11VyzHszmnyBK1k9@[84.145.218.47]) by fwd30.sul.t-online.de with esmtp id 1EivPS-1oRtzs0; Sun, 4 Dec 2005 16:04:14 +0100 Received: from serialm.homelinux.org (unknown [IPv6:2001:1a50:5057::1]) by fibonacci.home.krausn.de (Postfix) with ESMTP id F191730C2CB for ; Sun, 4 Dec 2005 16:04:12 +0100 (CET) Received: from waltraud.manson.mm (waltraud.manson.mm [IPv6:2001:1a50:5057:1:2e0:81ff:fe26:71fc]) by serialm.homelinux.org (8.13.5/8.13.4) with ESMTP id jB4F3erI022869 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 4 Dec 2005 16:03:40 +0100 (CET) Received: from waltraud.manson.mm (mary@localhost.localdomain [127.0.0.1]) by waltraud.manson.mm (8.13.4/8.13.4) with ESMTP id jB4F3d71013329 for ; Sun, 4 Dec 2005 16:03:39 +0100 Received: (from mary@localhost) by waltraud.manson.mm (8.13.4/8.13.4/Submit) id jB4F3dGd013328 for caml-list@yquem.inria.fr; Sun, 4 Dec 2005 16:03:39 +0100 Date: Sun, 4 Dec 2005 16:03:39 +0100 From: "Robert W." To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] yacc question Message-ID: <20051204150339.GA10618@waltraud.manson.mm> Mail-Followup-To: caml-list@yquem.inria.fr References: <1133705740.11050.14.camel@rosella> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1133705740.11050.14.camel@rosella> User-Agent: Mutt/1.5.11 X-ID: EwP3KvZ-QeTHLl6Pz2R1dpwUsV25vN1rL5mC9L11VyzHszmnyBK1k9@t-dialin.net X-TOI-MSGID: 314a23ea-0d34-47c2-a083-603af2437129 X-Miltered: at nez-perce with ID 43930577.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 parser:01 expr:01 buffer:01 ocamlyacc:01 parses:01 lexer:01 token:01 expr:01 token:01 trailing:01 buffer:01 parser:01 wrote:01 integer:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Mon, Dec 05, 2005 at 01:15:40AM +1100, skaller wrote: > I have the 'usual' kind of parser for expressions, with two > nonterminals 'expr' and 'atom', the latter including ( expr ) > and INTEGER of course. > > When I have input like > > 1; > 1 + 2 ; > (1 + 2) ; > > none of the case parse as expressions, the first and > last do parse as atoms (leaving the ; in the buffer). > > What I want is to parse the longest possible match. > The only way I can think of doing this is: > ocamlyacc parses longest match by default. Your rule for atoms seem to complex or you lexer isn't able to extract the token for atoms correctly from the line. > | expr token_not_allowed_in_expressions > > and then 'put back' the trailing token into the buffer. > Is there another way? > This shouldn't be necessary, normally you can redesign your parser rules to avoid this. -- Robert...