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.3. Generic Syntax<br />

interface Parser {<br />

String getParserID();<br />

}<br />

interface InternalParser {<br />

Method getParseMethod();<br />

byte[] getGrammarDefinition();<br />

}<br />

4.3 Generic Syntax<br />

Listing 4.2: Parser data structure<br />

Listing 4.3: InternalParser data structure<br />

Section 2.4 indicated that the chosen format for the representation of the configuration files<br />

in generic syntax would be XML (eXten<strong>de</strong>d Markup Language). Furthermore, that Section<br />

saw that there are two XML parser impl<strong>em</strong>entations for the Java programming language,<br />

DOM [W3S09] and SAX [Pro04]. It was seen that the first keeps a tree in m<strong>em</strong>ory, representing<br />

the XML document, while the second is event-driven.<br />

By balancing the benefits and drawbacks of each parser, DOM was preferred to SAX on<br />

account of representing an XML document in m<strong>em</strong>ory as a tree structure. This allows for a<br />

quick transition of an AST to a DOM tree.<br />

4.4 Data Structures<br />

This section presents the data structures created to cope with various aspects regarding the<br />

passing of data between components. For each data structure, an interface is revealed and an<br />

explanation on the data structure functionality and the methods <strong>de</strong>clared in the interface is<br />

presented.<br />

4.4.1 Parser<br />

Parser objects are used as references for the parsers used by the tool. This impl<strong>em</strong>entation<br />

consi<strong>de</strong>rs that the parsers are i<strong>de</strong>ntified by their name and, therefore, the ParserID field<br />

consists on a String instead. However, the Parser class cannot be instanciated since it is<br />

an abstract class. To distinguish the internal parsers, built by the tool, and external parsers,<br />

built outsi<strong>de</strong> the tool and imported by a user, two classes extending Parser were created:<br />

InternalParser and ExternalParser. The two classes are now explained.<br />

39

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

Saved successfully!

Ooh no, something went wrong!