KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > parser > ParseElements


1 package com.daffodilwoods.daffodildb.utils.parser;
2
3 import java.util.HashMap JavaDoc;
4 import javax.swing.tree.*;
5 import com.daffodilwoods.database.utility.P;
6 import com.daffodilwoods.daffodildb.utils.DBStack;
7
8    /**
9     * This class contains the necessary objects which is needed at the time of
10     * parsing the query.
11     * Object of this class is passed as reference to all the rules.
12     */

13
14 public class ParseElements {
15    /**
16     * HashMap for maintaining failed rule and passed rule entry.
17     * Key is object of class Key, which is the combination of nameOfRule and position.
18     */

19    HashMap JavaDoc successfulRule;
20
21    /**
22     * HashMap on Temporary basis
23     */

24     HashMap JavaDoc hashMap;
25
26    /**
27     * DebugTree object is used to construct parse tree
28     */

29
30    /**
31     * Position is held to maintain the parsePosition of query.
32     */

33    int position;
34
35    /**
36     * LookAhead Stack is maintained for lookAhead implementation.
37     */

38
39    /**
40     * ParentNode Object is held to have the reference of parent Object.
41     */

42    DefaultMutableTreeNode parentNode;
43
44    /**
45     * Object recursiveObject is used to assign the value of recursiveObject
46     * set to the next rule.
47     */

48    Object JavaDoc recursiveObject;
49
50    /**
51     * RecursionState states us the nameOfRule for which state is true.
52     */

53    String JavaDoc recursionState;
54
55    /**
56     * Query is the query to be parsed.
57     */

58    String JavaDoc query;
59
60    /**
61     * QueryArray is array of characters of query.
62     */

63    char[] queryArray;
64
65    /**
66     * Array held which contains the array of characters of tokens of
67     * query.
68     */

69    char[][] queryTokenCharacterArray;
70
71    /**
72     * Array containing the tokens of query.
73     */

74    Object JavaDoc []tokens;
75
76    /**
77     * Array conataining the position of token in the query.
78     */

79    Object JavaDoc []index;
80
81    /**
82     * ParseException Object is held to throw the parseException if it
83     * fails.
84     */

85    ParseException parseException = new ParseException();
86
87    boolean tokenFlag;
88    boolean bestOptionFlag;
89
90    /**
91     * Stacks held for drawing parse tree.
92     */

93    private DBStack treeNode = new DBStack();
94
95    void pushElementsForTree(){
96       treeNode.push(parentNode);
97    }
98
99    void popElementsFromTree(){
100       parentNode = (DefaultMutableTreeNode)treeNode.pop();
101    }
102
103    /**
104     * Get the index position of token in query which get failed.
105     * Position is position of any token in query for whicb parse is going on.
106     */

107    public int getIndexPosition(int position){
108       if ( index == null )
109          return position; // for parsing of tokens, if exception then position is returned.
110

111        if ( position < index.length ){
112          int pos = index[position].hashCode();
113          parseException.setCauseOfParseException(position,null,pos);
114          return pos;
115       }
116       return position;
117    }
118
119 }
120
121
Popular Tags