/*
PseudoCode Interpreted Language (PCIL): Part of the algoviz@vt collection of algorithm visualizations.
Copyright (C) 2008 Brandon Malone, Frank Hadlock
This file is part of the PseudoCode Interpreted Language.
PseudoCode Interpreted Language is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
PseudoCode Interpreted Language is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with
PseudoCode Interpreted Language. If not, see
.
*/
/*
* ParseEntry.java
*
* Created on March 2, 2008, 6:48 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package syntacticanalysis;
/**
*
* @author Brandon
*/
public class ParseEntry {
private Terminal sourceToken;
private Nonterminal sententialFormState;
private int ruleIndex;
/** Creates a new instance of ParseEntry */
public ParseEntry(Terminal sourceToken, Nonterminal sententialFormState) {
this.setSourceToken(sourceToken);
this.setSententialFormState(sententialFormState);
this.setRuleIndex(-1);
}
/** Creates a new instance of ParseEntry */
public ParseEntry(Terminal sourceToken, Nonterminal sententialFormState, int ruleIndex) {
this.setSourceToken(sourceToken);
this.setSententialFormState(sententialFormState);
this.setRuleIndex(ruleIndex);
}
public ParseEntry(String line) {
// assume of the form: ~[input]~0
String[] split = line.split("~");
// also, strip off the <> and []
String sententialFormState = split[0].substring(1, split[0].length() - 1);
String sourceToken = split[1].substring(1, split[1].length() - 1);
setSententialFormState(new Nonterminal(sententialFormState));
setSourceToken(new Terminal(sourceToken));
setRuleIndex(Integer.parseInt(split[2]));
}
public int hashCode() {
return getSourceToken().hashCode() * getSententialFormState().hashCode();
}
public boolean equals(Object other) {
if (other instanceof ParseEntry) {
return equals((ParseEntry)other);
}
return false;
}
public boolean equals(ParseEntry pe) {
return pe.getSourceToken().equals(getSourceToken()) && pe.getSententialFormState().equals(getSententialFormState());
}
public Terminal getSourceToken() {
return sourceToken;
}
public void setSourceToken(Terminal sourceToken) {
this.sourceToken = sourceToken;
}
public Nonterminal getSententialFormState() {
return sententialFormState;
}
public void setSententialFormState(Nonterminal sententialFormState) {
this.sententialFormState = sententialFormState;
}
public int getRuleIndex() {
return ruleIndex;
}
public void setRuleIndex(int ruleIndex) {
this.ruleIndex = ruleIndex;
}
public String toString() {
return sententialFormState.toString() + "~" + sourceToken.toString() + "~" + ruleIndex;
}
}