On ocamlyacc, function application grammar and precedence
Posted
by Amadan
on Stack Overflow
See other posts from Stack Overflow
or by Amadan
Published on 2010-05-17T07:53:41Z
Indexed on
2010/05/17
8:00 UTC
Read the original article
Hit count: 286
I'm OCaml newbie and I'm trying to write a simple OCaml-like grammar, and I can't figure this out. My grammar allows something like this:
let sub = fun x -> fun y -> x - y;;
However, if I want to use the function so defined, I can write: (sub 7) 3
but I can't write sub 7 3
, which really bugs me. For some reason, it gets interpreted as if I wrote sub (7 3)
(which would treat 7
as a function with argument 3
). The relevant sections are:
/* other operators, then at the very end: */
%left APPLY
/* ... */
expr:
/* ... */
| expr expr %prec APPLY { Apply($1, $2) }
Thanks!
© Stack Overflow or respective owner