Browse thread
camlp4 help
- Pietro Abate
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pietro Abate <Pietro.Abate@a...> |
| Subject: | camlp4 help |
Hi all,
I'm having problems (once again) with camlp4...
I'd like to parse and produce a bit of ocaml code out of the
following description :
---------------------
CONNECTIVES
"_&_",AssocLeft,And ;
"_v_",AssocLeft,Or
END
TABLEAU
RULE "And"
{ A & B }
----------
A ; B
END
END
---------------
The first time around I used quotes around the "{A & B}" and parsed the
expression with a adhoc parser outside camlp4 (and it's all good and
working). Now I want to remove the quotes tut-cur and do everything
using the pre-processor (quotes make my code quote un-readable). I've
started writing this code below, but I don't know how to proceed...
The main problem is of course that I've to parse an expression (in rule),
with a generic parser built on the top of the connectives that I've just
declared. Is there a way to tell campl4 : pass everything in between
RULE and END to a function my_parser ?
I was looking for inspiration in M. Jambon excellent tutorial, but
without much luck...
thanks,
p
-----------------------(not tested)
let rule = Grammar.Entry.create Pcaml.gram "rule";;
let connective = Grammar.Entry.create Pcaml.gram "connective";;
type assoc = |AssocLeft |AssocRight |AssocNone ;;
let conntable = Hashtbl.create 15;;
EXTEND
Pcaml.str_item: [
"CONNECTIVES"; clist = LIST1 connective SEP ";"; "END" ->
List.iter Hashtbl.add conntable clist;
<:str_item< value version = "connectives declared" >>
|"TABLEAU"; LIST1 rule; "END" ->
<:str_item< value version = "tableau declared" >>
];
connective: [
s = STRING; ","; a = UIDENT; ","; r = UIDENT -> (s,a,r)
];
(* how can I write a quotation outside the EXTEND syntax ? *)
(* how does this quotation looks like ? *)
(* Quotation.add my_parser ??? *)
rule: [
"RULE"; r = my_parser ??? "END" -> do_something r
];
END
------------------------
--
++ Blog: 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