This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
New front end, help needed
- From: James Buchanan <jamesbuch at iprimus dot com dot au>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 01 Jan 2003 03:14:47 +1100
- Subject: New front end, help needed
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