Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Problem with precedence declaration in .mly file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-10-31 (05:54)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Problem with precedence declaration in .mly file

On Tue, 2007-10-30 at 23:26 -0500, Angela Zhu wrote:

> /***** Precedence Rules  *****/
> ...
> %left PLUS MINUS
> %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 <skaller at users dot sf dot net>
Felix, successor to C++: