Browse thread
Problem with precedence declaration in .mly file
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Oliver Bandel <oliver@f...> |
| Subject: | Re: [Caml-list] Problem with precedence declaration in .mly file |
Zitat von Angela Zhu <angela.zhu@cs.rice.edu>: > 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? [...] Precedences also can be created by sophisticated organization of the grammar rules. So, if your grammar rules may have a contradictory meaning, then your parser works not as expected. In general I would use the precedence-declarations only, when you run into parser conflicts, if you don't use them. When developing a grammr, I would recommend, first to start with the grammar rules, and add precedence-/associatitivity- declarations, at the end, if really necessary. What is the rest of your mly-file? A complete example would be helpful. Ciao, Oliver