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 MAA21909; Wed, 3 Sep 2003 12:28:18 +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 MAA25360 for ; Wed, 3 Sep 2003 12:28:17 +0200 (MET DST) Received: from tcs.inf.tu-dresden.de (tcs.inf.tu-dresden.de [141.76.75.101]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h83ASHf11735 for ; Wed, 3 Sep 2003 12:28:17 +0200 (MET DST) Received: from ithif51 (ithif51 [141.76.75.51]) by tcs.inf.tu-dresden.de (8.12.9/8.12.9) with ESMTP id h83ASBiX012817 for ; Wed, 3 Sep 2003 12:28:11 +0200 (MET DST) Received: from tews by ithif51 with local (Exim 3.36 #1 (Debian)) id 19uUrz-0002y9-00 for ; Wed, 03 Sep 2003 12:28:11 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16213.49722.962405.471006@ithif51.inf.tu-dresden.de> Date: Wed, 3 Sep 2003 12:28:10 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Calling ocamlyacc from ocamlyacc In-Reply-To: <20030902152340.GA32745@henchmonkey.org> References: <20030901172828.GA24208@henchmonkey.org> <20030902151922.GB4055@roke.freak> <20030902152340.GA32745@henchmonkey.org> X-Mailer: VM 7.16 under Emacs 21.2.1 From: Hendrik Tews X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) at tcs.inf.tu-dresden.de X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 hendrik:01 tews:01 tews:01 fetches:01 hendrik:01 tu-dresden:01 approaches:01 token:01 token:01 writes:01 match:02 match:02 lexbuf:03 lexbuf:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk katre writes: Right, but is there a way, in a ocamlyacc action, to switch which lexer rule you're using? That seems to be the main part I am missing. Or if I could access the lexbuf directly, I could also use that. In the lexer you can do rule lexer = parse | "" { match !global_var with | Xlex -> xlex lexbuf | Ylex -> ylex lexbuf } and xlex = parse .... and ylex = parse .... You can set the global_var from the actions in the grammar. However, there is probably a better solution: First note that ocamlyacc generated functions expect a (Lexing.lexbuf -> token) function. So you can write your own master lexer: let lexer lexbuf = match !global_var with | Xlex -> Lexer.xlex lexbuf | Ylex -> .... with a bit of hacking you can also combine ocamllex lexers with other lexers. In both approaches the problem is the lookahead token: In some cases yacc fetches the next token and decides on that token whether to shift or reduce. If the action taken on reduce changes the lexer then have used the wrong lexer for the next token. You can examine the grammar.output file and the OCAMLRUNPARAM=p trace to find out if ocamlyacc needs the lookahead token for a given rule. (I can give examples on that if you are interested.) Bye, Hendrik ------------------- 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