caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pietro Abate <Pietro.Abate@anu.edu.au>
To: caml-list@inria.fr
Subject: [Caml-list] camlp4 and let binding...
Date: Tue, 26 Nov 2002 11:07:19 +1100	[thread overview]
Message-ID: <20021126000718.GA20511@zed> (raw)

hi all,

I'm having few problems writing an camlp4 grammar for my project.
I would like to rewrite something something like

let rule_1 = x & y ; z => x + y ; z ;;

in a piece of ocaml code like

let rule_r = 
	let pattern =
		let p1 = And(x,y) in
		let p2 = Star in
		(p1,p2)
	in
	let action s =
		match s with
		|And(x,y)::z -> Plus(x,y)::z
		|_ -> failwith ("error")
	in new rule(pattern,action)

I wrote something that, of course, doesn't work. My major problems are about 
the inner let definitions. How can I chain all let defintions in the list ?


EXTEND

    str_item: [[
        "let"; r = LIDENT; "="; n = complexnum "=>"; d = complexnum ->
            let pref =  "rule" ^ r in
            let definition = n @ (genaction n d)  in (****)
            <str_item:<
            value $lid:pref$ = $list:definition$ in
            new rule(pattern,action) 
            >>
    ]];;

    complexnum: [[
        n = LIST1 numerator SEP ';' -> (<:patt< "pattern" >>, n)
    ]];

    numerator: [[
        pel = LIST1 pattern SEP ';' -> pel >>
    ]];

    pattern: [[
	n = LIDENT -> (<:patt< $genid$>, <expr:< $n$ >) (***)
	n1 = LIDENT; '&'; n2 = LIDENT ->
		(<:patt< $genid$>, <expr:< And( $n1$ , $n2$ ) > )
	n1 = LIDENT; '+'; n2 = LIDENT ->
		(<:patt< $genid$>, <expr:< Plus( $n1$ , $n2$ ) > )

    ]];
END

(***) genid is a simple function that generates unique identifiers...
(****) genaction should be a function that generates the action 
	(but I still have no idea how to write it...)

tnx for your help,
p

-- 
pgp key: 1024D/8A091922 2000-10-18 Pietro Abate <abate@discus.anu.edu.au>
Key fingerprint = 5111 D91B 5E0C 5CE6 FDA3  5EF4 6120 E18E 8A09 1922
public key avalaible via public key server at wwwkeys.eu.pgp.net
"Who says that something cannot be done should not interrupt a man who is 
doing it." --- Old Chinese Proverb
-------------------
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


             reply	other threads:[~2002-11-26 10:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-26  0:07 Pietro Abate [this message]
2002-11-26  4:29 Pietro Abate
2002-11-26 11:56 ` Daniel de Rauglaudre

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=20021126000718.GA20511@zed \
    --to=pietro.abate@anu.edu.au \
    --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).