caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Camlp4 parser question
@ 2003-11-01  0:49 Peter Scott
  0 siblings, 0 replies; only message in thread
From: Peter Scott @ 2003-11-01  0:49 UTC (permalink / raw)
  To: caml-list

I'm making an interpreter for my own language. I have it to the point where 
it can parse the syntax of my language, make an abstract syntax tree, and 
evaluate it. The problem is that the program is structured as a list of 
lines, and I have no way of denoting block structure for these lines. The 
consequence: I can't have control flow in my language. I'm trying to get 
block structure in my internal representation.

Here is what I'm trying to do, boiled down to a simple example:

type section =
     Num of int
   | Block of section list;;

let testStream = [< '"1"; '"2"; '"3"; '"beginblock"; '"4"; '"5"; '"6"; 
'"endblock"; '"7"; '"8"; '"9" >];;

let whatIWant = [Num 1; Num 2; Num 3; Block [Num 4; Num 5; Num 6]; Num 7; 
Num 8; Num 9];;

I want (in my example) to change the "beginblock"..."endblock" into Block 
[...]. How would you do this with a parser? I don't know if a parser can 
match a variable number of elements until it reaches some delimiter telling 
it to stop, but that's what I want to do.

Thank you,
-Peter

-------------------
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] only message in thread

only message in thread, other threads:[~2003-11-01  0:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-01  0:49 [Caml-list] Camlp4 parser question Peter Scott

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