is a C compiler frontend that is designed for the implementation of static analysis tools. It provides a clean separation between syntax and semantics (with algorithmic- and heuristic-based syntax disambiguation), tolerance against failures—which is supported by the type inference of , , , and —, and API inspired by that of the . Psyche-C #include struct union enum typedef Roslyn .NET compiler The driver cnippet Psyche-C’s main use is through a C++ library. Specifically, by any tool that wishes to implement static analysis on C programs. But Psyche-C may as well be used as an ordinary C parser via the driver. In this little article, I will provide you with a glimpse of the AST ( ) that Psyche-C produces as the result of parsing a C program. But first, a quick illustration on how to invoke with the command. cnippet Abstract Syntax Tree cnippet cnip void f() { int a } The AST of a C program As the result of parsing a C program, Psyche-C produces an AST. This AST resembles that of the . Yet, a node in Psyche-C's AST does not always have a correspondent in Clang's AST. For instance, consider the program below and its Psyche-C produced AST. Clang (LLVM) frontend int v, f(int d); int f(int p) { if (p == v) return(p - 1); return 0; } Now, consider the Clang produced AST for that same C program. What's the difference between the two? For instance, you can't see s in Clang's AST, as they are absorbed by their containing s. Psyche-C's AST is a bit closer to the grammar of C. declarator declaration To better understand the statement above, consider the following declaration. int v, f(int d); In Clang's AST, is represented by a and by a ; both these nodes inherit from (i.e., a with a ). However, in pedantic terms, that representation isn't quite correct, given that only a single — starting at and ending at — exists in that snippet. v VarDecl f FunctionDecl DeclaratorDecl declaration declarator declaration int ; In Psyche-C’s AST, a single is created (like in Clang, this node inherits from ) with two child nodes: an , designating object of type , and a , designating function whose return type is . This is a finer-grained representation of the program syntax and one that enables an accurate rewrite of an AST—a characteristic of prime importance for static analysis tools that perform source code refactoring. VariableAndOrFunctionDeclaration DeclaratorDeclaration IdentifierDeclarator v int FunctionDeclarator f int Abstraction and concreteness Toward statically analyzing a program, the AST produced by a parser should abstract the program syntax at the “right” level. On one side, an AST should express, as much as possible, the meaning of a syntax and ignore grammar technicalities; on another side, an AST should expose any grammar technicality that affects, as least as possible, the meaning of a syntax. Producing an AST at a sweet spot between abstraction and concreteness, with precise conformance to the , is a primary goal of Psyche-C’s parser. C Standard … I'd love to hear your feedback. Thanks! Give Psyche-C a try