C language module for Harmonia
The C language module provides support for C89 and C99 with GNU extensions (as defined by GCC 3.3). This includes both syntax analysis and semantics.
Semantic analysis of files that have not been preprocessed, however, is difficult. A small change in a preprocessor directive (such as a #define) can have non-local effects, which impacts on the incrementality of not only the semantics, but the syntax and even lexical (sometimes) analysis of the file. In lieu of full support of analysis for un-preprocessed C files, we add an explicit mechanism to Harmonia-C mode to preprocess your files using a user-defined C compiler (default is gcc). Once the file has been successfully preprocessed, the contents of each #include are inserted invisibly into the Harmonia-C buffer, and semantic analysis is enabled. If the user modifies any preprocessor directive in the file (including a #include), semantic analysis is turned off, and the user is told to rerun the preprocessor to update the buffer.
Note: Preprocessor inclusion causes a lot of extra code to be put into the Harmonia-C buffer. Given that Harmonia-mode does not yet scale to analyze and present really large files, you will notice a slowdown in performance, especially during the initial analysis after the preprocessor is run.
View the source code
The source code for the C language module is presented here as appendices for the technical report below.
- c.lex (Flex source)
- c.ldl (Ladle grammar description)
- c-resolve.def (Name resolution and disambiguation semantic analysis)
- c-typecheck.def (Typechecking semantic analysis)
Read the technical report
Stephen McCamant. Handling the Complexities of a Real-World Language: A Harmonia Language Module for C. Technical Report CSD-02-1192, University of California, Berkeley, August 2002. (Gzipped PostScript, 25 pages, 240K) (PDF, 288K)