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 CAA23860; Tue, 8 Jul 2003 02:34:05 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA19008 for ; Tue, 8 Jul 2003 02:34:04 +0200 (MET DST) Received: from axiom.anu.edu.au (axiom.anu.edu.au [150.203.127.200]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h680Y2T27729 for ; Tue, 8 Jul 2003 02:34:02 +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 h680XxG13262 (using TLSv1/SSLv3 with cipher EDH-RSA-DES-CBC3-SHA (168 bits) verified NO) for ; Tue, 8 Jul 2003 10:33:59 +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 h680YHOf022150 for ; Tue, 8 Jul 2003 10:34:18 +1000 Received: (from abate@localhost) by pulp.anu.edu.au (8.12.9/8.12.9/Debian-5) id h680YHWw022147 for caml-list@inria.fr; Tue, 8 Jul 2003 10:34:17 +1000 Date: Tue, 8 Jul 2003 10:34:17 +1000 From: Pietro Abate To: caml-list@inria.fr Subject: Re: [Caml-list] genlex ... Message-ID: <20030708003417.GA22123@anu.edu.au> Mail-Followup-To: Pietro Abate , caml-list@inria.fr References: <20030707101344.GA13301@anu.edu.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030707101344.GA13301@anu.edu.au> User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pietro:01 abate:01 caml-list:01 re-writing:01 generic:01 dynamically:01 conn:01 atom:01 'kwd:01 expr:01 nonassoc:01 'ident:01 rec:01 node:02 parser:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi all, I solved my problem... On Mon, Jul 07, 2003 at 08:13:44PM +1000, Pietro Abate wrote: > 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... that's a piece of code that gives me keyword flexibility as I wanted... (conn is an object that stores my keyword with their associativity). let flexer = make_lexer ( conn#keywords @ ["(" ; ")"; "atom" ] );; let find_keyword level = parser [< 'Kwd x >] -> let v = try conn#lookup x with Not_found -> raise Stream.Failure in if (conn#assoc v = level) then x else raise Stream.Failure ;; let rec parse_main = parser [< e1 = parse_aux; e = parse_expr e1 >] -> e and parse_expr e1 = parser [< n = find_keyword (Connective.Left); e2 = parse_main >] -> term_h#node n [e1;e2] | [< >] -> e1 and parse_aux = parser [< n = find_keyword (Connective.NonAssoc); e = parse_aux >] -> term_h#node n [e] | [< 'Ident s >] -> term_h#atom s | [< 'Kwd "("; e = parse_main; 'Kwd ")" >] -> e I haven't test it yet, but it seems to make sense and compile correctly. 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