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
camlp5/revised syntax questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-10-08 (14:39)
From: Aaron Bohannon <bohannon@c...>
Subject: Re: [Caml-list] camlp5/revised syntax questions
Thanks for your detailed reply.  I had a suspicion I would have to
read the source code to get the all of the necessary documentation.
However, I'm still missing some basic point here.

On Wed, Oct 7, 2009 at 4:16 PM, blue storm <> wrote:
> The different "level names" are not absolute among all camlp4 grammars
> : they're a property of each grammar rule of each grammar. If you want
> to "modify" a specific grammar (that is, EXTEND it), you must check
> the different levels available in the definition.

Yes, I understand that.  But how do you specify which grammar your
file is extending?  My file is structured like this:

#load "pa_extend.cmo";
#load "q_MLast.cmo";
open Pcaml;

  GLOBAL: expr;

So where did I specify whether I was extending the original syntax or
the revised syntax (or some other grammar entirely)?  I suppose I must
have implicitly chosen the original syntax because my code works fine
on that.

> While concrete syntaxes for revised and classical syntax are
> different, the abstract syntax tree is the same. Camlp4 quotations
> works by replacing (using camlp4) the quotation you wrote by the
> concrete ocaml AST representation.

Yes, this point is crystal clear, and I have no problem writing the
quotations in the revised syntax.

> In your specific case, you can parse whatever syntax you want using
> the "<-" operator, then output the corresponding AST using a quotation
> in the revised syntax, that is <:expr< a := b >> (instead of "a <-
> b"). For a reference, see the related rules in etc/ :
>  | ":=" NONA
>    [ e1 = SELF; ":="; e2 = expr LEVEL "expr1" ->
>      <:expr< $e1$.val := $e2$ >>
>    | e1 = SELF; "<-"; e2 = expr LEVEL "expr1" ->
>      <:expr< $e1$ := $e2$ >> ]

Thanks, I found this piece of code.  Now on a more specific point, I
am confused about the parsing of record access and update:

1) In the parsing rule for the simple dot noation...

      | e1 = SELF; "."; e2 = SELF -> <:expr< $e1$ . $e2$ >> ]

...why is the field label an "expr"?  This does not agree with the
OCaml manual, which has a separate syntactic category for "field"
(, nor with my
intuition about the meaning of the code.

2) Furthermore, as one can see from the ":=" entry above, the entire
left side of a record update is parsed as its own subexpression.  So
this means, that in the context of a record update, that subexpression
has to be interpreted as a reference, but in other contexts, the very
same expression must be interpreted as a value.  I don't necessarily
care what kind of magic makes this possible on the back end, but I am
wondering whether this has any implications for modifying the record

 - Aaron