From: Andre Nathan <andre@sneakymustard.com>
To: caml-list@inria.fr
Subject: Camlp4 help
Date: Sat, 21 Mar 2009 00:41:03 -0300 [thread overview]
Message-ID: <1237606863.5943.0.camel@homesick> (raw)
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
next reply other threads:[~2009-03-21 3:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-21 3:41 Andre Nathan [this message]
2009-03-21 15:26 ` [Caml-list] " blue storm
2009-03-21 16:14 ` Andre Nathan
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
2005-07-15 8:39 camlp4 help Pietro Abate
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=1237606863.5943.0.camel@homesick \
--to=andre@sneakymustard.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