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=1.8 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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id EC1EFBBAF for ; Thu, 12 Mar 2009 10:13:44 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtEBAL9uuEnRVduumGdsb2JhbACMc4gHPwEBAQEBCAkMBxGsOoEGjyoBAwEDhAoG X-IronPort-AV: E=Sophos;i="4.38,349,1233529200"; d="scan'208";a="36444469" Received: from mail-ew0-f174.google.com ([209.85.219.174]) by mail4-smtp-sop.national.inria.fr with ESMTP; 12 Mar 2009 10:13:44 +0100 Received: by ewy22 with SMTP id 22so338004ewy.27 for ; Thu, 12 Mar 2009 02:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=54M9Rn8Cz2etAcZVqGPwojcIO1NHLvkq1NgzmRmlwVE=; b=xdbuTZIlvj5AKuuSna4yWYaTtVgLURIzqRzmd4BSibepitcp6eoCi2ExrelznfaxrE jMLCus2fTNwHUKu71gB8ZgBkPOhfqzPApxvK/BvLUrmOdZ/bI9KXwTf3c4Yk34WD5Zqb 97k5y2nUcsdfHwT5U6qYmg2XFQe/xhdXUNtVQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=G5+teYsFr2R7oew1nZDoS8HkLaMsMm+JZDmwJY3JkiBVxwcvu+3N9TaaLXDglqNJ0D O821c7MGWQm5gaBG5EP8gOzVESSWjBipomQw95NkDQL5huY4T4MLqxfJ44ltE4SN00JR uwL4753ycIT+Fr0tQVsfmNrtdZs3IUiF5Egfk= MIME-Version: 1.0 Received: by 10.210.11.17 with SMTP id 17mr6320650ebk.3.1236849224109; Thu, 12 Mar 2009 02:13:44 -0700 (PDT) In-Reply-To: <20BA0B67-42DD-4E9F-9165-741D91ECCF44@gmail.com> References: <20BA0B67-42DD-4E9F-9165-741D91ECCF44@gmail.com> Date: Thu, 12 Mar 2009 10:13:44 +0100 Message-ID: <527cf6bc0903120213k731ee9f5xb6b1104f12f001b@mail.gmail.com> Subject: Re: [Caml-list] camlp4: precedence, LEFTA, NONA, etc. From: blue storm To: Joel Reymont Cc: "O'Caml Mailing List" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; camlp:01 camlp:01 parsers:01 ml's:01 expr:01 expr:01 prec:01 bool:01 bool:01 instr:01 beginner's:01 ocaml:01 bug:01 storm:98 beginners:01 To my understanding, precendence levels correspond to the level you define in the grammar, in the given order : in your case, you have "=", "+" at the same level, with higher precendence than "And" and "*". You should reverse your rules (starting with the higher-precendence construnction instead of the atomic values), and possibly split some of your level into different levels (eg. "<" and "+") for finer-grained precedence. See camlp4/Camlp4Parsers/Camlp4OcamlRevisedParser.ml's "expr" rule (you may look for " expr:" in the source file) for a complete yet understandable example. On 3/12/09, Joel Reymont wrote: > I'm trying to properly set up the precedence in my expression camlp4 > rule. > > It's not working properly, though. > > (* wrong!!! > has higher prec than and*) > # parse_with_rule expr "1 > 2 and 3 > 4";; > - : Easy_ast.expr = Cond (Int 1, GT, And (Int 2, Cond (Int 3, GT, Int > 4))) > > (* right! mul is higher than plus *) > # parse_with_rule expr "1 + 2 * 3";; > - : Easy_ast.expr = Plus (Int 1, Mul (Int 2, Int 3)) > > (* wrong!!! > should be higher than + *) > # parse_with_rule expr "1 + 2 > 3";; > - : Easy_ast.expr = Plus (Int 1, Cond (Int 2, GT, Int 3)) > > (* wrong!!! mul should be higher than and *) > # parse_with_rule expr "1 * 2 and 3 * 4";; > - : Easy_ast.expr = Mul (Int 1, And (Int 2, Mul (Int 3, Int 4))) > > (* right!!! *) > # parse_with_rule expr "1 * not 2";; > - : Easy_ast.expr = Mul (Int 1, Not (Int 2)) > > Here's my rule. What am I doing wrong? > > Thanks, Joel > > --- > > expr: > [ NONA > [ (x, _) = INT -> Int x > | (x, _) = FLOAT -> Float x > | (s, _) = STRING -> Str s > | "true" -> Bool true > | "false" -> Bool false > | a = IDENT; "["; b = exprl; "]"; c = OPT ago -> > Var (a, b, c) > | a = IDENT; b = OPT ago -> > Var (a, [], b) > | "("; e = expr; ")" -> Group e > ] > | LEFTA > [ e1 = expr; "="; e2 = expr -> Cond (e1, EQ, e2) > | e1 = expr; "<="; e2 = expr -> Cond (e1, LE, e2) > | e1 = expr; ">="; e2 = expr -> Cond (e1, GE, e2) > | e1 = expr; "<"; e2 = expr -> Cond (e1, LT, e2) > | e1 = expr; ">"; e2 = expr -> Cond (e1, GT, e2) > | e1 = expr; "<>"; e2 = expr -> Cond (e1, NEQ, e2) > | e1 = expr; "+"; e2 = expr -> Plus (e1, e2) > | e1 = expr; "-"; e2 = expr -> Minus (e1, e2) > | "-"; e = expr -> UniMinus e > ] > | LEFTA > [ e1 = expr; "Or"; e2 = expr -> Or (e1, e2) > | e1 = expr; "And"; e2 = expr -> And (e1, e2) > | e1 = expr; "Mod"; e2 = expr -> Mod (e1, e2) > | e1 = expr; "*"; e2 = expr -> Mul (e1, e2) > | e1 = expr; "/"; e2 = expr -> Div (e1, e2) > | e = expr; [ "Points"; "Point" ]; i = OPT instr -> Points (e, i) > | "Not"; e = expr -> Not e > ] > ]; > > --- > http://tinyco.de > --- Mac & iPhone > > > > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >