18.04.2013 Views

Dissertaç ˜ao de Mestrado Mestrado em Engenharia Informática Jo ...

Dissertaç ˜ao de Mestrado Mestrado em Engenharia Informática Jo ...

Dissertaç ˜ao de Mestrado Mestrado em Engenharia Informática Jo ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

4. AN IMPLEMENTATION 4.5. Original to Generic syntax Converter<br />

<strong>de</strong>lete a parser from the repository, <strong>de</strong>leteParser, which consists on <strong>de</strong>leting the map entry<br />

with the parser name in argument.<br />

4.5.4 Grammar Compiler<br />

The Grammar Compiler is impl<strong>em</strong>ented as a class which receives a grammar <strong>de</strong>finition and<br />

produces a parser from it. After JavaCC generates the parser classes, these must be compiled<br />

before the Parser Repository is able to load th<strong>em</strong>.<br />

In the end, the Grammar Compiler returns a CompilationData object, which tells that<br />

a grammar failed to compile if an exception was caught, or that it compiled successfully other-<br />

wise.<br />

4.5.5 Co<strong>de</strong> Generator<br />

The Co<strong>de</strong> Generator traverses structures composed of no<strong>de</strong>s impl<strong>em</strong>enting the interface <strong>de</strong>-<br />

fined in Listing 4.1 and invokes the method <strong>de</strong>fined the interface upon visiting each no<strong>de</strong> in<br />

or<strong>de</strong>r to generate the generic XML of the pattern associated to that no<strong>de</strong>. The reason why every<br />

no<strong>de</strong> in structure impl<strong>em</strong>ents that interface was already explained in Section 4.2 and consists<br />

on forcing each no<strong>de</strong> of the AST to impl<strong>em</strong>ent a method which can be called by CG. In this way,<br />

the information on how to print the no<strong>de</strong>s to generic XML is stored in the no<strong>de</strong>s and CG gains<br />

the ability to successfully traverse ASTs of any configuration files.<br />

On an early stage of the tool, the co<strong>de</strong> that generates the generic XML of a no<strong>de</strong> in the<br />

AST must be generated manually, for new patterns. However, with the creation of a graphi-<br />

cal interface for the <strong>de</strong>finition of grammars for new types of configuration files in the User<br />

Interface, it should be possible to use the information received from the user to automati-<br />

cally generate that co<strong>de</strong>.<br />

CG is responsible for logging the <strong>de</strong>tails of each configuration file language, such as the<br />

used <strong>de</strong>limiters on patterns, or how a pattern is formatted. For this, CG resorts to a Metadata<br />

special field, which stores the information regarding the <strong>de</strong>limiters used by the patterns, and<br />

another FStr special field to log how each pattern is formatted. Details regarding the generation<br />

of original syntax <strong>de</strong>tails are further <strong>de</strong>scribed in Section 4.6. A set of functions to manipulate<br />

the Metadata and the FStr fields are provi<strong>de</strong>d.<br />

The generic XML must be the same for every configuration file types, following a structure<br />

similar to the presented in Section 1.3, with blocks, comments, parameters and other special ele-<br />

ments. This is important since the generic XML document might become unrecognizable to the<br />

configurator which modifies it if the user <strong>de</strong>ci<strong>de</strong>s, for example, to <strong>de</strong>note blocks by “blockx”.<br />

The configurator will afterwards find a “blockx”, when in fact its operation was <strong>de</strong>fined on a<br />

“block”.<br />

4.5.6 Tentative Grammar Repository<br />

The Tentative Grammar Repository impl<strong>em</strong>ents a linked list of TGRNo<strong>de</strong> objects. A<br />

TGRNo<strong>de</strong> represents a tentative grammar in TGR and contains a TGRNo<strong>de</strong> prev attribute with<br />

45

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

Saved successfully!

Ooh no, something went wrong!