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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

interface CompilationData {<br />

boolean wasCompiled();<br />

String getErrorMessage();<br />

String getParserLocation();<br />

}<br />

Listing 4.7: CompilationData data structure<br />

method. If the compilation en<strong>de</strong>d without any occurred error, the parser location is given by<br />

the getParserLocation method. Alternatively, if an error ocurred during the compilation,<br />

it is accessible through the getErrorMessage method.<br />

4.5 Original to Generic syntax Converter<br />

After the components required in the Original to Generic syntax Converter were i<strong>de</strong>ntified and<br />

the behaviour of each one was <strong>de</strong>scribed, their impl<strong>em</strong>entation took place. Following is shown<br />

how the components i<strong>de</strong>ntified in Section 3.3 were impl<strong>em</strong>ented.<br />

4.5.1 User Interface<br />

The User Interface is passed multiple configuration file locations upon its invocation by<br />

the user. The parsing of multiple configuration files is sequential, or, in other words, UI config-<br />

ures one file at a time and only when that file is configured should the next file configuration<br />

start.<br />

To configure a file, UI sends its location to the Configuration File Parser in or<strong>de</strong>r<br />

to parse it with every available parser. The Configuration File Parser returns a map of<br />

ParsingData objects which tells if the parsing was successful with any parser, as well as the<br />

percentage of parsed file, the parsed file blocks in generic syntax and the position of the first<br />

and last characters of the corresponding block.<br />

When a file is successfully parsed, the corresponding AST is sent to Co<strong>de</strong> Generator and<br />

the returned file in XML is placed in a t<strong>em</strong>porary file fol<strong>de</strong>r, with the same name as the original<br />

configuration file, plus the suffix “.xml”.<br />

If a file was not entirely parsed, UI displays the parts of the file which were recognized<br />

by the parser with the best configuration file parse percentage and the grammar used on the<br />

respective parser. Then, UI prompts the user for a file containing a grammar to be com-<br />

piled and sends the grammar to Grammar Compiler. The Grammar Compiler returns a<br />

CompilationData object which tells whether there was any error compiling the grammar. If<br />

an error ocurred, the user must alter the grammar in the file to correct the error(s) and then<br />

trigger another grammar compilation until the grammar is successfully compiled.<br />

When a grammar is successfully compiled, UI att<strong>em</strong>pts to parse the configuration file<br />

with the newly generated parser by invoking the Configuration File Parser’s doParse<br />

method which tests a file with a single parser. If the file was still not entirely recognized, the<br />

43

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

Saved successfully!

Ooh no, something went wrong!