Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Camlp4 parser question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ 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,

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: