November 9th, 2007, 08:42 PM
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)
November 11th, 2007, 01:51 PM
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.
Oh, and it's got built in AST support[/edit]
Last edited by gothic_type; November 11th, 2007 at 01:54 PM.
By Tiger Shark in forum The Security Tutorials Forum
Last Post: January 19th, 2011, 12:40 AM
By SDK in forum Miscellaneous Security Discussions
Last Post: January 28th, 2005, 05:54 PM
By foxdie in forum AntiVirus Discussions
Last Post: April 4th, 2004, 03:52 AM
By progme in forum Other Tutorials Forum
Last Post: November 2nd, 2003, 04:43 PM
By tampabay420 in forum Programming Security
Last Post: February 14th, 2003, 02:36 PM