Project Description

This is a framework for source code transformation. It is paradigm shift in Abstract Syntax Tree processing. Instead of implementing Visitor pattern to process nodes one can use full power of LINQ to select relevant nodes. Additionally it allows to perform 'Structural Comparison'


This project is in its initial stage. It was created as a prove of concept that one can use LINQ to query Abstract Syntax Tree.
When I was starting this project I named it Linq.SourceCode because I thought that AST concept is only know to people who finished courses in computer languages or compiles. Eventually, I decided that that I will stick to more accurate naming. I plan to change all namespaces in the next release but for now please excuse me for this naming inconsistency.


Here is just a small sample of what this framework can do. I know that it doesn't make much sense but still its cool.
// Find all calls to "foo" with parameter number equal to the current number of seconds mod 5
var query = from d in code.Descendants().OfType<FunctionCallExpression>()
            where d is IdentifierExpression
            let identifier = d.Function as IdentifierExpression
            where identifier.Value == "foo" &&
                  d.Parameters.Count == DateTime.Today.Second % 5
            select d;


  • Build in parser for Ansi C grammar
  • Full Object-Oriented representation of Abstract Syntax Tree
  • LINQ support
  • Structural comparison (available in LINQ)


  • No semantic analysis
  • No validations on values passed to nodes representing identifiers and constants (one may corrupt the tree)


When I first showed this project to my collages they found it very complex. I think it is mainly because they didn't know Ansi C grammar. That's why my first objective is to prepare some kind of tutorial to make it easy to start.

Moreover I would like to:
  • Add support for C#
  • Add validation to preserve tree in syntactically correct state

Last edited Nov 12, 2010 at 10:20 AM by proxon, version 5