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 XAA04572; Fri, 17 Oct 2003 23:46:35 +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 XAA02278 for ; Fri, 17 Oct 2003 23:46:34 +0200 (MET DST) Received: from ohsmtp02.ogw.rr.com (ohsmtp02.ogw.rr.com [65.24.7.37]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9HLkX106362 for ; Fri, 17 Oct 2003 23:46:33 +0200 (MET DST) Received: from vilya (cpe-024-033-201-104.columbus.rr.com [24.33.201.104]) by ohsmtp02.ogw.rr.com (8.12.10/8.12.2) with ESMTP id h9HLkVI5001604 for ; Fri, 17 Oct 2003 17:46:31 -0400 (EDT) Received: from peuter ([192.168.2.2] ident=mail) by vilya with esmtp (Exim 3.36 #1 (Debian)) id 1AAcQZ-0002br-00 for ; Fri, 17 Oct 2003 17:46:31 -0400 Received: from andrewl by peuter with local (Exim 3.36 #1 (Debian)) id 1AAcQZ-0001iP-00 for ; Fri, 17 Oct 2003 17:46:31 -0400 Date: Fri, 17 Oct 2003 17:46:31 -0400 From: Andrew Lenharth To: caml-list@inria.fr Subject: [Caml-list] a patch to support + and * in ocamlyacc Message-ID: <20031017214631.GA6576@peuter> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; foo:01 foo:01 buffer:01 buffer:01 writting:01 int:01 int:01 token:01 token:01 patch:02 patch:02 eof:02 eof:02 rewritten:02 parsers:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I find myself having to often implement rules such as: foo_plus: foo {[$1]} | foo foo_plus {$1::$2} ; foo_star: foo_plus {$1} | {[]} ; in my parsers. To get rid of this annoyance, here is a patch that add support for * and + to ocamlyacc. http://vilya.homelinux.net/~andrewl/ocamlyacc_p1.diff it is a bit hackish, but even limited support for * and + makes writting grammers less painful. I modify get_name to check for + and *, and rewrite the name it finds if those exist. It also adds appropriate rules to a buffer to implement the rewritten name. I change the read character rutine such that at EOF I switch to the buffer holding the generated rules. This has been tested not to break the bootstrapping system. An example: %token INT_LITERAL %token EOF %start main /* entry point */ %type main %% main: INT_LITERAL+ EOF {$1} ; Andrew Lenharth ------------------- 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