From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id MAA30602; Mon, 7 Jul 2003 12:13:34 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA03974 for ; Mon, 7 Jul 2003 12:13:33 +0200 (MET DST) Received: from axiom.anu.edu.au (axiom.anu.edu.au [150.203.127.200]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h67ADVf08507 for ; Mon, 7 Jul 2003 12:13:31 +0200 (MET DST) Received: from pulp.anu.edu.au (pulp.anu.edu.au [150.203.126.25]) by axiom.anu.edu.au (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id h67ADSG07273 (using TLSv1/SSLv3 with cipher EDH-RSA-DES-CBC3-SHA (168 bits) verified NO) for ; Mon, 7 Jul 2003 20:13:29 +1000 Received: from pulp.anu.edu.au (localhost [127.0.0.1]) by pulp.anu.edu.au (8.12.9/8.12.9/Debian-5) with ESMTP id h67ADiOf013830 for ; Mon, 7 Jul 2003 20:13:45 +1000 Received: (from abate@localhost) by pulp.anu.edu.au (8.12.9/8.12.9/Debian-5) id h67ADi49013827 for caml-list@inria.fr; Mon, 7 Jul 2003 20:13:44 +1000 Date: Mon, 7 Jul 2003 20:13:44 +1000 From: Pietro Abate To: caml-list@inria.fr Subject: [Caml-list] genlex ... Message-ID: <20030707101344.GA13301@anu.edu.au> Mail-Followup-To: Pietro Abate , caml-list@inria.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: GNU/Linux X-Organization: Research School of Information Science and Engineering (Australian National University) User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pietro:01 abate:01 re-writing:01 generic:01 dynamically:01 parses:01 dynlink:01 runtime:01 initialized:01 stub:01 expr:01 'kwd:01 rec:01 buf:01 parser:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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