InnovationQ will be updated on Sunday, Oct. 22, from 10am ET - noon. You may experience brief service interruptions during that time.
Browse Prior Art Database

An extensible method for incremental compilation and translation of code snippets in non-lexical context using an existing compiler for a compatible language

IP.com Disclosure Number: IPCOM000205848D
Publication Date: 2011-Apr-06
Document File: 6 page(s) / 165K

Publishing Venue

The IP.com Prior Art Database


A method and system to perform semantic analysis of a code snippet in a non-lexical context using an existing compiler for a similiar language by incrementally creating needed context and resolving bindings of identifiers in code snippet to elements in the non-lexical context

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 28% of the total text.

Page 01 of 6

An extensible method for incremental compilation and translation of code snippets in non-lexical context using an existing compiler for a compatible language

The problem

A compiler for a programming language analyzes given source code for adherence to the rules of the programming language, and translates it to another formal, assembly or machine language. A compiler is tightly coupled with a programming language, and typically consists of cohesive components that do lexical analysis, syntax analysis (


                                    arsing), semantic analysis, code generation and optimizations. In current practice, a new compiler needs to be created from scratch and a compiler for a language with different semantic rules can not be reused. However, correctness of a compiler is critical because its users assume that the compiler is translating their source correctly to a target programming, assembly or machine language. Therefore a compiler needs to be tested rigorously for correctness; any reuse of an existing compiler will reduce the required effort.

Modeling tools (for example, Rational Software Architect for UML modeling) are widely used to design and define structure of a software system. In such environments, behavior of the system can be described adding code snippets in various model elements. These code snippets are at the level of statements, instead of a specific compilation unit definition that is common in traditional programming language. So the compilation context is hybrid: some of the compilation context information is in the code snippet (e.g. local variable definitions) but most of the compilation context in the structure defined in the model. The code snippet needs to be compiled and translated in this hybrid context, which adds to the complexity of the name binding resolution: any identified used in the code snippet must be resolved in the naming environment defined by the model as well as the code (unlike in traditional compiler where the naming environment is lexical in nature). Every programming language defines a runtime (e.g. libc and other system libraries in C; and java.lang and other packages in a Java JRE). In a hybrid environment as describes above, the runtime might include runtime model libraries (instead of binary or lexical libraries). An obvious solution is to construct and test a compiler from scratch for such a complex and hybrid environment, which requires considerable effort.

This disclosure describes a novel method to construct a compiler for compiling and translating code snippets in non-lexical and hybrid context by using a well established and tested compiler for a compatible traditional programming language. The method has following characteristics:

• Compiles and translates code snippet units at a level (e.g. statements, expressions) that is lower than traditional compilation units.

• Incrementally creates minimal context required to compile a code snippet.

• Semantic analysis consists of type checking and na...