public class Dot extends Object
The algorithm is as follows:
S -> . E
S -> .E closure: E -> .E + T E -> .E - TClosure rules are identical when the two rules are the same, and the dot positions are also the same.
state 0 S -> .E closure: E -> .E + T closure on E E -> .E - T closure on E E -> .T closure on E T -> .T * F closure on T T -> .T / F closure on T T -> .F closure on T F -> .number closure on F F -> .- F closure on F F -> .( F ) closure on F state 1 (with its closure, transition of state 0 with E) S -> E . E -> E .+ T E -> E .- T state 2 (with its closure, transition of state 1 with +) E -> E + .T closure: T -> .T * F closure on T T -> .T / F closure on T T -> .F closure on T F -> .number closure on F F -> .- F closure on F F -> .( F ) closure on F etc...
As such, a dot is a positional element that defines a rule, and the position the observed rule item.
| Constructor and Description |
|---|
Dot(State state,
Rule rule,
RuleItem item)
Construct a dot
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAllLookaheads(Set<Integer> symbolIds)
merge lookaheads into this dot
|
void |
addLookahead(int symbolId)
Adds a non terminal to the dot
|
static boolean |
equals(Dot a,
Dot b)
Utility method to compare two dots, accounting for nulls
|
boolean |
equals(Object obj) |
RuleItem |
getItem() |
Set<Integer> |
getLookahead() |
Rule |
getRule() |
State |
getState() |
Dot |
next()
State dots are linked.
|
RuleItem |
nextItem()
Given a dot, move the dot to the right of the pointed symbol
It does this by going to the rule and finding the rule item i+1 from the rule item i. |
void |
setItem(RuleItem item) |
void |
setRule(Rule rule) |
void |
setState(State state) |
String |
toString()
Returns a "dotted" representation of the rule items in the rule
|
public RuleItem nextItem()
public Dot next()
for a "state view" of its dots.public void addLookahead(int symbolId)
symbolId - is the id of the non terminalpublic void addAllLookaheads(Set<Integer> symbolIds)
symbolIds - is the set of symbols that make up the lookaheadpublic State getState()
public void setState(State state)
state - the state to setpublic RuleItem getItem()
public void setItem(RuleItem item)
item - the item to setpublic Rule getRule()
public void setRule(Rule rule)
rule - the rule to setpublic boolean equals(Object obj)
equals in class ObjectObject.equals(java.lang.Object)public static boolean equals(Dot a, Dot b)
a - the first element. Can be null.b - the second element. Can be null.public String toString()
toString in class ObjectObject.toString()Copyright © 2017. All rights reserved.