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.

2. STATE OF THE ART AND RELATED WORK 2.3. Automatic Recognition of Configuration Files<br />

compiles it, resulting in the generation of a parser for a specific configuration file language.<br />

Following are presented some parser generators:<br />

2.3.1 SableCC<br />

SableCC [GH98] is an object-oriented framework that generates compilers, or parsers, in the<br />

Java programming language. This framework is based on two fundamental <strong>de</strong>sign <strong>de</strong>cisions.<br />

Firstly, the framework uses object-oriented techniques to automatically build a strictly-typed<br />

abstract syntax tree that matches the grammar of the compiled language and simplifies <strong>de</strong>bug-<br />

ging. Secondly, the framework generates tree-walker classes using an exten<strong>de</strong>d version of the<br />

visitor <strong>de</strong>sign pattern which enables the impl<strong>em</strong>entation of actions on the no<strong>de</strong>s of the abstract<br />

syntax tree using inheritance.<br />

SableCC specification files do not contain any action co<strong>de</strong>. Instead, SableCC generates an<br />

object-oriented framework in which actions can be ad<strong>de</strong>d by <strong>de</strong>fining new classes containing<br />

the action co<strong>de</strong>. This leads to a shorter <strong>de</strong>velopment cycle, allowing for the rapid prototyping<br />

of SmART.<br />

Given a grammar, SableCC’s produces a set of packages, namely:<br />

• analysis: contains different tree walkers (e.g., <strong>de</strong>pth first, reversed);<br />

• lexer: contains the el<strong>em</strong>ents nee<strong>de</strong>d for the lexical analysis of the grammar;<br />

• no<strong>de</strong>: classes containing no<strong>de</strong> representations;<br />

• parser: contains the parser class.<br />

None of the automatically produced classes ought to be modified. Instead, all of the user<br />

generated co<strong>de</strong> should be put in classes extending those created by SableCC. By doing this,<br />

every time a probl<strong>em</strong> arises (e.g., error in a grammar), it can be easily located and corrected by<br />

modifying only a small portion of the co<strong>de</strong>. Another aspect of discussible importance is that<br />

SableCC is distributed un<strong>de</strong>r the GNU Lesser General Public License.<br />

Notwithstanding, SableCC also reveals some significant shortcomings. SableCC does not<br />

support error productions. In other words, when a generated parser comes upon an unrecog-<br />

nizable token in a configuration file, it does not allow the parse to advance further beyond that<br />

token, consequently halting the parse on that position. Since error productions are a common<br />

feature on parser generators, this lackage was not noticed upon the choice. This, in turn, sev-<br />

ered the ability to produce multiple recognized file blocks to just one. The parsing statistics<br />

also become unreliable, since a parser might not recognize the first token a configuration file<br />

and recognize the rest of the file, but without error productions, parsing will inevitably stop in<br />

the beginning of the file and that parser will be reported to have parsed 0% of the file, when in<br />

fact it would manage to parse nearly 100% of the file.<br />

17

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

Saved successfully!

Ooh no, something went wrong!