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.8 required=5.0 tests=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 5CFE9BBAF for ; Thu, 12 Mar 2009 00:47:07 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvYEACjpt0nRVduudWdsb2JhbACUej8BDAoLBxGqe4EGj1oBAwEDhAoGgyM X-IronPort-AV: E=Sophos;i="4.38,346,1233529200"; d="scan'208";a="36429961" Received: from mail-ew0-f174.google.com ([209.85.219.174]) by mail4-smtp-sop.national.inria.fr with ESMTP; 12 Mar 2009 00:47:06 +0100 Received: by ewy22 with SMTP id 22so222062ewy.27 for ; Wed, 11 Mar 2009 16:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:mime-version:from :date:content-transfer-encoding:message-id:content-type:to:x-mailer; bh=FhuTS2zA/wOHIcSohcHOoCUc+CYJ7eFpXmWY8rsewtU=; b=MeBeyq04F1rR1WGnFR9Uy4PKUHCnoyojHpJG09nRFgWw78DxGWs/tgvOZvnZZo8euT LTz1ox3Pe9xLylyMICCfpLCqZZgShXdvH8gugHfgMrinZEEWj2r+yKMKd1h5QXwiohXT wwRDN4MyNmaDuv6NghYFhne/GLKRbFGUi8m70= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:mime-version:from:date:content-transfer-encoding:message-id :content-type:to:x-mailer; b=k1LK4P7bViVXU3xa9dYbu6RS2BAMkB6xVwkMcW6JYGFdoZP+NvtFKqvFHy7t/VMMDm pS1BKkLtFnW+1KGqpmf/Vretfqlf+SiE1BpY/mYBDq9kpTfRIsC9MVfFj/1/5a1O9o4Q vk3khmLl4VvPijHpJoqia7tXfW4eNDYmGKlRo= Received: by 10.210.38.17 with SMTP id l17mr5950182ebl.51.1236815222976; Wed, 11 Mar 2009 16:47:02 -0700 (PDT) Received: from ?10.10.30.9? (127.Red-88-3-8.dynamicIP.rima-tde.net [88.3.8.127]) by mx.google.com with ESMTPS id 10sm20669eyd.23.2009.03.11.16.47.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 11 Mar 2009 16:47:02 -0700 (PDT) Subject: camlp4: precedence, LEFTA, NONA, etc. Mime-Version: 1.0 (Apple Message framework v1043) From: Joel Reymont Date: Wed, 11 Mar 2009 23:46:59 +0000 Content-Transfer-Encoding: 7bit Message-Id: <20BA0B67-42DD-4E9F-9165-741D91ECCF44@gmail.com> Content-Type: text/plain; delsp=yes; charset=us-ascii; format=flowed To: O'Caml Mailing List X-Mailer: Apple Mail (2.1043) X-Spam: no; 0.00; camlp:01 camlp:01 prec:01 expr:01 expr:01 bool:01 bool:01 instr:01 precedence:01 precedence:01 int:01 int:01 ident:01 ident:01 cond:02 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