From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.3 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 84143BBC4 for ; Sun, 8 Mar 2009 00:43:15 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4CAMuVsklA6ba5k2dsb2JhbACUYj8BAQEBCQkKCREDrSaBByoIjlcBAwEDgkoIgTAGgxQ X-IronPort-AV: E=Sophos;i="4.38,321,1233529200"; d="scan'208";a="22203586" Received: from nf-out-0910.google.com ([64.233.182.185]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Mar 2009 00:43:00 +0100 Received: by nf-out-0910.google.com with SMTP id b11so124282nfh.13 for ; Sat, 07 Mar 2009 15:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:references:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:cc:x-mailer; bh=FsKdmzgTqY/ZMMPeqqUbnC2ix4atQLOVQpYWZKcSDVo=; b=RiynEF46854MXLf2zegQ44RCWewEKuQ2QorBJ/f0FByNKJyYIIu7TLeaeS71bpzcrr X7GzMa8MRDz3S4WS4WHnMtPFwAGPI70yKhE2ei/uXI8awlf4+xk2h9GqIjzqZsC9ONqn xwR95AWqj5QS3DXFVU1MfXpVzhqPA83PnXwys= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=references:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:cc:x-mailer; b=Aiwzy4cTED+jQk+zltQZ2OxMV9Ue8/tMj25ynjybnK98LT73epkT1PPofhHamQ2//D 0saFtClRV4MAiJhFmQjvcOpDmlI8FpCKYRCaLbRMoySHeTP/mPMPjalipAM7tZoXS1iR 2Z4vpqVZqBIE+gV5Dzm8rXlVioySv7sy5DcIY= Received: by 10.210.52.15 with SMTP id z15mr1133049ebz.96.1236469379860; Sat, 07 Mar 2009 15:42:59 -0800 (PST) Received: from ?10.10.30.5? (94.Red-88-6-143.staticIP.rima-tde.net [88.6.143.94]) by mx.google.com with ESMTPS id 28sm2787861eyg.25.2009.03.07.15.42.58 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 07 Mar 2009 15:42:59 -0800 (PST) References: <24D11586-4F15-4B6E-8FB7-58651317164D@gmail.com> <46331.52510.qm@web27007.mail.ukl.yahoo.com> Message-Id: From: Joel Reymont To: Matthieu Wipliez In-Reply-To: <46331.52510.qm@web27007.mail.ukl.yahoo.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: Re : [Caml-list] Re: camlp4 stream parser syntax Date: Sat, 7 Mar 2009 23:42:55 +0000 Cc: O'Caml Mailing List X-Mailer: Apple Mail (2.930.3) X-Spam: no; 0.00; camlp:01 parser:01 syntax:01 matthieu:01 parsers:01 camlp:01 grammars:01 parser:01 ocamlyacc:01 vastly:01 lexer:01 lexer:01 ocamllex:01 functor:01 struct:01 On Mar 7, 2009, at 11:21 PM, Matthieu Wipliez wrote: > why are you using stream parsers instead of Camlp4 grammars ? Because I don't know any better? I'm just starting out, really. I have a parser that I wrote using ocamlyacc and menhir. I finally when with dypgen and didn't touch the code for a few months. I then tried to simplify the grammar on account of a later type checking pass and realized that I cannot troubleshoot it. I think I can make do with a camlp4 parser and it will vastly simplify debugging. > This: > ... > could be written as: > expression: [ > [ (i, _) = INT -> Int i > | (s, _) = STRING -> Str s > ... ] > ]; Doesn't your example assume that I'm using the camlp4 lexer? > expression: [ > [ e1 = SELF; "/"; e2 = SELF -> > if e2 = Int 0 then > Loc.raise _loc (Failure "division by zero") > else > BinaryOp (e1, Div, e2) ] > ]; Where does SELF above come from? Can I use a token instead of "/" since I return SLASH whenever "/" is found by the lexer. > By the way, do you need you own tailor-made lexer? Camlp4 provides > one that might satisfy your needs. It has been said that it's not extensible so I wrote my own lexer using ocamllex and wrapped it to return (tok, loc) Stream.t. > Otherwise, you can always define your own lexer (I had to do that > for the project I'm working on, see file attached). Thanks, I'll study it. > Your parser would then look like > > (* functor application *) > module Camlp4Loc = Camlp4.Struct.Loc > module Lexer = Cal_lexer.Make(Camlp4Loc) > module Gram = Camlp4.Struct.Grammar.Static.Make(Lexer) Is this extending the OCaml grammar or starting with an "empty" one? > (* rule definition *) > let rule = Gram.Entry.mk "rule" Is this the "start" rule of the parser? Thanks, Joel --- http://tinyco.de Mac, C++, OCaml