public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: James Buchanan <jamesbuch@iprimus.com.au>
To: gcc@gcc.gnu.org
Subject: New front end, help needed
Date: Tue, 31 Dec 2002 09:53:00 -0000	[thread overview]
Message-ID: <5.1.0.14.0.20030101031203.009f2a00@pop.iprimus.com.au> (raw)

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

             reply	other threads:[~2002-12-31 16:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-31  9:53 James Buchanan [this message]
2002-12-31 10:15 ` Daniel Jacobowitz
2002-12-31 10:32   ` James Buchanan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5.1.0.14.0.20030101031203.009f2a00@pop.iprimus.com.au \
    --to=jamesbuch@iprimus.com.au \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).