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 WAA08008; Fri, 5 Sep 2003 22:57:24 +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 WAA17894 for ; Fri, 5 Sep 2003 22:57:23 +0200 (MET DST) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h85KvMT25361 for ; Fri, 5 Sep 2003 22:57:22 +0200 (MET DST) Received: (qmail 2491 invoked by uid 566); 5 Sep 2003 20:57:14 -0000 Date: Fri, 5 Sep 2003 22:56:34 +0200 From: Michal Moskal To: "Rafael 'Dido' Sevilla" Cc: caml-list@inria.fr Subject: Re: [Caml-list] parsing forward references in ocamlyacc and other ocamlyacc questions Message-ID: <20030905205634.GA16638@roke.freak> Mail-Followup-To: Rafael 'Dido' Sevilla , caml-list@inria.fr References: <20030903053114.GA2490@imperium.ph> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030903053114.GA2490@imperium.ph> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 rafael:01 'dido':01 hash:01 bison:01 hashtbl:01 symtable:01 hashtbl:01 symtable:01 michal:01 moskal:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, Sep 03, 2003 at 01:31:14PM +0800, Rafael 'Dido' Sevilla wrote: > I'm just wondering how you can guarantee that certain imperative effects > occur, like adding a name into a symbol table hash. I'm writing a > compiler whose semantics allow some limited forward references, e.g.: > > adt_declaration: IDENTIFIER COLON ADT OBRACE adt_member_list CBRACE SEMI > > where the rules under the adt_member_list nonterminal have access to the > identifier name given in the ADT declaration. For the original Yacc or > Bison, it can be done with an intermediate semantic action like: > > adt_declaration: IDENTIFIER COLON ADT { Hashtbl.add symtable $1 ... } OBRACE ... > > Something like (which is how you would do it without the use of > intermediate actions): > > adt_name: IDENTIFIER COLON ADT { Hashtbl.add symtable $1 adt_skel; $1 } > ; > > adt_declaration: adt_name OBRACE adt_member_list CBRACE SEMI { ... } > ; > > doesn't seem to work. The symbol table addition still doesn't occur > until after the entire adt_declaration has been parsed. The > documentation for ocamlyacc has very little to say about it (unless > there's more documentation in other places besides the ocaml manual). Are you *sure*? From what I know about yacc parser, this action *had* to be taken before adt_member_list was parsed. -- : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h ------------------- 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