> I'm trying to use the SML version of yacc to write a parser
> for Objective Caml, but I've run into problems because of some
> differences in SML-yacc and Caml-yacc. More precisely, Caml-yacc
> allows you to specify precedence and associativity for non-terminals
> in the grammar, while SML-yacc will let you do this only for
> terminals.
If you're talking about the "%prec" directive, I'm very, very
surprised that SML-yacc does not have an equivalent feature (to
override the default precedence and associativities assigned to a
production). It's the standard trick for handling e.g. unary minus,
and also very useful to resolve reduce/reduce conflicts. You may want
to check with the author of SML-yacc (David Tarditi, I think).
> Alternatively, does there exist a specification
> of the OCaml grammar that doesn't rely on these precedence
> levels/associativities?
There have been several attempts at writing recursive-descent parsers
for Caml, but none that will handle the whole O'Caml syntax. More
generally, it can be very hard to disambiguate a grammar by rewriting
the rules (as opposed to playing with precedences).
Regards,
- Xavier Leroy