Hi On Sat, 2009-03-21 at 16:26 +0100, blue storm wrote: > This is not a camlp4-specific problem : the grammar you described > apparently do not conform to what you have in mind.
I think I understand, although I thought the "x = expr" rule in the sum form definition meant that before "plus" any expression would be allowed. I want to allow any expression inside a "sum" block, which I think I could do by defining it as a new rule in "expr", but I'd like "plus" expressions to only be allowed inside a "sum" block, which I'm not sure how to do. Thanks, Andre > > 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 <an...@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 > > > > _______________________________________________ > 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 _______________________________________________ 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