caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] camlp4 and let binding...
@ 2002-11-26  0:07 Pietro Abate
  0 siblings, 0 replies; 3+ messages in thread
From: Pietro Abate @ 2002-11-26  0:07 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread
* [Caml-list] camlp4 and let binding...
@ 2002-11-26  4:29 Pietro Abate
  2002-11-26 11:56 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 3+ messages in thread
From: Pietro Abate @ 2002-11-26  4:29 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-11-26 11:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-26  0:07 [Caml-list] camlp4 and let binding Pietro Abate
2002-11-26  4:29 Pietro Abate
2002-11-26 11:56 ` Daniel de Rauglaudre

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).