* New front end, help needed
@ 2002-12-31 9:53 James Buchanan
2002-12-31 10:15 ` Daniel Jacobowitz
0 siblings, 1 reply; 3+ messages in thread
From: James Buchanan @ 2002-12-31 9:53 UTC (permalink / raw)
To: gcc
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: New front end, help needed
2002-12-31 9:53 New front end, help needed James Buchanan
@ 2002-12-31 10:15 ` Daniel Jacobowitz
2002-12-31 10:32 ` James Buchanan
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2002-12-31 10:15 UTC (permalink / raw)
To: James Buchanan; +Cc: gcc
On Wed, Jan 01, 2003 at 03:14:47AM +1100, James Buchanan wrote:
> 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.
> 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.
You should take a good look at "treelang", which is the sample
frontend, and also a good look at the GCC Internals manual (gccint.info
in gcc/doc/ in a built tree).
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: New front end, help needed
2002-12-31 10:15 ` Daniel Jacobowitz
@ 2002-12-31 10:32 ` James Buchanan
0 siblings, 0 replies; 3+ messages in thread
From: James Buchanan @ 2002-12-31 10:32 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gcc
At 11:22 AM 12/31/2002 -0500, Daniel Jacobowitz wrote:
>You should take a good look at "treelang", which is the sample
>frontend, and also a good look at the GCC Internals manual (gccint.info
>in gcc/doc/ in a built tree).
Thanks for this. I can get the gccint manual on the website,
I just went and had a look.
I've already seen treelang, but it wasn't very helpful for me. I was
looking for more of something that starts from the very beginning.
It already requires a good knowledge of GCC internals because
I can't fully understand it. I suppose I need to fill in the gaps myself
and keep going back for another look until it falls into place. :-)
Cheers
James
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-12-31 16:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-31 9:53 New front end, help needed James Buchanan
2002-12-31 10:15 ` Daniel Jacobowitz
2002-12-31 10:32 ` James Buchanan
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).