Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Angela Zhu <angela.zhu@c...>
Subject: Problem with precedence declaration in .mly file
Hi all,

I have some problem with precedence declaration in OCaml parser.
If I what to say exponential(ATOB) is prior to *(STAR) and / (DIVIDE),
  * and / are prior to +(PLUS)  and -(MINUS),
I wrote the following in the parser:


/***** Precedence Rules  *****/
...
%left PLUS MINUS
%left STAR DIVIDE
%left ATOB
...

But I still have the following problems:
(1) It appears that the parser
reads "test = 2^2 + 7;" as "test = 2^9" instead of "test = 4+7", which
would follow the conventional order of operations.

(2)It also interprets "test = (1^2)/3 + 1;" as "test = (1 ^ 2
/ (3 + 1));"

Can any one help me to see why it happens? Why the precedence rules  
doesn't work?

Thanks,
Angela
------------------------------------------
Dept. of CS, Rice U.
http://www.cs.rice.edu/~yz2/
------------------------------------------