KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > parsers > acc > SyntaxElement


1 package org.objectweb.jac.core.parsers.acc;
2
3 /**
4  * Base class for Terminal and NonTerminal.
5  */

6 public class SyntaxElement {
7    /** Element's name */
8    String JavaDoc name;
9    /** Left position of element in stream */
10    int left;
11    /** Right position of element in stream */
12    int right;
13
14    SyntaxElement parent;
15
16    public SyntaxElement(String JavaDoc name, int left, int right) {
17       this.name = name;
18       this.left = left;
19       this.right = right;
20    }
21    public String JavaDoc getName() {
22       return name;
23    }
24    public int getLeft() {
25       return left;
26    }
27    public int getRight() {
28       return right;
29    }
30    public void setParent(SyntaxElement parent) {
31       this.parent = parent;
32    }
33
34    public SyntaxElement getParent() {
35       return parent;
36    }
37
38    /**
39     * Find a parent element of this element with a given name
40     * @param searchedName the name to find
41     * @return a SyntaxElement who is a parent of this (or this)
42     */

43    public SyntaxElement findParent(String JavaDoc searchedName) {
44       if (name.equals(searchedName))
45          return this;
46       else if (parent==null)
47          return null;
48       else
49          return parent.findParent(searchedName);
50    }
51
52    public String JavaDoc toString() {
53       return name+":"+left+"-"+right;
54    }
55 }
56
Popular Tags