01: /*
02: * Copyright (C) Chaperon. All rights reserved.
03: * -------------------------------------------------------------------------
04: * This software is published under the terms of the Apache Software License
05: * version 1.1, a copy of which has been included with this distribution in
06: * the LICENSE file.
07: */
08:
09: package net.sourceforge.chaperon.process.extended;
10:
11: import org.xml.sax.ContentHandler;
12: import org.xml.sax.SAXException;
13:
14: public abstract class StackNode {
15: public State state = null;
16:
17: //public int deep = 0;
18: public StackNode ancestor = null;
19: public StackNode[] ancestors = null;
20: public int lineNumber = 1;
21: public int columnNumber = 1;
22: public int length = 1;
23:
24: public boolean addAncestor(StackNode ancestor) {
25: for (int i = 0; i < ancestors.length; i++)
26: if (ancestors[i] == ancestor)
27: return false;
28:
29: StackNode[] newAncestors = new StackNode[ancestors.length + 1];
30: for (int i = 0; i < ancestors.length; i++)
31: newAncestors[i] = ancestors[i];
32:
33: newAncestors[ancestors.length] = ancestor;
34: ancestors = newAncestors;
35:
36: return true;
37: }
38:
39: public boolean compare(StackNode node) {
40: return (state == node.state) && (lineNumber == node.lineNumber)
41: && (columnNumber == node.columnNumber)
42: && (length == node.length);
43: }
44:
45: public String toCanonicalString(ExtendedParserAutomaton automaton) {
46: return (ancestor != null) ? (ancestor
47: .toCanonicalString(automaton)
48: + "<-null[" + automaton.indexOf(state) + "]")
49: : ("null[" + automaton.indexOf(state) + "]");
50: }
51:
52: public abstract void toXML(ContentHandler contentHandler)
53: throws SAXException;
54:
55: public StackNode getTopMost(StackNode node) {
56: if (lineNumber < node.lineNumber)
57: return node;
58: else if (lineNumber > node.lineNumber)
59: return this;
60: else if (columnNumber < node.columnNumber)
61: return node;
62: else
63: return this;
64: }
65: }
|