From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24836 invoked by alias); 31 Dec 2002 16:15:43 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 24812 invoked from network); 31 Dec 2002 16:15:41 -0000 Received: from unknown (HELO smtp03.iprimus.com.au) (210.50.30.52) by 209.249.29.67 with SMTP; 31 Dec 2002 16:15:41 -0000 Received: from smtp01.iprimus.net.au (210.50.30.70) by smtp03.iprimus.com.au (6.7.010) id 3E0FA3A20001D2B4 for gcc@gcc.gnu.org; Wed, 1 Jan 2003 03:15:29 +1100 Received: from localhost.iprimus.com.au ([203.134.93.129]) by smtp01.iprimus.net.au with Microsoft SMTPSVC(5.0.2195.5600); Wed, 1 Jan 2003 03:15:28 +1100 Message-Id: <5.1.0.14.0.20030101031203.009f2a00@pop.iprimus.com.au> X-Sender: jamesbuch@pop.iprimus.com.au (Unverified) Date: Tue, 31 Dec 2002 09:53:00 -0000 To: gcc@gcc.gnu.org From: James Buchanan Subject: New front end, help needed Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-OriginalArrivalTime: 31 Dec 2002 16:15:28.0903 (UTC) FILETIME=[D5B35970:01C2B0E7] X-SW-Source: 2002-12/txt/msg01643.txt.bz2 Hi everyone, I suppose the thing that stumps me is the trees. I have looked in tree.def, tree.h, coretypes.h and many other places without much success. Sometimes it appears to be a union (coretypes.h - but just a nothing typedef saying tree is a pointer to union treenode) but sometimes it appears to be a struct. I can't see what it is supposed to be. If I could make these trees for arithmetic expressions, assignment statements, functions, and so on, then I could compile a new language by writing a front end. But I don't even know where to start. By the way, my new language is a dialect and subset of BASIC. Hopefully not so useless that it's useless, but useful enough to learn a lot about writing a front end, so I can implement something more ambitious. :-) Do you have any tips for me? I see that everything gets a tree, even single numbers that appear as constants in an expression. So to compile up the following BASIC: DECLARE name$, amount%, tax% INPUT "Enter your name: ", name$ PRINT "Hello ", name$ INPUT "Enter an amount: ", amount% tax% = amount% - (amount% * 0.05) IF tax% < 100.0 THEN PRINT "You didn't pay much tax!" ELSE PRINT "I feel sorry for you." END IF PRINT "You paid $", tax%, " in taxes." .... I would need to write the parser which calls on the tree functions and macros to build things up. Now, for something like: DECLARE name$, amount%, tax% ... where $ and % mean "string type" and "real type" respectively, I could go: tree str_decl = build_decl(STRING_DECL, get_identifier(name), type); ... where I have defined STRING_DECL, or I use a POINTER_DECL or something else as in tree.def. Now, after this, what next? I suppose it is all taken care of by GCC... and assembler comes out and gets processed and linked. Suppose I need a string, use an ARRAY_DECL (as in an array of chars or unicode wchar's) or a POINTER_DECL? I suppose I don't use POINTER_DECL, since there is no actual object, only a placeholder address for something else, so I use an ARRAY_DECL or something to internally represent var$ as a C string. Where to from here? I need to grow strings automagically within the compiler, and handle IF var$ = foo$ THEN... by calling strcmp() or something like that, within the runtime library. How do I implement these operators? How do I get the assembler that is generated to hook into the runtime code needed? Sorry for all this, but I am not sure who to ask or where to look or anything like that. Kind regards, James