Have you ever written a compiler?

This is a discussion on Have you ever written a compiler? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I'm finishing up my final project for the course Compiler Design, and I thought it would be nice to know ...

  1. #1
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953

    Have you ever written a compiler?

    I'm finishing up my final project for the course Compiler Design, and I thought it would be nice to know how many of you tried writting compilers, and what did you use to write it.

    What I did in the project is that I wrote a compiler for a "toy" language called C- (C minus), which is simmilar to C but simpler.

    I wrote the scanner myself, I used YACC to make the parser (LR(1)) and wrote the semantics and code generation myself.

    If you have ever done a similar thing I would like to know how did you do it. If you didn't I really encourage you to read about compiler construction, it's a very interesting topic.

    [edit]
    BTW: The text book that we have is Compiler Construction Principles and Practice by Kenneth C. Louden
    none...

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I tried writing an assembler once. It was written in C (CGI program) and did little more than read in an instruction, and replace it with the correct binary sequence (lots of switch/case action going on...) . I never managed to work out the binary sequences for operators and that was what brought the project to a halt. I might try again one day.

  3. #3
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    I write one every other week, just to make sure I don't get rusty.

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Quote Originally Posted by -KEN-
    I write one every other week, just to make sure I don't get rusty.
    Can you explain what kind of compilers you write, and what methods you use to do so.
    I'm interested in knowing about other techniques in compiler construction.

    Thanks.
    none...

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I think -KEN- was being a tad sarcastic, though I wouldn't be surprized if has written ONE. In addition to picking the brains of board members, you might want to check out directory.google.com. I find the directory format better than the search format for finding tutorials on subjects like this. It was very useful when I was learning about OS theory.

  6. #6
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Quote Originally Posted by sean_mackrory
    I think -KEN- was being a tad sarcastic, though I wouldn't be surprized if has written ONE. In addition to picking the brains of board members, you might want to check out directory.google.com. I find the directory format better than the search format for finding tutorials on subjects like this. It was very useful when I was learning about OS theory.
    I know he was being sarcastic (who would write a compiler each week), I was just hoping that if has written one he would tell me more about it!
    none...

  7. #7
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    I wrote a small BASIC compiler. It does not have offer much in terms of a language, but it was fun to write. It generates assembly code for NASM. If anyone cares you can download it at http://blackfrog.pagemac.com

    I found a lot of information from comp.compilers and from looking at the source for the free C Compiler, lcc.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  8. #8
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    I've been working on a server for some time and no idea what to do when I first started. I've learned a lot more by reading the source code of the most simple of servers than I have from studying the complex ones for hours. The same may apply to compilers, so keep it in mind. Once you've got the essntials, the rest is just good design and use of C/C++.

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I was just hoping that if has written one he would tell me more about it!
    A compiler is one of the more complicated programs that one can write. So, for the most part, you can expect anyone who actually has written one to remain silent about it so as to avoid answering a flood of questions.

    You would be better off asking more specific questions. "Tell me everything about <topic>" questions don't go over very well.
    My best code is written with the delete key.

  10. #10
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    For example, "tell me everything about women".

    edit: Sorry Prelude. But it's true. We have no idea what's going on.

  11. #11
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    >For example, "tell me everything about women".

    edit: Sorry Prelude. But it's true. We have no idea what's going on.

    An iPod and a diamond makes Prelude a happy geek girl.

    What else is there?

  12. #12
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Quote Originally Posted by Prelude
    >I was just hoping that if has written one he would tell me more about it!
    A compiler is one of the more complicated programs that one can write. So, for the most part, you can expect anyone who actually has written one to remain silent about it so as to avoid answering a flood of questions.

    You would be better off asking more specific questions. "Tell me everything about <topic>" questions don't go over very well.
    What I was looking for is some little and general information, like saying: I used YACC for the parser, LR(1), or LALR(1), or I used reqursive decent parsing, I used lex for the scanner or I wrote the scanner myself, what kind of target code and or intermediate code did you generate etc...

    I'm not looking for details because I already had a whole course called Compiler Design (CS474) that covered most of these topics, and also included a project that I talked about in my first post( which I finished already) , I only wanted to know what you ( people on this board ) did, maybe there are some methods that I don't know about, and I was looking forward to knowing it.

    [edit]
    I will not ask too many questions, I promise .
    Last edited by ammar; 12-26-2004 at 03:34 AM.
    none...

  13. #13
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I haven't written a compiler to machine code, but I've created a scripting language called Omicron.
    The parser finds the operator with the highest predecence and converts it to RPN. When the whole program is converted to RPN the program is exxcuted.
    http://www.strandmark.com/omicron.shtml
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  14. #14
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Sorry to disappoint. I've tried tackling an OS a looong time ago (which may sound odd from somebody who can't legally buy alcohol yet), but quickly got bored and left it after learning how to make it display pretty colors . Never tried a compiler.

  15. #15
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Alternate Ending:

    ... but quickly got bored and left it to go buy some alocohol.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 12:07 PM
  2. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  3. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  4. Help With finding a compiler
    By macman in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-15-2005, 09:15 AM
  5. C Compiler
    By SAMSEIED in forum C Programming
    Replies: 5
    Last Post: 06-06-2002, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21