Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Please help a n00b write a compiler :-)

Reply
Thread Tools

Please help a n00b write a compiler :-)

 
 
Anton Gavrilov
Guest
Posts: n/a
 
      12-18-2003
Hi all,

I seek your advice on where to start if I want to write a compiler for a
toy C-like language I invented (or, rather, am in the process of
inventing). Yes, yes, I know I'm crazy and the very idea is
brain-damaged and all that. Chances are I will lose interest long before
I reach break-even, but it doesn't hurt trying, does it?

I'm a C addict reluctant to switch to C++, partly because I can't fully
grok (and accept) the OOP paradigm. Nevertheless I like C++'s arguable
improvements such as overloading of functions and operators, references,
const types etc. I also miss Pascal's way-less-cryptic typedefs and
consistent array types.

I suppose that rather than writing my experimental compiler from scratch
it might be a better idea to take an existing one and hack it towards my
notion of 'the ideal multi-purpose language'. I had some experience
with QuakeC (a byte-code compiler for the game Quake) so I know what a
very simple compiler looks like, but things like parsing and handling of
composite data types and generation of x86 machine code are still beyond
my understanding.

I have taken a look at GCC source once and was startled to death.
Obviously it's a highly advanced, extendible and portable compiler and
this implies quite a lot of unnecessary complexity.

Is there something like 'The Art of Writing Compilers for Dummies?'? Is
there a simple C compiler somewhere for which source is available under
a GPL-compatible license?

Any help is appreciated.

BR,
Anton 'Tonik' Gavrilov
 
Reply With Quote
 
 
 
 
Grumble
Guest
Posts: n/a
 
      12-18-2003
Anton Gavrilov wrote:
> Any help is appreciated.


http://google.com/groups?group=comp.compilers

 
Reply With Quote
 
 
 
 
Seth Morecraft
Guest
Posts: n/a
 
      12-18-2003
Try Flex (LEX) (http://www.gnu.org/software/flex/) and Bison (YACC)
(http://www.gnu.org/software/bison/bison.html).
good luck!

Seth

Anton Gavrilov wrote:
> Hi all,
>
> I seek your advice on where to start if I want to write a compiler for a
> toy C-like language I invented (or, rather, am in the process of
> inventing). Yes, yes, I know I'm crazy and the very idea is
> brain-damaged and all that. Chances are I will lose interest long before
> I reach break-even, but it doesn't hurt trying, does it?
>
> I'm a C addict reluctant to switch to C++, partly because I can't fully
> grok (and accept) the OOP paradigm. Nevertheless I like C++'s arguable
> improvements such as overloading of functions and operators, references,
> const types etc. I also miss Pascal's way-less-cryptic typedefs and
> consistent array types.
>
> I suppose that rather than writing my experimental compiler from scratch
> it might be a better idea to take an existing one and hack it towards my
> notion of 'the ideal multi-purpose language'. I had some experience
> with QuakeC (a byte-code compiler for the game Quake) so I know what a
> very simple compiler looks like, but things like parsing and handling of
> composite data types and generation of x86 machine code are still beyond
> my understanding.
>
> I have taken a look at GCC source once and was startled to death.
> Obviously it's a highly advanced, extendible and portable compiler and
> this implies quite a lot of unnecessary complexity.
>
> Is there something like 'The Art of Writing Compilers for Dummies?'? Is
> there a simple C compiler somewhere for which source is available under
> a GPL-compatible license?
>
> Any help is appreciated.
>
> BR,
> Anton 'Tonik' Gavrilov


~ Let us linux ~


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
 
Reply With Quote
 
Alan Balmer
Guest
Posts: n/a
 
      12-18-2003
On Thu, 18 Dec 2003 13:15:38 GMT, Anton Gavrilov <>
wrote:

>Hi all,
>
>I seek your advice on where to start if I want to write a compiler for a
>toy C-like language I invented (or, rather, am in the process of


Try this:
http://compilers.iecc.com/crenshaw/

--
Al Balmer
Balmer Consulting

 
Reply With Quote
 
John Bode
Guest
Posts: n/a
 
      12-18-2003
Anton Gavrilov <> wrote in message news:<_LhEb.5223$>...
> Hi all,
>
> I seek your advice on where to start if I want to write a compiler for a
> toy C-like language I invented (or, rather, am in the process of
> inventing). Yes, yes, I know I'm crazy and the very idea is
> brain-damaged and all that. Chances are I will lose interest long before
> I reach break-even, but it doesn't hurt trying, does it?
>
> I'm a C addict reluctant to switch to C++, partly because I can't fully
> grok (and accept) the OOP paradigm. Nevertheless I like C++'s arguable
> improvements such as overloading of functions and operators, references,
> const types etc. I also miss Pascal's way-less-cryptic typedefs and
> consistent array types.
>
> I suppose that rather than writing my experimental compiler from scratch
> it might be a better idea to take an existing one and hack it towards my
> notion of 'the ideal multi-purpose language'. I had some experience
> with QuakeC (a byte-code compiler for the game Quake) so I know what a
> very simple compiler looks like, but things like parsing and handling of
> composite data types and generation of x86 machine code are still beyond
> my understanding.
>
> I have taken a look at GCC source once and was startled to death.
> Obviously it's a highly advanced, extendible and portable compiler and
> this implies quite a lot of unnecessary complexity.
>
> Is there something like 'The Art of Writing Compilers for Dummies?'? Is
> there a simple C compiler somewhere for which source is available under
> a GPL-compatible license?
>
> Any help is appreciated.
>
> BR,
> Anton 'Tonik' Gavrilov



Niklaus Wirth has a small volume called "The Compiler Construction
Handbook". It's written for Oberon rather than C, but most of the
lessons should translate.

I admire you. I've started a half-dozen toy compiler projects and
always lost steam before getting too far.
 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      12-18-2003
Anton Gavrilov <> writes:

> I seek your advice on where to start if I want to write a compiler for
> a toy C-like language I invented (or, rather, am in the process of
> inventing). Yes, yes, I know I'm crazy and the very idea is
> brain-damaged and all that. Chances are I will lose interest long
> before I reach break-even, but it doesn't hurt trying, does it?


Your question is outside the domain of comp.lang.c, which discusses
only the standard C programming language, including the standard C
library. This is a remarkably narrow topic compared to what many
people expect.

For your convenience, the list below contains topics that are not
on-topic for comp.lang.c, and suggests newsgroups for you to
explore if you have questions about these topics. Please do
observe proper netiquette before posting to any of these
newsgroups. In particular, you should read the group's charter
and FAQ, if any. If those fail to answer your question then you
should browse through at least two weeks of recent articles to
make sure that your question has not already been answered.

* OS-specific questions, such as how to clear the screen,
access the network, list the files in a directory, or read
"piped" output from a subprocess. These questions should be
directed to OS-specific newsgroups, such as
comp.os.ms-windows.programmer.misc, comp.unix.programmer, or
comp.os.linux.development.apps.

* Compiler-specific questions. Ask about these in
compiler-specific newsgroups, such as gnu.gcc.help or
comp.os.ms-windows.programmer.misc. Questions about writing
compilers are appropriate in comp.compilers.

* Processor-specific questions, such as questions about
assembly and machine code. x86 questions are appropriate in
comp.lang.asm.x86, embedded system processor questions may
be appropriate in comp.arch.embedded.

* ABI-specific questions, such as how to interface assembly
code to C. These questions are both processor- and
OS-specific and should typically be asked in OS-specific
newsgroups.

* Algorithms, except questions about C implementations of
algorithms. "How do I implement algorithm X in C?" is not a
question about a C implementation of an algorithm, it is a
request for source code. Newsgroups comp.programming and
comp.theory may be appropriate.

* Making C interoperate with other languages. C has no
facilities for such interoperation. These questions should
be directed to system- or compiler-specific newsgroups. C++
has features for interoperating with C, so consider
comp.lang.c++ for such questions.

* The C standard, as opposed to standard C. Questions about
the C standard are best asked in comp.std.c.

* C++. Please do not post or cross-post questions about C++
to comp.lang.c. Ask C++ questions in C++ newsgroups, such
as comp.lang.c++ or comp.lang.c++.moderated.

news.groups.questions is a good place to ask about the appropriate
newsgroup for a given topic.


--
"I'm not here to convince idiots not to be stupid.
They won't listen anyway."
--Dann Corbit
 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      12-18-2003
Anton Gavrilov wrote:

> Hi all,
>
> I seek your advice on where to start if I want to write a compiler for a
> toy C-like language I invented (or, rather, am in the process of
> inventing). Yes, yes, I know I'm crazy and the very idea is
> brain-damaged and all that. Chances are I will lose interest long before
> I reach break-even, but it doesn't hurt trying, does it?

[snip]


>
> Any help is appreciated.
>
> BR,
> Anton 'Tonik' Gavrilov

In my Compiler Design class, we first tackled a simple expression
parser, then a language lexer. After the lexer worked, we moved
on to emitting executable code for the compiler. The language
was the instructor's "D-" which a very simple subset of the C
language.

The course was one year long and dreaded by all of the Computer
Science students. Kind of our Final Project.

I don't wish the task on any single person.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

 
Reply With Quote
 
E. Robert Tisdale
Guest
Posts: n/a
 
      12-18-2003
Anton Gavrilov wrote:

> I seek your advice on where to start
> if I want to write a compiler for a toy C-like language
> that I invented (or, rather, am in the process of inventing).
> I know I'm crazy and the very idea is brain-damaged and all that.


No it isn't brain damaged. It's a good idea.
Every computer scientist does this in the course of University classes.

Check out Yet Another Compiler Compiler (YACC).
Use Google to look for book for books by Brinch Hansen.
Subscribe to a compilers newsgroup and ask them.
The comp.lang.c newsgroup is a good place
to get *bad* advice about compiler design.

 
Reply With Quote
 
Malcolm
Guest
Posts: n/a
 
      12-18-2003

"Anton Gavrilov" <> wrote in message
>
> I seek your advice on where to start if I want to write a compiler for a
> toy C-like language I invented (or, rather, am in the process of
> inventing).
>

It's a lot harder to write a compiler than you might imagine. I recommend
starting with a BASIC interpreter. If you are serious, you could do worse
than purchase the dragon book (Aho, Sethi and Ullman, Compilers, principles
and tools).


 
Reply With Quote
 
Martin Dickopp
Guest
Posts: n/a
 
      12-19-2003
"E. Robert Tisdale" <> writes:

> The comp.lang.c newsgroup is a good place
> to get *bad* advice about compiler design.


Actually, I think bad advice about compiler design would be
as off-topic as good advice about compiler design here.

Martin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Couple of n00b questions - please help :) Hellraiser UK VOIP 17 03-20-2006 10:49 PM
n00b Help Setting up MSDE SQL Server newgenre ASP .Net 4 04-27-2004 04:13 PM
n00b Help with Beginning SQL for ASP.NET App newgenre ASP .Net 1 04-14-2004 06:03 PM
N00b 413Rt - need help Joseph Good Cisco 2 04-04-2004 05:11 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments