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 ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
3. AN APPLICATION RECONFIGURATION FRAMEWORK 3.3. Original to Generic syntax Converter<br />
Listing 3.2: Configuration File Parser proposed interface<br />
interface CFP {<br />
Map doParse(String fileName);<br />
ParsingData doParse(String fileName, Parser parser);<br />
}<br />
Repository. Then, the user can fetch the previsouly built grammars through the<br />
getTentativeGrammar call.<br />
The parsers generated by the Grammar Compiler must be validated by the user to check<br />
if the new parser is able to parse the configuration file, or if the generic syntax produced by the<br />
parser is in<strong>de</strong>ed the <strong>de</strong>sired one. UI must handle this information and show it to the user in<br />
a user-friendly optic (e.g., graphically). Then, if the user approves the parser, he can summon<br />
the approveParser method to store the parser with the r<strong>em</strong>aining parsers in the Parser<br />
Repository. Finally, UI stores the generic syntax in m<strong>em</strong>ory on a file.<br />
Besi<strong>de</strong>s the presented basic functionality, UI offers some more utilities to the user. Namely,<br />
the importParser method allows the importation of external parsers if the user is already<br />
in possession of a functional parser for a new configuration file. Additionally, the user may<br />
suspend the tool’s execution and resume it later through the haltSession method. This<br />
method stores the tentative grammars to disk, as well as other volatile data in m<strong>em</strong>ory, such as<br />
the produced file in generic syntax, if it was already produced. The recoverSession method<br />
obtains all the stored data to resume a previously saved session.<br />
Configuration File Parser<br />
The Configuration File Parser (CFP, Listing 3.2) can either parse a configuration file with every<br />
parser in the database or just with a single one. The parsers analyse the configuration files in<br />
their original syntax, <strong>de</strong>clared in a grammar which <strong>de</strong>fines the tokens and productions of that<br />
syntax, and produce the abstract syntax tree (AST) of the file.<br />
The ASTs generated by the parsers must follow the typing indicated in Section 1.3. There-<br />
fore, no<strong>de</strong>s composing an AST are either parameters, blocks, comments or no<strong>de</strong>s corresponding<br />
to new patterns. By assuring that the ASTs are typed in such a way, it is possible to conceive a<br />
uniform Co<strong>de</strong> Generator, which is able to traverse the AST of any application. Furthermore,<br />
strictly typed ASTs guarantee that the generic syntax is constant for every application. In other<br />
words, the generic syntax will be composed of el<strong>em</strong>ents like parameters, blocks, comments and<br />
specials, which is a standard recognized by the file modification agent.<br />
CFP may iterate the available parsers in the Parser Repository and att<strong>em</strong>pt to parse<br />
the input file with each one of th<strong>em</strong>. Alternatively, CFP may also be called to parse a file with a<br />
newly generated parser if the file was not entirely recognized with any of the existing parsers.<br />
When a parser is tested, it returns the configuration file intervals which were recognized,<br />
along with the AST of each interval. The ASTs are sent to the Co<strong>de</strong> Generator to be con-<br />
verted into generic syntax, in or<strong>de</strong>r to help the user analyse and validate the output produced<br />
28