Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
ocaml parser
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-07-02 (15:34)
From: blue storm <bluestorm.dylc@g...>
Subject: Re: [Caml-list] ocaml parser
> 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'

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
    print_endline "Hello World"
  $ camlp4 pa_o.cmo pr_dump.cmo > test.out
  $ ocamlc -o test -impl test.out
  $ ./test
    Hello World