I am taking a data structures class which is taught 73% in Java and 27% in C. Right now, we are now doing C and the examples of C code on the lecture slides are is what I consider to be Java-style C code in that it is very verbose. C is a programming language in which I am very comfortable in programming, but C is also my favorite programming language and each time I see Java-style C code, it feels like a piece of me dies inside, so to resolve this, I would like to write a program that will do the following things in the following order:
- Read a C source file from the file system
- Verify it has no syntax errors (if it does, it will stop here)
- Generate a parse tree containing a description of the program
- Do manipulation to the parse tree to apply optimizations to the code
- Output a neatly formatted C source file to the file system
After I have written this program, I will give it to my professor in the hope that he uses it to fix his lecture slides. I know all of the optimizations that I want the program to do and I could list them, but I have a more fundamental problem.
I have a copy of the dragon book and I have read its first few chapters, but it but it is very abstract in its descriptions. Consequently, its examples only show how portions of things are done, such as mathematical expressions. It would take several months for me to derive how all of this would be applied to something as complicated as the C language and to write a working program that does what I want, so I am wondering, is there any sort of shortcut I can take?
More specifically, is there any sort of idiot's guide for specialized tools compiler writers use like LEX and YACC that would enable me to quickly get code that will produce a parse tree so I can do the manipulations I want and then output the tree's information to a text file without having to concern myself with the algorithms behind how the parse tree was generated in the first place?