Results 1 to 2 of 2

Thread: Need Help Writing a C compiler...

  1. #1
    Senior Member
    Join Date
    Oct 2005
    Posts
    106

    Need Help Writing a C compiler...

    Alright, I'm writing a C compiler "for the hell of it", and I'm using Flex/Bison as my lexer/parser combo. It works pretty well so far, but I'm rather lost when it comes to the abstract syntax tree implementation.

    All I really want to do is have a simple translator from C to MMIX assembly language that has absolutely no optimization. My motivation is because I'd like to: 1) have a C-to-MMIXAL "compiler", 2) have it demonstrate the efficiency of algorithms and code.

    That's why I don't want to use the GCC, because even if you write crappy code it will be optimized so you wouldn't notice unless you wrote really crappy code.

    Perhaps using Yacc/Bison is too heavy duty for this job, perhaps a simple perl/python/<insert your favorite scripting language> script would do? (It could even use the system's preprocessor that way...) I heard through the grapevine that it would be a "solid day of Perl hacking" to write something like this, so perhaps this would be the way to go?

    Thoughts and feedback would be greatly appreciated
    "The Texan turned out to be good-natured, generous and likeable. In three days no one could stand him." Catch 22 by Joseph Heller.

    Buddies? I have no buddies...


    Give the BSD daemon some love (proud FreeBSD user)

  2. #2
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    I would recommend Antlr and StringTemplate. Antlr has the advantages over flex/bison that it combines the lexer and parser, and you also write your grammar rules in EBNF rather than BNF (which is horrendous when you try to do repetitions and the like).

    Another advantage of using Antlr is that it is perfectly suited for creating an input for StringTemplate (and in fact I believe that the Antlr and StringTemplate java code is translated into the other supported languages using StringTemplate).

    The only downside is that the documentation is pretty crap...but at the same time it's relatively straight forward to get up and running with Antlr. I use StringTemplate all the time for code gen at my work (mainly generating a load of T-SQL) and would recommend it to anyone.

    Hope that's helpful.

    ac

    [edit]Oh, and it's got built in AST support[/edit]
    Last edited by gothic_type; November 11th, 2007 at 01:54 PM.

Similar Threads

  1. Tutorial: What to avoid while writing a tutorial
    By Tiger Shark in forum The Security Tutorials Forum
    Replies: 24
    Last Post: January 19th, 2011, 12:40 AM
  2. Criminal IT: Should you trust the Internet?
    By SDK in forum Miscellaneous Security Discussions
    Replies: 4
    Last Post: January 28th, 2005, 05:54 PM
  3. The Bulgarian and Soviet Virus Factories
    By foxdie in forum AntiVirus Discussions
    Replies: 11
    Last Post: April 4th, 2004, 02:52 AM
  4. Advanced C++, generic programming & STL
    By progme in forum Other Tutorials Forum
    Replies: 11
    Last Post: November 2nd, 2003, 04:43 PM
  5. C++ portability guide
    By tampabay420 in forum Programming Security
    Replies: 2
    Last Post: February 14th, 2003, 02:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •