Implementation of Dynamic Scoping for C Programs
In this work I modified the LLVM C compiler (Clang) source code to produce a C compiler that supports dynamic scoping. In other words, the new C Compiler takes C programs that follow dynamic scoping rules as input. This can be done in two ways. In both approaches are required to add passes to Clang to traverse the Abstract Syntax Tree(AST) produced by Clang and so that a modified AST is generated. The new AST must include all the modifications and extra nodes to handle dynamic scoping. In the first approach, the new AST can be handed over to the internal compilation pipeline for further processing. The second approach is to produce new C source code from the AST with support for dynamic scoping that can be compiled with any C compiler. Input programs will be required to support only int, float and structure type variables.
For solving the above eluded problem we use the second method of parsing the AST and generating new source code. The libtooling tool chain of clang is used to instantiate the compiler instance and parse the AST.
This project has concluded.
The detailed report is available below (Download here ). The code is available for inspection on my github repo https://github.com/adarshpatil/dynamicScopingForC
- Compiler Design
- Clang Compiler
- Dynamic Scoping
- Course Project