org.ourgrid.common.spec.grammar
Class CommonGrammar

java.lang.Object
  extended by org.ourgrid.common.spec.grammar.CommonGrammar
All Implemented Interfaces:
Grammar

public class CommonGrammar
extends java.lang.Object
implements Grammar

From Project: Caymman(DSC/UFCG) Description: This class represents a LL(1) grammar.

Version:
1.0 Created on Sep 25, 2003 ************************************************************, 2.0 Updated on May 23, 2004

Constructor Summary
CommonGrammar()
           
 
Method Summary
 void addRule(Rule rule)
          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 id)
          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.
 java.util.Iterator<Rule> getRules()
          Gets all the rules of the grammar.
 Symbol getSymbol(java.lang.String symbolName)
          Gets the symbol represented by the symbolName
 int lastNonTerminal()
          The code of the last non terminal symbol in the grammar.
 int lastTerminal()
          The code of the last terminal symbol in the grammar.
 void loadSyntacticTable()
          Loads the internal syntactical table using the rules and symbols inserted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonGrammar

public CommonGrammar()
See Also:
Grammar
Method Detail

addSymbol

public void addSymbol(Symbol symbol)
Description copied from interface: Grammar
Adds a symbol in the grammar.

Specified by:
addSymbol in interface Grammar
Parameters:
symbol - The symbol to be added.
See Also:
Grammar.addSymbol(Symbol)

addRule

public void addRule(Rule rule)
Description copied from interface: Grammar
Adds a new rule to the grammar.

Specified by:
addRule in interface Grammar
Parameters:
rule - The Rule to be inserted at the grammar.
See Also:
Grammar.addRule(Rule)

getSymbol

public Symbol getSymbol(java.lang.String symbolName)
Description copied from interface: Grammar
Gets the symbol represented by the symbolName

Specified by:
getSymbol in interface Grammar
Parameters:
symbolName - The symbolName in the grammar that represents the required symbol.
Returns:
The symbol represented by the symbolName.
See Also:
Grammar.getSymbol(java.lang.String)

getRule

public Rule getRule(int id)
Description copied from interface: Grammar
Returns the rule defined by a given number.

Specified by:
getRule in interface Grammar
Parameters:
id - The rule number.
Returns:
A object Rule that is the rule with ruleNumber as code.
See Also:
Grammar.getRule(int)

getRule

public Rule getRule(Symbol stackTop,
                    Symbol nextSymbol)
Description copied from interface: Grammar
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.

Specified by:
getRule in interface Grammar
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.
See Also:
Grammar.getRule(Symbol,Symbol)

getInitialSymbol

public Symbol getInitialSymbol()
Description copied from interface: Grammar
Returns the initial symbol of the grammar.

Specified by:
getInitialSymbol in interface Grammar
Returns:
The initial symbol of the grammar.
See Also:
Grammar.getInitialSymbol()

getEndOfSourceSymbol

public Symbol getEndOfSourceSymbol()
Description copied from interface: Grammar
Defines the last symbol from source. It means that if this symbol is read then the source has finished.

Specified by:
getEndOfSourceSymbol in interface Grammar
Returns:
The symbol that represents the end of the source.
See Also:
Grammar.getEndOfSourceSymbol()

lastTerminal

public int lastTerminal()
The code of the last terminal symbol in the grammar.

Returns:
The code of the last terminal.

lastNonTerminal

public int lastNonTerminal()
The code of the last non terminal symbol in the grammar.

Returns:
The code of the last non Terminal.

getRules

public java.util.Iterator<Rule> getRules()
Gets all the rules of the grammar.

Returns:
The iterator with all the rules of the grammar.

loadSyntacticTable

public void loadSyntacticTable()
Loads the internal syntactical table using the rules and symbols inserted. ATTENTION: Do not try to compile using this grammar without before call this method!!! Generally it will be used after finish to read the grammar description file.

See Also:
GrammarReader