Java Reference
In-Depth Information
G
rammar
(S): Creates a new grammar with start symbol S. The grammar
does not yet contain any productions.
P
roduction
, rhs ): Creates a new production for nonterminal A and returns
a descriptor for the production. The iterator rhs supplies the symbols for
the production's RHS.
(A
P
roductions
( ): Returns an iterator that visits each of the grammar's produc-
tions in no particular order.
N
onterminal
(A): Adds A to the set of nonterminals. An error occurs if A
is already a terminal symbol. The function returns a descriptor for the
nonterminal.
T
erminal
( x ): Adds x to the set of terminals. An error occurs if x is already a
nonterminal symbol. The function returns a descriptor for the terminal.
N
on
T
erminals
( ): Returns an iterator for the set of nonterminals.
T
erminals
( ): Returns an iterator for the set of terminal symbols.
I
s
T
erminal
(
X
): Returns true if
X
is a terminal; otherwise, returns false .
RHS( p ): Returns an iterator for the symbols on the RHS of production p .
LHS( p ): Returns the nonterminal defined by production p .
P
roductions
F
or
(A): Returns an iterator that visits each production for non-
terminal A.
O
ccurrences
(
X
): Returns an iterator that visits each occurrence of
X
in the
RHS of all rules.
P
roduction
( y ): Returns a descriptor for the production A
→α
where
α
con-
tains the occurrence y of some vocabulary symbol.
T
ail
( y ): Accesses the symbols appearing after an occurrence. Given a symbol
occurrence y in the rule A
→α y β
,T
ail
( y ) returns an iterator for the
symbols in
β
.
4.5.2 Deriving the Empty String
One of the most common grammar computations determines which nonter-
minals can derive
. This information is important because such nonterminals
may disappear during a parse and hencemust be handled carefully. Determin-
ing if a nonterminal can derive
λ
λ
is not entirely trivial because the derivation
can take more than one step:
A
BCD
BC
B
⇒λ.
 
 
Search WWH ::




Custom Search