Version française
Home     About     Download     Resources     Contact us    
Browse thread
ergonomie du compilateur
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: ergonomie du compilateur
> - There is no error recovery in the compiler. Before I start the
> first compile I have at least 5 syntax errors in the file. In
> order to find them I have to go through at least 5 edit-compile
> cycles, which I find very annoying.

My experience with ML compilers that attempt error recovery is that
they usually get it wrong and report many spurious syntax errors after
the first actual error, which is even more annoying than stopping at
the first error. Perhaps that's because of the ML syntax, which
has fewer obvious resynchronization points than, say, C syntax.

Also, as an implementor, I must say that I find parsing extremely
boring and prefer to concentrate on semantic issues. But all the usual
Yacc error recovery machinery is there, and any work on the OCaml
parser is welcome.

> - In case of a syntax error, the compiler never reports what it
> was expecting.

My understanding is that this can be done on a case by case basis,
using error productions. But I'm not sure it can be done in a
systematic way by reporting all tokens that the LALR tables are
expecting at that point. My recollection is that various Yacc
optimizations make this information (the set of expected tokens) hard
to recover from the transition tables.

> - I don't understand the behavior of "ocamlc -i" if an type error
> occurs. Especially in this case, where any information about the
> inferred types would be useful, it just prints nothing.

The "-i" option means ``typecheck the whole compilation unit, then
print out the inferred signature''. If the typing fails, nothing is
printed. Remember that a compilation unit, in OCaml, is parsed as a
whole, then typechecked as a whole, etc. There is no such thing as a
"phrase" or "toplevel definition" in a compilation unit.

In Caml Light there is actually a notion of "phrase" in a compilation
unit, and the "-i" option reports types on a phrase by phrase
basis. This is better for understanding type errors, but can alos lead
to inconsistent typings being printed. Consider:

        let r = ref []
        let f x = ... r := [1] ...

camlc -i reports

        value r : '_a list ref
        value f : ... -> ...

which is not right (the type of r is actually int list ref), while
ocamlc -i reports the correct types

        val r : int list ref
        val f : ... -> ...

Regards,

- Xavier Leroy