Browse thread
[Caml-list] Camlp4 parser question
- Peter Scott
[
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: | 2003-11-01 (00:30) |
From: | Peter Scott <sketerpot@c...> |
Subject: | [Caml-list] Camlp4 parser question |
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