com.inxar.syntacs.grammar.regular
Class REGrammar

java.lang.Object
  |
  +--com.inxar.syntacs.grammar.regular.REGrammar
All Implemented Interfaces:
RegularGrammar, RegularSet

public class REGrammar
extends Object
implements RegularSet, RegularGrammar

Standard RegularGrammar implementation.


Constructor Summary
REGrammar()
          Constructs the REGrammar.
REGrammar(int id)
          Constructs the REGrammar having the given ID.
REGrammar(int id, String name)
          Constructs the REGrammar having the given ID and name.
 
Method Summary
 RegularSet compile()
          When token construction is complete, compile() compiles and returns a RegularSet object which can be used for generation of DFA's, for example.
 Epsilon getEpsilon()
          Returns the Epsilon symbol in the (rare) case one needs it.
 int getID()
          Returns the globally allocated ID for this RegularSet.
 Interval getInterval(int id)
          Returns the Interval by the given id.
 String getName()
          Returns the name of this RegularSet.
 RegularGrammar getRegularGrammar()
          Returns the parent RegularGrammar.
 IntSet getStart()
          Returns the IntSet of intervals which are visible from some abstract initial state.
 Token getToken(int id)
          Returns the Token with the given id.
 int intervals()
          Returns the number of Intervals used by the grammar.
 CharClass newCharClass()
          Allocates and returns a new CharClass expression ([^-a-z]).
 CharString newCharString(String s)
          Allocates and returns a new CharString expression ('+') wrapping the given RegularExpression.
 Closure newClosure(RegularExpression re)
          Allocates and returns a new Closure expression ('*') wrapping the given RegularExpression.
 Concatenation newConcatenation(RegularExpression left, RegularExpression right)
          Allocates and returns a new Concatenation expression from the given left and right RegularExpressions.
 Interval newInterval(char c)
          Allocates and returns a new Interval expression over the given char.
 Interval newInterval(int lo, int hi)
          Allocates and returns a new Interval expression over the given character range from lo to hi, inclusive.
 Option newOption(RegularExpression re)
          Allocates and returns a new Option expression ('?') wrapping the given RegularExpression.
 PositiveClosure newPositiveClosure(RegularExpression re)
          Allocates and returns a new PositiveClosure expression ('+') wrapping the given RegularExpression.
 RegularToken newToken(int tokenID, String tokenName, RegularExpression re)
          Allocates and returns a new RegularToken mapping the given name to the given RegularExpression.
 RegularToken newToken(int tokenID, String tokenName, String re)
          Allocates a new RegularToken in this grammar having the given tokenID number, name, and regex.
 Union newUnion()
          Allocates and returns a new Union expression.
 int tokens()
          Returns the number of tokens in the RegularSet.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

REGrammar

public REGrammar(int id,
                 String name)
Constructs the REGrammar having the given ID and name.

REGrammar

public REGrammar(int id)
Constructs the REGrammar having the given ID.

REGrammar

public REGrammar()
Constructs the REGrammar.
Method Detail

getName

public String getName()
Description copied from interface: RegularSet
Returns the name of this RegularSet. This is generally relevant only when PushdownRegularGrammars are being created.
Specified by:
getName in interface RegularSet

getID

public int getID()
Description copied from interface: RegularSet
Returns the globally allocated ID for this RegularSet. This is useful for lexer construction algorithms which use "start states" or multiple DFA's and switch between them.
Specified by:
getID in interface RegularSet

tokens

public int tokens()
Description copied from interface: RegularSet
Returns the number of tokens in the RegularSet.
Specified by:
tokens in interface RegularSet

newConcatenation

public Concatenation newConcatenation(RegularExpression left,
                                      RegularExpression right)
Description copied from interface: RegularGrammar
Allocates and returns a new Concatenation expression from the given left and right RegularExpressions.
Specified by:
newConcatenation in interface RegularGrammar

newUnion

public Union newUnion()
Description copied from interface: RegularGrammar
Allocates and returns a new Union expression. Subsequent modification of the Union is required (i.e. an empty union is invalid).
Specified by:
newUnion in interface RegularGrammar

newClosure

public Closure newClosure(RegularExpression re)
Description copied from interface: RegularGrammar
Allocates and returns a new Closure expression ('*') wrapping the given RegularExpression.
Specified by:
newClosure in interface RegularGrammar

newPositiveClosure

public PositiveClosure newPositiveClosure(RegularExpression re)
Description copied from interface: RegularGrammar
Allocates and returns a new PositiveClosure expression ('+') wrapping the given RegularExpression. Note that the PositiveClosure is a shortcut for concatenation-closure. Therefore, a+ expands to aa*.
Specified by:
newPositiveClosure in interface RegularGrammar

newOption

public Option newOption(RegularExpression re)
Description copied from interface: RegularGrammar
Allocates and returns a new Option expression ('?') wrapping the given RegularExpression. Note that Option is not an atomic RegularExpression. Thus, 'a?' expands to the Union (a|Epsilon).
Specified by:
newOption in interface RegularGrammar

newCharString

public CharString newCharString(String s)
Description copied from interface: RegularGrammar
Allocates and returns a new CharString expression ('+') wrapping the given RegularExpression. Note CharString is not a fundamental expression. Thus, 'abc' expands to the concatenation sequence a-b-c.
Specified by:
newCharString in interface RegularGrammar

newCharClass

public CharClass newCharClass()
Description copied from interface: RegularGrammar
Allocates and returns a new CharClass expression ([^-a-z]). Subsequent modification of the character class is required (i.e. an empty character class is invalid).
Specified by:
newCharClass in interface RegularGrammar

newInterval

public Interval newInterval(char c)
Description copied from interface: RegularGrammar
Allocates and returns a new Interval expression over the given char. Note newInterval(97, 97) has the same meaning as newInterval('a') under the ascii or unicode charset.
Specified by:
newInterval in interface RegularGrammar

newInterval

public Interval newInterval(int lo,
                            int hi)
Description copied from interface: RegularGrammar
Allocates and returns a new Interval expression over the given character range from lo to hi, inclusive.
Specified by:
newInterval in interface RegularGrammar

newToken

public RegularToken newToken(int tokenID,
                             String tokenName,
                             RegularExpression re)
Description copied from interface: RegularGrammar
Allocates and returns a new RegularToken mapping the given name to the given RegularExpression. This is the 'special' newXXX() method in that it does not return a RegularExpression, but a Token. The RegularToken is returned to potentially facilitate it's incorporation into other languages such as the ContextFreeLanguage.newTerminal(Token) method. Therefore, calling newToken() not only makes a RegularToken object on the regex, it becomes associated into the grammar.
Specified by:
newToken in interface RegularGrammar

newToken

public RegularToken newToken(int tokenID,
                             String tokenName,
                             String re)
Description copied from interface: RegularGrammar
Allocates a new RegularToken in this grammar having the given tokenID number, name, and regex. The RegularGrammar is then responsible for parsing the regex string and generating a RegularExpression.
Specified by:
newToken in interface RegularGrammar

getEpsilon

public Epsilon getEpsilon()
Description copied from interface: RegularGrammar
Returns the Epsilon symbol in the (rare) case one needs it.
Specified by:
getEpsilon in interface RegularGrammar

getStart

public IntSet getStart()
Description copied from interface: RegularSet
Returns the IntSet of intervals which are visible from some abstract initial state. This is the first set over the collection of tokens (each with its regular expression). Therefore, this set represents the first state in a DFA.
Specified by:
getStart in interface RegularSet

getInterval

public Interval getInterval(int id)
Description copied from interface: RegularSet
Returns the Interval by the given id.
Specified by:
getInterval in interface RegularSet

intervals

public int intervals()
Description copied from interface: RegularSet
Returns the number of Intervals used by the grammar.
Specified by:
intervals in interface RegularSet

getToken

public Token getToken(int id)
Description copied from interface: RegularSet
Returns the Token with the given id.
Specified by:
getToken in interface RegularSet

compile

public RegularSet compile()
Description copied from interface: RegularGrammar
When token construction is complete, compile() compiles and returns a RegularSet object which can be used for generation of DFA's, for example. The compilation process is essentially making sure Intervals each get a unique ID and concatenating ExpressionTerminators where appropriate.
Specified by:
compile in interface RegularGrammar

getRegularGrammar

public RegularGrammar getRegularGrammar()
Description copied from interface: RegularSet
Returns the parent RegularGrammar.
Specified by:
getRegularGrammar in interface RegularSet

toString

public String toString()
Overrides:
toString in class Object