Re: Caml Parsing

Xavier Leroy (xleroy@pauillac.inria.fr)
Wed, 18 Sep 1996 16:42:11 +0200 (MET DST)

From: Xavier Leroy <xleroy@pauillac.inria.fr>
Message-Id: <199609181442.QAA02733@pauillac.inria.fr>
Subject: Re: Caml Parsing
To: zdance@cs.cornell.edu (Stephan Zdancewic)
Date: Wed, 18 Sep 1996 16:42:11 +0200 (MET DST)
In-Reply-To: <199609171857.OAA04386@earth.cs.cornell.edu> from "Stephan Zdancewic" at Sep 17, 96 02:57:12 pm

> 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