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
a parsing question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: knotwell@f...
Subject: a parsing question
Hello all--

I've been writing a configuration file parser using ocaml's lex and
yacc.  So far, I've run into two things (actually they both grow out
of the same problem) that seem like there should be a better way
(NOTE: since I'm new the example will seem pretty contrived):

Let's say I have the following data:

and I want to parse out the 40 and stuff it into a data structure
usable *outside* of parser (assume lexer.mll, parser.mly, and  What I've currently done is the following:

(* parser.mly *)
(* NOTE:  I tried creating a yoyo_time object, but ocamlyacc
          apparently doesn't like the yoyo_time#set_time syntax *)
let yoyo_time = ref 10;;
let set_yoyo_time newtime = yoyo_time := (int_of_string newtime);;

%start <string> main
%type <string> INT

main: YOYO_TIME_BEGIN INT YOYO_TIME_END { set_yoyo_time $2; $2 }


Unfortunately, I don't know how to "export" yoyo_time to parser.mli.
My Makefile currently does the following:  

    echo "val yoyo_time: int ref" >> parser.mli

While this works fine, I'd like to avoid using Make as a post-processor.

I wondered about defining numerous entry points, but I presumed this
would force me to be extremely careful about the ordering in my config

Put another way, am I incorrect in assuming the lexer discards
previously unmatched data?

Since this is so long, I'll skip the second question--macros.