org.ourgrid.common.spec.grammar
Interface Grammar

All Known Implementing Classes:
CommonGrammar

public interface Grammar

This interface is one of the principal parts of the syntactical module of a compiler. It handles every operation about the language and its formation rules.


Method Summary
 void addRule(Rule newRule)
          Adds a new rule to the grammar.
 void addSymbol(Symbol symbol)
          Adds a symbol in the grammar.
 Symbol getEndOfSourceSymbol()
          Defines the last symbol from source.
 Symbol getInitialSymbol()
          Returns the initial symbol of the grammar.
 Rule getRule(int ruleNumber)
          Returns the rule defined by a given number.
 Rule getRule(Symbol stackTop, Symbol nextSymbol)
          At a syntactical compilation ( considering a predictor LL(n) grammar) this is one of the principal operations, that is: at one certain moment, where the next symbol from source and the stack top are non-terminals, it is necessary to know what rule from grammar has to be used to continue with the process.
 Symbol getSymbol(java.lang.String symbolName)
          Gets the symbol represented by the symbolName
 

Method Detail

getRule

Rule getRule(Symbol stackTop,
             Symbol nextSymbol)
At a syntactical compilation ( considering a predictor LL(n) grammar) this is one of the principal operations, that is: at one certain moment, where the next symbol from source and the stack top are non-terminals, it is necessary to know what rule from grammar has to be used to continue with the process.

Parameters:
stackTop - The symbol at the stack top.
nextSymbol - The symbol just read from source.
Returns:
The rule object to be used at the case - null if any.

getRule

Rule getRule(int ruleNumber)
Returns the rule defined by a given number.

Parameters:
ruleNumber - The rule number.
Returns:
A object Rule that is the rule with ruleNumber as code.

addRule

void addRule(Rule newRule)
Adds a new rule to the grammar.

Parameters:
newRule - The Rule to be inserted at the grammar.

addSymbol

void addSymbol(Symbol symbol)
Adds a symbol in the grammar.

Parameters:
symbol - The symbol to be added.

getSymbol

Symbol getSymbol(java.lang.String symbolName)
Gets the symbol represented by the symbolName

Parameters:
symbolName - The symbolName in the grammar that represents the required symbol.
Returns:
The symbol represented by the symbolName.

getInitialSymbol

Symbol getInitialSymbol()
Returns the initial symbol of the grammar.

Returns:
The initial symbol of the grammar.

getEndOfSourceSymbol

Symbol getEndOfSourceSymbol()
Defines the last symbol from source. It means that if this symbol is read then the source has finished.

Returns:
The symbol that represents the end of the source.