|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.inxar.syntacs.grammar.regular.REGrammar
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 |
public REGrammar(int id, String name)
REGrammar
having the given ID and name.public REGrammar(int id)
REGrammar
having the given ID.public REGrammar()
REGrammar
.Method Detail |
public String getName()
RegularSet
RegularSet
. This is
generally relevant only when
PushdownRegularGrammars
are being created.getName
in interface RegularSet
public int getID()
RegularSet
RegularSet
. This is useful for lexer construction
algorithms which use "start states" or multiple DFA's and
switch between them.getID
in interface RegularSet
public int tokens()
RegularSet
RegularSet
.tokens
in interface RegularSet
public Concatenation newConcatenation(RegularExpression left, RegularExpression right)
RegularGrammar
Concatenation
expression from the given left and right
RegularExpressions
.newConcatenation
in interface RegularGrammar
public Union newUnion()
RegularGrammar
Union
expression.
Subsequent modification of the Union
is required
(i.e. an empty union is invalid).newUnion
in interface RegularGrammar
public Closure newClosure(RegularExpression re)
RegularGrammar
Closure
expression
('*') wrapping the given RegularExpression
.newClosure
in interface RegularGrammar
public PositiveClosure newPositiveClosure(RegularExpression re)
RegularGrammar
PositiveClosure
expression ('+') wrapping the given
RegularExpression
. Note that the
PositiveClosure
is a shortcut for
concatenation-closure. Therefore, a+ expands to aa*.newPositiveClosure
in interface RegularGrammar
public Option newOption(RegularExpression re)
RegularGrammar
Option
expression
('?') wrapping the given RegularExpression
. Note
that Option
is not an atomic
RegularExpression
. Thus, 'a?' expands to the
Union
(a|Epsilon
).newOption
in interface RegularGrammar
public CharString newCharString(String s)
RegularGrammar
CharString
expression
('+') wrapping the given RegularExpression
. Note
CharString
is not a fundamental expression. Thus,
'abc' expands to the concatenation sequence a-b-c.newCharString
in interface RegularGrammar
public CharClass newCharClass()
RegularGrammar
CharClass
expression
([^-a-z]). Subsequent modification of the character class is
required (i.e. an empty character class is invalid).newCharClass
in interface RegularGrammar
public Interval newInterval(char c)
RegularGrammar
Interval
expression
over the given char
. Note newInterval(97,
97)
has the same meaning as
newInterval('a')
under the ascii or unicode
charset.newInterval
in interface RegularGrammar
public Interval newInterval(int lo, int hi)
RegularGrammar
Interval
expression
over the given character range from lo to hi, inclusive.newInterval
in interface RegularGrammar
public RegularToken newToken(int tokenID, String tokenName, RegularExpression re)
RegularGrammar
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.newToken
in interface RegularGrammar
public RegularToken newToken(int tokenID, String tokenName, String re)
RegularGrammar
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
.newToken
in interface RegularGrammar
public Epsilon getEpsilon()
RegularGrammar
Epsilon
symbol in the (rare) case one
needs it.getEpsilon
in interface RegularGrammar
public IntSet getStart()
RegularSet
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
.getStart
in interface RegularSet
public Interval getInterval(int id)
RegularSet
Interval
by the given id.getInterval
in interface RegularSet
public int intervals()
RegularSet
Intervals
used by the
grammar.intervals
in interface RegularSet
public Token getToken(int id)
RegularSet
Token
with the given id.getToken
in interface RegularSet
public RegularSet compile()
RegularGrammar
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.compile
in interface RegularGrammar
public RegularGrammar getRegularGrammar()
RegularSet
RegularGrammar
.getRegularGrammar
in interface RegularSet
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |