caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andre Nathan <andre@sneakymustard.com>
To: blue storm <bluestorm.dylc@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Camlp4 help
Date: Sat, 21 Mar 2009 13:14:36 -0300	[thread overview]
Message-ID: <1237652076.6137.15.camel@homesick> (raw)
In-Reply-To: <527cf6bc0903210826r5a0c079bm71068f5b1d89ebe1@mail.gmail.com>

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 <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
> >
> 
> _______________________________________________
> 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


  reply	other threads:[~2009-03-21 16:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-21  3:41 Andre Nathan
2009-03-21 15:26 ` [Caml-list] " blue storm
2009-03-21 16:14   ` Andre Nathan [this message]
2009-03-21 17:24     ` blue storm
2009-03-21 17:26       ` blue storm
  -- strict thread matches above, loose matches on Subject: below --
2009-04-13  0:05 Andre Nathan
2009-04-13 19:08 ` [Caml-list] " Andre Nathan
2005-07-15  8:39 camlp4 help Pietro Abate
2005-07-15 20:24 ` [Caml-list] " Martin Jambon
2005-07-18 10:12 ` Hendrik Tews
2005-07-19  5:23   ` Pietro Abate
2005-07-20  7:37     ` Hendrik Tews
2005-07-20  9:57       ` Gerd Stolpmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1237652076.6137.15.camel@homesick \
    --to=andre@sneakymustard.com \
    --cc=bluestorm.dylc@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).