27.10.2014 Views

Implementing an OCL 2.0 Compiler for ... - ResearchGate

Implementing an OCL 2.0 Compiler for ... - ResearchGate

Implementing an OCL 2.0 Compiler for ... - ResearchGate

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>an</strong>d (ii) the generation (synthesis) of the target l<strong>an</strong>guage output based on the<br />

retrieved sem<strong>an</strong>tic in<strong>for</strong>mation. Accordingly, the <strong>OCL</strong> <strong>Compiler</strong> realized in<br />

VMTS consists of several parts (Fig. 3). First, the user defines the constraints in<br />

<strong>OCL</strong>, then the constraint definitions are parsed <strong>an</strong>d syntactically <strong>an</strong>alyzed. The<br />

Syntax tree does not contain every necessary in<strong>for</strong>mation, it should be extended<br />

e.g. with type in<strong>for</strong>mation, <strong>an</strong>d implicit self references. This amendment is<br />

per<strong>for</strong>med in the sem<strong>an</strong>tic <strong>an</strong>alysis phase, <strong>an</strong>d it produces the Sem<strong>an</strong>tic Analyzed<br />

Syntax tree. As the next step, the constructed tree is tr<strong>an</strong>s<strong>for</strong>med to a CodeDom<br />

tree. CodeDom is a .NET-based technology that c<strong>an</strong> describe programs using<br />

abstract trees <strong>an</strong>d it c<strong>an</strong> use this tree representation to generate code to <strong>an</strong>y<br />

l<strong>an</strong>guages that is supported by the .NET CLR (like C#, Visual Basic or Java).<br />

Using CodeDom, the generated source code is syntactically correct in all cases;<br />

our task is only to deal with the appropriate sem<strong>an</strong>tic content. Finally, the<br />

compiler tr<strong>an</strong>s<strong>for</strong>ms the CodeDom tree to C# source code, it compiles <strong>an</strong>d builds<br />

it. The output of the <strong>OCL</strong> compiler is a binary executable (a .dll file) that<br />

implements the <strong>OCL</strong> constraint.<br />

Figure 3<br />

The structure of the <strong>OCL</strong> <strong>Compiler</strong><br />

3 The <strong>Compiler</strong><br />

3.1 Lexical Analysis<br />

Lexical <strong>an</strong>d syntactic <strong>an</strong>alysis are realized using the tools Flex [5] <strong>an</strong>d Bison [6].<br />

These tools are optimized <strong>an</strong>d well-tested solutions to syntax tree generation, both<br />

of them were used in thous<strong>an</strong>ds of software projects. Un<strong>for</strong>tunately Flex <strong>an</strong>d<br />

Bison tools use ANSI C code, but they were relative easy to integrate in VMTS.<br />

The first step of the lexical <strong>an</strong>alysis is the tokenization, which parses the source<br />

code <strong>an</strong>d reads lexical patterns (tokens) <strong>for</strong>m it (e.g. identifiers (name) <strong>an</strong>d the<br />

keywords of the l<strong>an</strong>guage). Tokenization eliminates the whitespaces as well as

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!