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 JAA02729; Mon, 15 Sep 2003 09:51:25 +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 JAA25735 for ; Mon, 15 Sep 2003 09:51:24 +0200 (MET DST) Received: from intmail.imperium.ph ([202.175.240.154]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8F7pLT18149 for ; Mon, 15 Sep 2003 09:51:22 +0200 (MET DST) Received: from morgoth.imperium.ph (unknown [192.168.1.35]) by intmail.imperium.ph (Postfix) with SMTP id BD57B46AC0 for ; Mon, 15 Sep 2003 15:51:19 +0800 (PHT) Received: by morgoth.imperium.ph (sSMTP sendmail emulation); Mon, 15 Sep 2003 15:53:39 +0800 Date: Mon, 15 Sep 2003 15:53:39 +0800 From: "Rafael 'Dido' Sevilla" To: caml-list@inria.fr Subject: [Caml-list] line number information in abstract syntax trees Message-ID: <20030915075339.GA20719@imperium.ph> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: Linux morgoth 2.4.20-gentoo-r5 User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; rafael:01 'dido':01 dido:01 decl:01 decl:01 datatype:01 datatype:01 int':01 compiler:01 func:01 byte:01 int:01 int:01 syntax:02 syntax:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk As some of you have suggested earlier, I have foregone doing some preliminary semantic analysis for my compiler in my ocamlyacc grammar, and instead am using the grammar solely to do syntactic analysis. Which then brings me to another problem. I've created an abstract syntax tree data type, but now I need to somehow embed line number information obtained from the syntactic analysis phase so that I can later do error reporting. I can't think of a clean way to do this. So far, I have a syntax tree data type that kind of looks like: type program = { impmodule: string ; tdecls: topdecl list; plineno:int} and topdecl = Declaration of decl * int and decl = { idents: string list ; dtype: xtype ; dlineno:int} and xtype = Data of datatype * int | Func of fntype * int | Alias of xtype * int and datatype = Byte of int | Int of int | Big of int | Real of int | String of int | Tuple of (datatype list * int) | Array of (datatype * int) | List of (datatype * int) | Chan of (datatype * int) Note that all the record types have additional fields that look like 'plineno:int' and every variant type has an int tacked on somewhere. That int is supposed to contain the line number. This works just fine, but it just seems to me like such a grossly ugly hack into what is otherwise an elegant-looking data structure. Anyone have style guidelines ------------------- 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