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=0.3 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id E0238BC6B for ; Wed, 31 Oct 2007 06:54:11 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAOC0J0fLENaHnmdsb2JhbACOZQIBAQcEBhEY X-IronPort-AV: E=Sophos;i="4.21,349,1188770400"; d="scan'208";a="5305164" Received: from ipmail03.adl2.internode.on.net ([203.16.214.135]) by mail3-smtp-sop.national.inria.fr with ESMTP; 31 Oct 2007 06:54:10 +0100 X-IronPort-AV: E=Sophos;i="4.21,349,1188743400"; d="scan'208";a="178284786" Received: from ppp121-44-98-190.lns10.syd6.internode.on.net (HELO [192.168.1.201]) ([121.44.98.190]) by ipmail03.adl2.internode.on.net with ESMTP; 31 Oct 2007 16:22:01 +1030 Subject: Re: [Caml-list] Problem with precedence declaration in .mly file From: skaller To: Angela Zhu Cc: caml-list@yquem.inria.fr In-Reply-To: <23EC0ABA-12EE-49DE-B76A-1D91BCCAE1BA@cs.rice.edu> References: <6C4DFFEF-0A5E-496F-9468-56693FFA4DC2@cs.rice.edu> <1193753915.47273d3bb15f2@webmail.in-berlin.de> <23EC0ABA-12EE-49DE-B76A-1D91BCCAE1BA@cs.rice.edu> Content-Type: text/plain Date: Wed, 31 Oct 2007 16:52:00 +1100 Message-Id: <1193809920.8355.41.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ocaml:01 angela:98 sourceforge:01 wrote:01 precedence:01 precedence:01 integer:01 caml-list:01 mly:01 grammar:02 grammar:02 declaration:02 zhu:04 hack:04 star:94 On Tue, 2007-10-30 at 23:26 -0500, Angela Zhu wrote: > /***** Precedence Rules *****/ > ... > %left PLUS MINUS > %left STAR DIVIDE > %left ATOB > Can any one help me to see why it happens? Why the precedence rules > doesn't work? > Precedences also can be created by sophisticated > organization of the grammar rules. > But I want to avoid this. DO NOT USE THEM. The rules are hard to explain and very badly designed, in other words, they're a hack. Ocaml provides them for compatibility with older yacc like tools. Write your grammar properly instead, in pseudo code: term = factor | term + factor factor = atom | factor * atom atom = INTEGER | ( term ) gives the precedence of * over + and left associativity, without using incomprehensible precedence rules. -- John Skaller Felix, successor to C++: http://felix.sf.net