caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Misunderstandings about the AST
@ 2007-03-27 13:44 Loup Vaillant
  2007-03-27 14:06 ` [Caml-list] " Nicolas Pouillard
  2007-03-27 14:13 ` Jeremy Yallop
  0 siblings, 2 replies; 5+ messages in thread
From: Loup Vaillant @ 2007-03-27 13:44 UTC (permalink / raw)
  To: caml-list

Good afternoon,

Pursuing my goal of making a lisp syntax for Ocaml, I began to take a
close look at the AST (Ocaml-3.09.3/parsing/parsetree.mli). I don't
understand some of the constructors in the type expression_desc:


| Pexp_function of label * expression option * (pattern * expression) list
What is the "expression option" for?

| Pexp_construct of Longident.t * expression option * bool

What is the boolean for?

| Pexp_variant of label * expression option

What is a "variant"? (Does not seem to be related to variant types, as
"Pexp_construct" is used for them)

| Pexp_record of (Longident.t * expression) list * expression option
What is the "expression option" for?

| Pexp_constraint of expression * core_type option * core_type option
Why two "core_type option", instead of just a "core_type"?

| Pexp_when of expression * expression
Why not "pattern * expression"?

| Pexp_send of expression * string
What does "Pexp_send" stand for?

| Pexp_new of Longident.t
What does "Pexp_new" stand for?

| Pexp_setinstvar of string * expression
What does "Pexp_setinstvar" stand for?

| Pexp_override of (string * expression) list
What does "Pexp_override" stand for?

| Pexp_lazy of expression
Why does this constructor even exist? Are some specific optimizations made?

| Pexp_poly of expression * core_type option
What does "Pexp_poly" stand for?


Phew, I am done, for now. Except one question: is the AST likely to
change, or else is it likely to be standardized (so any freak like me
can try her fancy syntax)?.

By the way, I would like to see documentation about the AST (or other
related part of Ocaml's implementation). The sources are great, and
highly readable, but I am afraid of hitting a wall.

Thanks
Loup


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Misunderstandings about the AST
  2007-03-27 13:44 Misunderstandings about the AST Loup Vaillant
@ 2007-03-27 14:06 ` Nicolas Pouillard
       [not found]   ` <6f9f8f4a0703271034m3be7cdc8t43708c8a8a2144ce@mail.gmail.com>
  2007-03-27 14:13 ` Jeremy Yallop
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolas Pouillard @ 2007-03-27 14:06 UTC (permalink / raw)
  To: Loup Vaillant; +Cc: caml-list

On 3/27/07, Loup Vaillant <loup.vaillant@gmail.com> wrote:
> Good afternoon,
>
> Pursuing my goal of making a lisp syntax for Ocaml, I began to take a
> close look at the AST (Ocaml-3.09.3/parsing/parsetree.mli). I don't
> understand some of the constructors in the type expression_desc:
>
>
> | Pexp_function of label * expression option * (pattern * expression) list
> What is the "expression option" for?

The default value for labeled arguments  << fun ?(label=default_value) -> ... >>

> | Pexp_construct of Longident.t * expression option * bool
>
> What is the boolean for?

Ha, ha...

Is one is more tricky this it seems not produced by the parser (my
main source of inspiration for this mail). In fact it's use by camlp4,
and it means that you know that the arity is good.

When you write:

A(x, y) how to know if it's 2 args for A or 1 arg but a pair.

If you directly produce AST nodes and that you know want you do you
can set this flag to true.

> | Pexp_variant of label * expression option
>
> What is a "variant"? (Does not seem to be related to variant types, as
> "Pexp_construct" is used for them)

It's for polymorphic variants, checkout the documentation...

> | Pexp_record of (Longident.t * expression) list * expression option
> What is the "expression option" for?

{ (expression) with field1 = expr1; ... ; fieldN = exprN }

> | Pexp_constraint of expression * core_type option * core_type option
> Why two "core_type option", instead of just a "core_type"?

Since there is 3 type of constraints.

(e : t)

(e :> t)

(e : t1 :> t2)

> | Pexp_when of expression * expression
> Why not "pattern * expression"?

The `when' form is:

pattern when expr1 -> expr2

expr1 and expr2 are paired with Pexp_when

> | Pexp_send of expression * string
> What does "Pexp_send" stand for?

Method call.

object_value#method_name

> | Pexp_new of Longident.t
> What does "Pexp_new" stand for?

new class_name

> | Pexp_setinstvar of string * expression
> What does "Pexp_setinstvar" stand for?

object_value.instance_variable <- expr

> | Pexp_override of (string * expression) list
> What does "Pexp_override" stand for?

{< instvar1 = expr1 ; ... ; instvarN = exprN >}

Same as { expr with ... } but for objects and automatically on self.

> | Pexp_lazy of expression
> Why does this constructor even exist? Are some specific optimizations made?

Since the evaluation of the expression is delayed it's not a plain function.

> | Pexp_poly of expression * core_type option
> What does "Pexp_poly" stand for?

It's for methods with polymorphic types, some syntax nodes are
inserted to keep track of this polymorphism.

Regards,

-- 
Nicolas Pouillard


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Misunderstandings about the AST
  2007-03-27 13:44 Misunderstandings about the AST Loup Vaillant
  2007-03-27 14:06 ` [Caml-list] " Nicolas Pouillard
@ 2007-03-27 14:13 ` Jeremy Yallop
  1 sibling, 0 replies; 5+ messages in thread
From: Jeremy Yallop @ 2007-03-27 14:13 UTC (permalink / raw)
  Cc: caml-list

Loup Vaillant wrote:
> Pursuing my goal of making a lisp syntax for Ocaml, I began to take a
> close look at the AST (Ocaml-3.09.3/parsing/parsetree.mli). I don't
> understand some of the constructors in the type expression_desc:

Reading the source for the parser (where these constructors are used) 
and comparing it with the documentation should help you find the answers 
to almost all of your questions.

Parser source:
http://camlcvs.inria.fr/cgi-bin/cvsweb/ocaml/parsing/parser.mly?rev=1.126

Language reference:
http://caml.inria.fr/pub/docs/manual-ocaml/manual008.html

Jeremy.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Misunderstandings about the AST
       [not found]   ` <6f9f8f4a0703271034m3be7cdc8t43708c8a8a2144ce@mail.gmail.com>
@ 2007-03-28  6:42     ` Loup Vaillant
  2007-03-28 12:30       ` Nicolas Pouillard
  0 siblings, 1 reply; 5+ messages in thread
From: Loup Vaillant @ 2007-03-28  6:42 UTC (permalink / raw)
  To: Caml mailing list

Thank you for your help, I will get back to work.

2007/3/27, Nicolas Pouillard <nicolas.pouillard@gmail.com>:
> On 3/27/07, Loup Vaillant <loup.vaillant@gmail.com> wrote:
> > | Pexp_lazy of expression
> > Why does this constructor even exist? Are some specific optimizations made?
>
> Since the evaluation of the expression is delayed it's not a plain function.

Actually, I knew that.
However, given the following expressions are semantically equivalent:

lazy expr;;
lazy_from_fun (fun () -> expr);;

With "lazy_from_fun" being a plain function,
my point is then to know if they are really equivalent
(e.g. implementation wise), so I can assume
the keyword "lazy" is just syntactic sugar.

Loup

PS: Nicolas, Sorry for the double post, I messed up the "reply" button.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Misunderstandings about the AST
  2007-03-28  6:42     ` Loup Vaillant
@ 2007-03-28 12:30       ` Nicolas Pouillard
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolas Pouillard @ 2007-03-28 12:30 UTC (permalink / raw)
  To: Loup Vaillant; +Cc: Caml mailing list

On 3/28/07, Loup Vaillant <loup.vaillant@gmail.com> wrote:
> Thank you for your help, I will get back to work.
>
> 2007/3/27, Nicolas Pouillard <nicolas.pouillard@gmail.com>:
> > On 3/27/07, Loup Vaillant <loup.vaillant@gmail.com> wrote:
> > > | Pexp_lazy of expression
> > > Why does this constructor even exist? Are some specific optimizations made?
> >
> > Since the evaluation of the expression is delayed it's not a plain function.
>
> Actually, I knew that.
> However, given the following expressions are semantically equivalent:
>
> lazy expr;;
> lazy_from_fun (fun () -> expr);;
>
> With "lazy_from_fun" being a plain function,
> my point is then to know if they are really equivalent
> (e.g. implementation wise), so I can assume
> the keyword "lazy" is just syntactic sugar.

I think that's safe to assume it.

-- 
Nicolas Pouillard


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-03-28 12:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-27 13:44 Misunderstandings about the AST Loup Vaillant
2007-03-27 14:06 ` [Caml-list] " Nicolas Pouillard
     [not found]   ` <6f9f8f4a0703271034m3be7cdc8t43708c8a8a2144ce@mail.gmail.com>
2007-03-28  6:42     ` Loup Vaillant
2007-03-28 12:30       ` Nicolas Pouillard
2007-03-27 14:13 ` Jeremy Yallop

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).