Version française
Home     About     Download     Resources     Contact us    
Browse thread
passing argument in campl4 ?
[ 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: passing argument in campl4 ?
Hi all,

I've this small example below that I'd like to modify to
pass information top-down, from aa to bb (this is definitely
possible using parser and streams).

I see bb as a function but as it is translated (below below) 
is not entirely clear to me how I can pass a value from 

aa: [[ "AA"; c = bb "val" -> "aa"^c ]];
to 
bb arg: [[ a = INT; "BB" -> a ]];

I don't think this is directly possible (using the pseudo 
syntax above), but I was wonder if you have a trick to 
achieve something similar...

p


---------------- -------------------
(*pp camlp4o -I . pa_extend.cmo q_MLast.cmo *)

open Pcaml

let aa      = Grammar.Entry.create gram "aa"
let bb      = Grammar.Entry.create gram "bb"

EXTEND
   aa: [[ "AA"; c = bb -> "aa"^c ]];
   bb: [[ a = INT; "BB" -> a ]];
END

------------------dump ------------------------
(*pp camlp4o -I . pa_extend.cmo q_MLast.cmo *)

open Pcaml

let aa = Grammar.Entry.create gram "aa"
let bb = Grammar.Entry.create gram "bb"

let _ =
  Grammar.extend
    [Grammar.Entry.obj (aa : 'aa Grammar.Entry.e), None,
     [None, None,
      [[Gramext.Stoken ("", "AA");
        Gramext.Snterm (Grammar.Entry.obj (bb : 'bb Grammar.Entry.e))],
       Gramext.action
         (fun (c : 'bb) _ (loc : Lexing.position * Lexing.position) ->
            ("aa" ^ c : 'aa))]];
     Grammar.Entry.obj (bb : 'bb Grammar.Entry.e), None,
     [None, None,
      [[Gramext.Stoken ("INT", ""); Gramext.Stoken ("", "BB")],
       Gramext.action
         (fun _ (a : string) (loc : Lexing.position * Lexing.position) ->
            (a : 'bb))]]]


-- 
++ WebBlog/Diary: http://blog.rsise.anu.edu.au/?q=pietro
++
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html