Alachisoft.NCache.Parser.Reduction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-parser Show documentation
Show all versions of nc-parser Show documentation
Internal package of Alachisoft.
package Alachisoft.NCache.Parser;
// C# Translation of GoldParser, by Marcus Klimstra .
// Based on GOLDParser by Devin Cook .
/**
* This class is used by the engine to hold a reduced rule. Rather than contain
* a list of Symbols, a reduction contains a list of Tokens corresponding to the
* the rule it represents. This class is important since it is used to store the
* actual source program parsed by the Engine.
*/
public class Reduction {
private java.util.ArrayList m_tokens;
private Rule m_parentRule;
private Object m_tag;
/* constructor */
/**
* Creates a new Reduction.
*/
public Reduction() {
m_tokens = new java.util.ArrayList();
}
/* properties */
/**
* Returns an ArrayList containing the Token s in this reduction.
*/
public final java.util.ArrayList getTokens() {
return m_tokens;
}
/**
* Returns the Rule that this Reduction represents.
*/
public final Rule getParentRule() {
return m_parentRule;
}
public final void setParentRule(Rule value) {
m_parentRule = value;
}
/**
* This is a general purpose field that can be used at the developer's leisure.
*/
public final Object getTag() {
return m_tag;
}
public final void setTag(Object value) {
m_tag = value;
}
/* public methods */
/**
* Returns the token with the specified index.
*/
public final Token GetToken(int p_index) {
return (Token) m_tokens.get(p_index);
}
/**
* Returns a string-representation of this Reduction.
*/
@Override
public String toString() {
return m_parentRule.toString();
}
/**
* Makes the IGoldVisitor visit this Reduction .
* See the GoldTest sample project.
*/
public final void Accept(IGoldVisitor p_visitor) {
p_visitor.Visit(this);
}
/**
* Makes the IGoldVisitor visit the children of this
* Reduction .
* See the GoldTest sample project.
*/
public final void ChildrenAccept(IGoldVisitor p_visitor) {
//Huma:
Token token;
Object tempVar = new Object();
for (Object tokenObj : m_tokens) {
token = (Token) tokenObj;
if (token.getKind() == SymbolType.NonTerminal)
tempVar = token.getData();
{
((Reduction) ((tempVar instanceof Reduction) ? tempVar : null)).Accept(p_visitor);
}
}
// for (Token token : m_tokens) {
// if (token.getKind() == SymbolType.NonTerminal)
// Object tempVar = token.getData(); {
// ((Reduction)((tempVar instanceof Reduction) ? tempVar : null)).Accept(p_visitor);
// }
// }
}
/* internal methods */
/**
*
*/
public final void AddToken(Token p_token) {
m_tokens.add(p_token);
}
}