From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1B8kvwj031854 for ; Fri, 11 Feb 2011 09:46:57 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: At0BAKmFVE3RVaE2dGdsb2JhbAClbQgVAQwJDAcNAgYgoTeMJoRZiQkBAQMFhVcEi3yIOzqBEA X-IronPort-AV: E=Sophos;i="4.60,454,1291590000"; d="scan'208";a="91106442" Received: from mail-fx0-f54.google.com ([209.85.161.54]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 11 Feb 2011 09:46:52 +0100 Received: by fxm16 with SMTP id 16so2647343fxm.27 for ; Fri, 11 Feb 2011 00:46:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:from:date :x-google-sender-auth:message-id:subject:to:content-type; bh=I9+rt/lEetjvDGj8cJWldlgQ0OEB48eL7fn3eIQYwIw=; b=SbUtpzMWkjRh4WxfR/Q5L2PyUwGFgHjKCqtVtui2tt4JTjofw/VzrY4KrMvlWkI4Aq XOF2X7Ny+a+4/QxUbSBIyHM93sQBDjKbdaD7meqLX8O7m8xedTD2ub2Ldh7HcUOXsavL alA/TVM+h/cb/XMpfR/H8BsZ6wLK+7xjpMdw0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:from:date:x-google-sender-auth:message-id :subject:to:content-type; b=mmtTqM0j7HVrOO5z58I9UrtihqwAc+je8PjVVA8Yq4gFWO1WRtsn/1em6SwES/4tjU 9+YpzRA/X7eosLUP3GOaqcgUpyHn8xnBg2Ia3KGWaJP0j+fotapFAFWxYPYTq8iDGJfo DmPvGff1L2OQaKIqdmLcPJk4qTY+8O7x4ziTM= Received: by 10.223.81.76 with SMTP id w12mr214759fak.26.1297414011888; Fri, 11 Feb 2011 00:46:51 -0800 (PST) MIME-Version: 1.0 Sender: david.mentre@gmail.com Received: by 10.223.158.70 with HTTP; Fri, 11 Feb 2011 00:46:21 -0800 (PST) From: David MENTRE Date: Fri, 11 Feb 2011 09:46:21 +0100 X-Google-Sender-Auth: o2u5-mM7Rfy6jSMTJQIa0WjBuxg Message-ID: To: caml users Content-Type: text/plain; charset=ISO-8859-1 Subject: [Caml-list] Priority issue in an ocamlyacc grammar Hello, I'm trying to parse a logic language. In this language, I have operators like '&' (AND), 'or' (OR) and '=' (EQUAL). I have defined in my parser.mly file the following priorities: """ /* 30 */ %left IMPLY /* 40 */ %left AND OR /* 60 */ %left EQUAL /* 115 */ %left COMMA /* 120 */ %left COLUMN /* 160 */ %left UNION MAPLET /* 170 */ %left DOTDOT /* 190 */ %left STAR /* 220 */ %left DOT """ So, if I read the ocamlyacc manual correctly the EQUAL operator (priority 60) should have higher priority than OR or AND operators (priority 40). Then, I define in my grammar a rule to parse an expression (exp): """ exp: LPAREN exp RPAREN { $2 } | INT MAPLET IDENTIFIER %prec MAPLET { Enum_value($1, $3) } | NOT LPAREN exp RPAREN { Not($3) } | exp SPACES EQUAL SPACES exp %prec EQUAL { Equal($1, $5) } | exp SPACES AND SPACES exp %prec AND { And($1, $5) } | exp SPACES OR SPACES exp %prec OR { Or($1, $5) } | exp SPACES IMPLY SPACES exp %prec IMPLY { Imply($1, $5) } | exp SPACES EQUALEQUAL SPACES exp { Equalequal($1, $5) } | exp UNION exp { Union($1, $3) } | exp STAR exp { Star($1, $3) } | exp COLUMN SPACES exp %prec COLUMN { In($1, $4) } | exp COMMA exp { Goal($1, $3) } | FIN LPAREN exp RPAREN { Fin($3) } | POVERSION { POVersion($1) } | UNDERSCORE_F { F($1) } | GOAL_NAME { match $1 with a, b -> Goal_name(a, b) } | COMMENT { Comment($1) } | LBRACKET RBRACKET { Empty_set } | enumerated_set { Enumerated_set($1) } | LPAREN INT DOTDOT INT RPAREN %prec DOTDOT { Interval($2, $4) } | IDENTIFIER { Identifier($1) } ; """ As far as I have correctly read the manual, I define the correct precedence for each rule, e.g. rule parsing the AND operator have the precedence of it. So far so good. However, after parsing, I have the following kind of tree: """ 1|->POSITION: {m1}\/{m2}\/{m3} & not(2|->POSITION = m1) & not(2|->POSITION = m2) & not(2|->POSITION = m3) & 3|->POSITION = 1|->POSITION or 2|->POSITION: {m1}\/{m2}\/{m3} & not(1|->POSITION = m1) & not(1|->POSITION = m2) & not(1|->POSITION = m3) & 3|->POSITION = 2|->POSITION or 1|->POSITION: {m1}\/{m2}\/{m3} => 2|->POSITION: {m1}\/{m2}\/{m3} & 2|->POSITION: {m1}\/{m2}\/{m3} => 1|->POSITION: {m1}\/{m2}\/{m3} """ It appears that the OR operator binds more tightly than the EQUAL operator! I should have: """ & 3|->POSITION = 1|->POSITION or 2|->POSITION: {m1}\/{m2}\/{m3} ... """ Could somebody explain to me the point I'm missing? I'm using OCaml 3.10.2 if it has any relevance. Sincerely yours, david