[
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: | -- (:) |
| From: | Pietro Abate <Pietro.Abate@a...> |
| Subject: | [Caml-list] genlex ... |
Hi all,
I'm re-writing the parser of my application and I'd like to write a kind
of generic parser that can parse a language that I can change dynamically...
In other words... My application is composed by a library, a set of
modules that are compiled separately and dynamically loaded and an
application that get the name of a module, a file and it parses the file
differently regarding the definions that it loads from the dynamic
module.
My point is that I want to have a generic parser that given a set of
keyword is able to parse different input.
so far I realized that I cannot do that with lex/yacc as they need a
compilation step (I could generate the lex/yacc file from the dynamic
module, but I think it's too messy...). But I can use Genlex.
Since I'm using Dynlink it's strightforward to load at runtime a
different set of keyword and initialized the lexer as :
let flexer = make_lexer Stub.variable_keyword_list
but at this point I don't know how to use the Genlex.parser to feed it
with my generic rules (every connective is declared as left assoc or non
assoc and the generic language is a calculator-like one ... )
I'd like to write something like
expr:
| LBRACK expr RBRACK { $2 }
| expr (keyword buf) expr { Tree(keyword_lookup buf,$1,$3)
| (keyword buf) expr { Leaf(keyword_lookup buf,$2)
| IDENT { Var($1)
where (keyword buf) is a function that returns 'Kwd if buf is a keyword
or fails ... Or using Genlex.parser as :
let rec parse_level1 = parser
[< e1 = parse_level0; e = parse_level11 e1 >] -> e
and parse_level11 e1 = parser
[< (keyword buf); e2 = parse_level1 >] ->
| [< >] -> e1
and parse_level0 = parser
[< (keyword buf); e = parse_level0 >] ->
....
is it possible ? does anybody can give me a small example ?
tnx,
P
--
Civilization advances by extending the number
of important operations which we can perform
without thinking. (Alfred North Whitehead)
-------------------
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