[plt-scheme] parsing/prettyprinting C

From: Dave Herman (dherman at ccs.neu.edu)
Date: Thu Mar 5 11:02:42 EST 2009

>> I see it uses yacc.  The 2nd edition K&R has a grammar acceptable by
>> yacc in appendix A, section A13.  Are there any difficulties to
>> making this a complete parser other than "just typing it in" ?

P.S. To answer your question more directly: *yes*. Parsing C is 
extremely tricky, especially using a parser generator. Long story short: 
the parser has to maintain an environment and feed the information to 
the lexer, and the lexer has to make sure it doesn't look ahead to far 
before the environment has been appropriately updated. It's one of 
history's glorious botches (a remarkable proportion of which seems to 
belong to C). Of course, C++ would be orders of magnitude harder...

Dave


Posted on the users mailing list.