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 MAA09228; Wed, 28 May 2003 12:48:05 +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 MAA09418 for ; Wed, 28 May 2003 12:48:04 +0200 (MET DST) Received: from mail.tepkom.ru (mail.tepkom.ru [195.9.10.14]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h4SAm3H15201 for ; Wed, 28 May 2003 12:48:03 +0200 (MET DST) Received: from localhost (localhost [127.0.0.1]) by mail.tepkom.ru (Postfix) with SMTP id BB2E497278; Wed, 28 May 2003 14:54:17 +0400 (MSD) Received: from post.tepkom.ru (max.tepkom.ru [195.19.226.43]) by mail.tepkom.ru (Postfix) with ESMTP id 9EA3C97277; Wed, 28 May 2003 14:54:17 +0400 (MSD) Message-ID: <3ED493F3.1000400@post.tepkom.ru> Date: Wed, 28 May 2003 14:48:19 +0400 From: Anton Moscal User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Michal Moskal Cc: caml-list@inria.fr Subject: Re: [Caml-list] Ocamlyacc vs stream parser References: <20030523092657.GA4547@roke.freak> In-Reply-To: <20030523092657.GA4547@roke.freak> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; caml-list:01 michal:01 moskal:01 camlp:01 runtime:01 higher-level:01 dependecies:01 strm:01 npeek:01 tokens:01 workaround:01 int:01 tepkom:01 sep:01 complexity:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Michal Moskal wrote: >>One question: >> Why should I use parser keyword instead of ocamlyacc? > > > ocamlyacc gives you better error reporting (about conflicts) and > strictly bigger set of languages it can recognize. But keyword parser > build with camlp4 libraries can be modified at runtime. It also provides > some higher-level constructs like LIST0. > There is another useful feature of camlp4 - you can manually write parsing function which can perform lookahead to any number of tokens and use criteria of arbitrary complexity. This provides simply and efficient workaround for resolving ambiguities. (or use some external information to implement context dependecies - for example - I can easily write rule type_identifier, which can succeed only if current lexem is name which was declared before as type name) - Example: "guard" rule, which don't eat any tokens from input strean and succeed iff next two tokens are: "[ " or "[]" or "[..." let is_bound = Grammar.Entry.of_parser gram "[is_bound]" (fun strm -> match Stream.npeek 2 strm with | ("", "[")::("INT", _)::_ | ("", "[")::("", "]")::_ | ("", "[")::("", "...")::_ -> () | _ -> raise Stream.Failure ) usage: .... | LEFTA [ t=SELF; is_bound; "["; bounds=LIST0 bound SEP ","; "]" -> Type.Array (t, bounds) .... Anton Moscal ------------------- 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