* [Caml-list] Question about camlp4
@ 2002-03-25 10:13 Frederic Tronel
2002-03-25 10:52 ` Daniel de Rauglaudre
0 siblings, 1 reply; 3+ messages in thread
From: Frederic Tronel @ 2002-03-25 10:13 UTC (permalink / raw)
To: caml-list
Hello,
I'm using ocaml 3.04.
I'm trying to extend ocaml syntax, using camlp4.
But I'm facing a problem.
I have the following rule in my grammar:
spec_exp: [[ "specification" ; name = LIDENT; "[" ; g = LIST0 gate_exp
SEP "," ; "]" -> <:expr<Specification $str:name$ $list:g$ >> ]]
and the following definition of type spec:
type spec = Specification of string * gate list
However it does not compile. The compilation returns with the following
error code:
File "lotos.ml", line 46, characters 123-131:
While expanding quotation "expr":
Parse error: end of input expected after [expression] (in [expression])
Preprocessing error
It is related with the term $list:g$. If I replace it with [| $list:g$
|] (for example)
the compilation will fail later saying that the constructor
Specification
expects a gate list, not a gate array, which is somehow reasonable.
My question is the following one:
How can I explain that I what the MLast.expr of a list, when $g$ is a
MLast.expr list ????
I did not found the answer in the documentation.
Best regards,
Frederic Tronel.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Question about camlp4
2002-03-25 10:13 [Caml-list] Question about camlp4 Frederic Tronel
@ 2002-03-25 10:52 ` Daniel de Rauglaudre
[not found] ` <3C9F13DE.7B2F4BD2@inrialpes.fr>
0 siblings, 1 reply; 3+ messages in thread
From: Daniel de Rauglaudre @ 2002-03-25 10:52 UTC (permalink / raw)
To: caml-list
Hi,
On Mon, Mar 25, 2002 at 11:13:48AM +0100, Frederic Tronel wrote:
> spec_exp: [[ "specification" ; name = LIDENT; "[" ; g = LIST0 gate_exp
> SEP "," ; "]" -> <:expr<Specification $str:name$ $list:g$ >> ]]
There is no node "list" in the abstract syntax tree. The antiquotation
of type "list" cannot be used to create the tree node of a list.
To build your your list node, you have to apply the contructors :: and []:
List.fold_right (fun x l -> <:expr< [$x$ :: $l$] >>) g <:expr< [] >>
Your code could then be:
spec_exp:
[[ "specification" ; name = LIDENT; "[" ; g = LIST0 gate_exp
SEP "," ; "]" ->
let e =
List.fold_right (fun x l -> <:expr< [$x$ :: $l$] >>) g
<:expr< [] >>
in
<:expr<Specification $str:name$ $e$ >> ]]
Note: this is different if you would want to create an array, because
arrays are built by one construction. You can write:
<:expr<Specification $str:name$ [| $list:e$ |] >>
--
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Question about camlp4
[not found] ` <20020325143309.H15808@verdot.inria.fr>
@ 2002-03-25 13:57 ` Frederic Tronel
0 siblings, 0 replies; 3+ messages in thread
From: Frederic Tronel @ 2002-03-25 13:57 UTC (permalink / raw)
To: Daniel de Rauglaudre, caml-list
Daniel de Rauglaudre wrote:
>
> Salut,
>
> > Thanks for your prompt answer.
> > Why not adding a special construction for building lists directly ??
>
> Chais pas si c'est intentionnel de ta part, mais tu m'as juste répondu
> à moi personnellement et pas dans la mailing list, alors je te réponds
> en français, s'pas...
J'ai repondu trop vite.
>
> La réponse est qu'il y n'y a qu'une seule représentation pour les listes.
> Le type des listes est équivalent à quelque chose du genre:
> type 'a mylist =
> Nil
> | Cons of 'a * 'a mylist
>
> Toi, ce que tu demandes, c'est que ça puisse être:
> type 'a mylist =
> Nil
> | Cons of 'a * 'a mylist
> | List of 'a list
>
> Du coup, la liste [1; 2] aurait plusieurs représentations possibles:
> Cons (1, Cons (2, Nil))
> List [1; 2]
> Cons (1, List [2])
>
> Bien sûr, on pourrait faire en sorte que <:expr< $list:x$ >> soit un
> raccourci de mon List.fold_left. Ça marcherait en position d'expression
> mais pas en position de pattern, comme par exemple:
> function <:expr< $list:e$ >> -> e
>
> car il faudrait que le pattern matching extraie la liste e constituée
> des élements de la liste, liste qui n'existe pas forcément, si le
> noeud d'arbre de syntaxe est juste un Cons de deux variables, par
> exemple.
D'accord, j'ai compris. Est-il possible que cela soit indique dans
la doc (ca l'est peut-etre, mais je ne l'ai pas vu).
Frederic.
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-03-25 13:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-25 10:13 [Caml-list] Question about camlp4 Frederic Tronel
2002-03-25 10:52 ` Daniel de Rauglaudre
[not found] ` <3C9F13DE.7B2F4BD2@inrialpes.fr>
[not found] ` <20020325143309.H15808@verdot.inria.fr>
2002-03-25 13:57 ` Frederic Tronel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox