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.4. Data Structures<br />

InternalParser<br />

'()*+,-#".+()&/+0%<br />

!"#$%#&!<br />

!"#$%#&"<br />

Figure 4.1: Recognition of a configuration file by two parsers<br />

InternalParser (Listing 4.3) objects represent parsers generated by the tool, through the<br />

Grammar Compiler. An InternalParser object contains a pointer to the parse method<br />

and the grammar used to construct the parser.<br />

Regarding the parse method, the latter is invoked resorting to the Java reflex API and re-<br />

turns a list of No<strong>de</strong> objects (Listing 4.1) due to be transformed to XML by the<br />

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

Concerning the grammar used for the generation of the InternalParser, it is kept with<br />

the parser in or<strong>de</strong>r to aid users on the generation of new parsers. Consi<strong>de</strong>r the case where a<br />

user tries to configure a file which is new to the tool and two parsers are stored. The result of<br />

the parsing att<strong>em</strong>pt is <strong>de</strong>picted in Figure 4.1.<br />

In the example, two parsers are tested on a configuration file with 100 lines. The first parser,<br />

α, manages to recognize the file from line 0 to 59 and then from line 70 to 99, resulting in a 90%<br />

of parsed file. On the other hand, parser β recognized 20% of the file, from line 50 to 69.<br />

In this situation, the user who would build the new parser for the file might want to access<br />

the grammar of the parser α, since it parsed almost the entire file, and base the new parser on<br />

the old instead of starting from scratch. Also, seen as the second parser recognized the part of<br />

the file that the first did not, the user might want to check the grammar of the second parser.<br />

40

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

Saved successfully!

Ooh no, something went wrong!