[
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: | 2000-05-04 (16:49) |
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: <yoyo-time> 40 </yoyo-time> 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 config_test.ml). 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);; %} %token YOYO_TIME_BEGIN YOYO_TIME_END INT %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 file. 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. Thanks. --Brad