ocaml parser

View: New views
4 Messages — Rating Filter:   Alert me  

ocaml parser

by Christophe Raffalli-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Dear list members and ocaml developper,

Is it a bug to have any difference between both ocaml parser (with "-pp
camlp4o" or without) ?

I expected that everything that compiles with ocamlc should compile with
ocamlc -pp camlp4o
(the opposite is not true and does not need to be true) which is not the
case.

And a secondary question : why to have two parsers (except maybe for
bootstraping) ?

Here is an example:

-------- test.ml ------
let parser = 0
-------- en test.ml --

Tocksi:pml christopheraffalli$ ocamlc -c test.ml
Tocksi:pml christopheraffalli$ ocamlc -c -pp camlp4o test.ml
File "test.ml", line 1, characters 0-3:
Parse error: [binding] expected after [opt_rec] (in [str_item])
Preprocessor error

(remark: this is the error message from ocaml 3.10, the error from 3.09
was clearer).

Cheers,
Christophe

--
Christophe Raffalli
Universite de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tel: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@...
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature. The public key is
stored on www.keyserver.net
---------------------------------------------


[Christophe_Raffalli.vcf]

begin:vcard
fn:Christophe Raffalli
n:Raffalli;Christophe
org:LAMA (UMR 5127)
email;internet:christophe.raffalli@...
title;quoted-printable:Ma=C3=AEtre de conf=C3=A9rences
tel;work:+33 4 79 75 81 03
note:http://www.lama.univ-savoie.fr/~raffalli
x-mozilla-html:TRUE
version:2.1
end:vcard




_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

signature.asc (257 bytes) Download Attachment

Re: ocaml parser

by Michel Mauny :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Christophe Raffalli écrit/writes [07/01/2008 06:34 PM] :

> Is it a bug to have any difference between both ocaml parser (with "-pp
> camlp4o" or without) ?

In some situations yes, in others no.

> I expected that everything that compiles with ocamlc should compile with
> ocamlc -pp camlp4o
> (the opposite is not true and does not need to be true) which is not the
> case.

Camlp4o is supposed to parse all OCaml plus things such as stream
parsers.  Since adding keywords ("parser", for instance) may break
legal OCaml programs, Camlp4o is supposed to parse OCaml programs that
don't conflict with such extensions.  Camlp4o cannot therefore parse
_all_ OCaml programs.

> And a secondary question : why to have two parsers (except maybe for
> bootstraping) ?

I'm not sure I understand your question, but the OCaml and Camlp4o
parsers use a different technology. The latter is extensible while the
former is not.

-- Michel

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Re: ocaml parser

by Christophe Raffalli-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>
>
>> And a secondary question : why to have two parsers (except maybe for
>> bootstraping) ?
>
> I'm not sure I understand your question, but the OCaml and Camlp4o
> parsers use a different technology. The latter is extensible while the
> former is not.

I just think one parser technology (-pp camlp4o by default) sounds
better to me !
This is a problem when you generate ocaml code that you must make sure
to be compatible
with as many as possible OCaml parsers ...

Christophe
>
> -- Michel
>
>


--
Christophe Raffalli
Universite de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tel: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@...
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature. The public key is
stored on www.keyserver.net
---------------------------------------------


[Christophe_Raffalli.vcf]

begin:vcard
fn:Christophe Raffalli
n:Raffalli;Christophe
org:LAMA (UMR 5127)
email;internet:christophe.raffalli@...
title;quoted-printable:Ma=C3=AEtre de conf=C3=A9rences
tel;work:+33 4 79 75 81 03
note:http://www.lama.univ-savoie.fr/~raffalli
x-mozilla-html:TRUE
version:2.1
end:vcard




_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

signature.asc (257 bytes) Download Attachment

Re: ocaml parser

by bluestorm.dylc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Is it a bug to have any difference between both ocaml parser (with "-pp camlp4o" or without) ?
camlp4o add some extensions to the ocaml syntax (streams and parser,
thus your conflict). But you can use a bare "camlp4" preprocessor,
adding it only the ocaml parser, and you wouldn't get those
incompatibilities :
  $ ocamlc -pp 'camlp4 pa_o.cmo pr_dump.cmo' test.ml

As explained in the man page :
       The command camlp4o is a shortcut for:
           camlp4 pa_o.cmo pa_op.cmo pr_dump.cmo
(pa_op.cmo providing streams and parser syntax)

> This is a problem when you generate ocaml code that
> you must make sure to be compatible
> with as many as possible OCaml parsers ...

An other solution would be to use the camlp4 libraries to output a
piece of OCaml AST directly, wich you can then read and interpret
directly and without ambiguities, without going through an additional
parsing stage. The pr_dump.cmo printer achieve this, although i'm not
exactly sure how you should proceed from an independent generator :
  $ cat test.ml
    print_endline "Hello World"
  $ camlp4 pa_o.cmo pr_dump.cmo test.ml > test.out
  $ ocamlc -o test -impl test.out
  $ ./test
    Hello World

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
LightInTheBox - Buy quality products at wholesale price