On Wed, Mar 4, 2009 at 2:45 PM, Jonathan S. Shapiro <[email protected]> wrote:
> I'm looking at the OCaml syntax. The syntax for expressions includes:
>
>  expr :=  expr ';' expr      # sequencing
>  expr := let BINDING in EXPR
>
> which means that
>
>  let BINDING in EXPR ; let BINDING in EXPR
>
> is legal but ambiguous. It is either:
>
>  let BINDING in (EXPR ; let BINDING in EXPR)
>  (let BINDING in EXPR ); let BINDING in EXPR
>
> what means does the compiler use to resolve this ambiguity?

I'm not sure about the details of how the stock compiler does this,
but it's conceptually just precedence.  ";" has higher precedence than
"let", so the result is

    let BINDING in (EXPR; let BINDING in EXPR)

There are a slew of similar ambiguities as well.  When I wrote an
ocaml parser my first draft had several thousand shift/reduce
conflicts.  Unfortunately, I don't believe I was able to resolve all
of them with precedence declarations, and eventually had to split the
expression grammar into several different levels.  It was all quite
painful, but worked fine in the end.

Geoffrey

Geoffrey
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to