caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
To: Caml mailing list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] How can I generate an AST?
Date: Mon, 20 Aug 2007 13:13:50 +0200	[thread overview]
Message-ID: <20070820111350.GA22843@yquem.inria.fr> (raw)
In-Reply-To: <6f9f8f4a0708200122k710b2f3dnd723a7244140575e@mail.gmail.com>

Hi,

On Mon, Aug 20, 2007 at 10:22:17AM +0200, Loup Vaillant wrote:

> This may be a better approach. However, I am not eager to use camlp*,
> for it will introduce a additional dependency. I may choose this
> however, if the camlp* AST is simpler than the Ocaml AST. Where can I
> find it?

Solution using camlp5:

  For the syntax tree, look at:
    http://pauillac.inria.fr/~ddr/camlp5/doc/html/ml_ast.html

  You can generate abstract syntax tree by using concrete syntax. For
  example, the syntax tree for the "if" statement is (in revised syntax):
    MLast.ExIfe loc e1 e2 e3

  but you can write it with quotations (in revised syntax):
    <:expr< if $e1$ then $e2$ else $e3$ >>

  and build syntax trees as complicated as you want using quotations.

  But, well, you need to know camlp5, understand the quotation system,
  perhaps the revised syntax too, in one word, read the doc, and I can
  understand that if you did not use camlp5 before, it is some work...

Solution using camlp4:

  The principle is the same but the syntax tree is different.

Other solution not using camlp*:

  Read the ocaml sources, file "parsing/parser.mly" to understand how
  the ocaml syntax tree works. Program your parser to generate this
  syntax tree. Once done, to give your syntax tree directly to the
  ocaml compiler, output:

  1/ the magic number you can find in ocaml sources at utils/config.ml
       - ast_impl_magic_number for an implementation
         ast_intf_magic_number for an interface
  2/ your input file name
  3/ your syntax tree in binary with "output_value"

-- 
Daniel de Rauglaudre
http://pauillac.inria.fr/~ddr/


  reply	other threads:[~2007-08-20 11:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-19 17:39 Loup Vaillant
2007-08-19 18:16 ` [Caml-list] " Daniel de Rauglaudre
2007-08-20  8:22   ` Loup Vaillant
2007-08-20 11:13     ` Daniel de Rauglaudre [this message]
2007-08-20 13:24       ` Loup Vaillant
2007-08-20 13:29         ` Massimiliano Brocchini
2007-08-20 15:45         ` Daniel de Rauglaudre
     [not found]           ` <6f9f8f4a0708220222q5ea56138u8b4c85dd4c35c56e@mail.gmail.com>
     [not found]             ` <20070822103226.GA12907@yquem.inria.fr>
2007-08-22 13:47               ` Loup Vaillant
2007-08-19 21:37 ` Alain Frisch
2007-08-20  8:29   ` Loup Vaillant

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070820111350.GA22843@yquem.inria.fr \
    --to=daniel.de_rauglaudre@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).