Version française
Home     About     Download     Resources     Contact us    
Browse thread
Camlp4 help
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: blue storm <bluestorm.dylc@g...>
Subject: Re: [Caml-list] Camlp4 help
This is not a camlp4-specific problem : the grammar you described
apparently do not conform to what you have in mind.

According to your definition, the "sum do ... done" can only contain
"sum" forms, not an arbitrary expression. The only valid way to parse
"sum do let a = b in a plus c done" is thus "sum do (let a = b in a)
plus b done", as "sum do let a = b in (a plus b) done" has an
expression (instead of a sum) between do ... done (and a sum in expr
position, wich is also incorrect, but it can also be parsed as a
correct expression).

What is the syntax you want to be supported ?

On 3/21/09, Andre Nathan <andre@sneakymustard.com> wrote:
> Hello
>
> I'm just beginning with camlp4 here, and I'm stuck with what I think is
> a precedence issue. I have the following syntax extension:
>
> open Camlp4.PreCast
> open Syntax
>
> let sum = Gram.Entry.mk "sum"
>
> EXTEND Gram
>   expr: LEVEL "top"
>     [ [ "sum"; "do"; seq = LIST1 sum; "done" ->
>         <:expr< do { $list:seq$ } >> ] ]
>     ;
>   sum:
>     [ [ x = expr; "plus"; y = expr ->
>         <:expr< $x$ + $y$ >> ] ]
>     ;
> END
>
> This works fine for something like this:
>
> sum do
>   1 plus 2
> done
>
> which becomes (1 + 2).
>
> However, it breaks on
>
> sum do
>   let a = 1 in
>   let b = 2 in
>   a plus b
> done
>
> because it becomes ((let a = 1 in let b = 2 in a) + b).
>
> How can fix that (allowing "b" to be in scope for the second argument of
> "plus")?
>
> Also, sequences of operations don't parse:
>
> sum do
>   1 + 2;
>   3 + 4
> done
>
> gives "Parse error: [sum] or "done" expected (in [expr])"
>
> What am I missing here?
>
> Thanks in advance,
> Andre
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>