Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] camlp4 and let binding...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pietro Abate <Pietro.Abate@a...>
Subject: [Caml-list] camlp4 and let binding...
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