001: /*
002: * Copyright (c) 2007, intarsys consulting GmbH
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * - Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * - Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * - Neither the name of intarsys nor the names of its contributors may be used
015: * to endorse or promote products derived from this software without specific
016: * prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028: * POSSIBILITY OF SUCH DAMAGE.
029: */
030: /* Generated By:JavaCC: Do not edit this line. Parser.java */
031: package de.intarsys.pdf.postscript;
032:
033: public class Parser implements ParserConstants {
034: static private int[] jj_la1_0;
035:
036: static {
037: jj_la1_0();
038: }
039:
040: private static void jj_la1_0() {
041: jj_la1_0 = new int[] { 0x3cf48, 0x3cf48, };
042: }
043:
044: private java.util.Vector jj_expentries = new java.util.Vector();
045:
046: private int[] jj_expentry;
047:
048: private int jj_gen;
049:
050: JavaCharStream jj_input_stream;
051:
052: private int jj_kind = -1;
053:
054: final private int[] jj_la1 = new int[2];
055:
056: private int jj_ntk;
057:
058: public Token token;
059:
060: public Token jj_nt;
061:
062: public ParserTokenManager token_source;
063:
064: public Parser(java.io.InputStream stream) {
065: this (stream, null);
066: }
067:
068: public Parser(java.io.InputStream stream, String encoding) {
069: try {
070: jj_input_stream = new JavaCharStream(stream, encoding, 1, 1);
071: } catch (java.io.UnsupportedEncodingException e) {
072: throw new RuntimeException(e);
073: }
074: token_source = new ParserTokenManager(jj_input_stream);
075: token = new Token();
076: jj_ntk = -1;
077: jj_gen = 0;
078: for (int i = 0; i < 2; i++)
079: jj_la1[i] = -1;
080: }
081:
082: public Parser(java.io.Reader stream) {
083: jj_input_stream = new JavaCharStream(stream, 1, 1);
084: token_source = new ParserTokenManager(jj_input_stream);
085: token = new Token();
086: jj_ntk = -1;
087: jj_gen = 0;
088: for (int i = 0; i < 2; i++)
089: jj_la1[i] = -1;
090: }
091:
092: public Parser(ParserTokenManager tm) {
093: token_source = tm;
094: token = new Token();
095: jj_ntk = -1;
096: jj_gen = 0;
097: for (int i = 0; i < 2; i++)
098: jj_la1[i] = -1;
099: }
100:
101: final public void disable_tracing() {
102: }
103:
104: final public void enable_tracing() {
105: }
106:
107: public ParseException generateParseException() {
108: jj_expentries.removeAllElements();
109: boolean[] la1tokens = new boolean[18];
110: for (int i = 0; i < 18; i++) {
111: la1tokens[i] = false;
112: }
113: if (jj_kind >= 0) {
114: la1tokens[jj_kind] = true;
115: jj_kind = -1;
116: }
117: for (int i = 0; i < 2; i++) {
118: if (jj_la1[i] == jj_gen) {
119: for (int j = 0; j < 32; j++) {
120: if ((jj_la1_0[i] & (1 << j)) != 0) {
121: la1tokens[j] = true;
122: }
123: }
124: }
125: }
126: for (int i = 0; i < 18; i++) {
127: if (la1tokens[i]) {
128: jj_expentry = new int[1];
129: jj_expentry[0] = i;
130: jj_expentries.addElement(jj_expentry);
131: }
132: }
133: int[][] exptokseq = new int[jj_expentries.size()][];
134: for (int i = 0; i < jj_expentries.size(); i++) {
135: exptokseq[i] = (int[]) jj_expentries.elementAt(i);
136: }
137: return new ParseException(token, exptokseq, tokenImage);
138: }
139:
140: final public Token getNextToken() {
141: if (token.next != null) {
142: token = token.next;
143: } else {
144: token = token.next = token_source.getNextToken();
145: }
146: jj_ntk = -1;
147: jj_gen++;
148: return token;
149: }
150:
151: final public Token getToken(int index) {
152: Token t = token;
153: for (int i = 0; i < index; i++) {
154: if (t.next != null) {
155: t = t.next;
156: } else {
157: t = t.next = token_source.getNextToken();
158: }
159: }
160: return t;
161: }
162:
163: final private Token jj_consume_token(int kind)
164: throws ParseException {
165: Token oldToken;
166: if ((oldToken = token).next != null) {
167: token = token.next;
168: } else {
169: token = token.next = token_source.getNextToken();
170: }
171: jj_ntk = -1;
172: if (token.kind == kind) {
173: jj_gen++;
174: return token;
175: }
176: token = oldToken;
177: jj_kind = kind;
178: throw generateParseException();
179: }
180:
181: final private int jj_ntk() {
182: if ((jj_nt = token.next) == null) {
183: return (jj_ntk = (token.next = token_source.getNextToken()).kind);
184: } else {
185: return (jj_ntk = jj_nt.kind);
186: }
187: }
188:
189: final public void parse(Handler handler) throws ParseException {
190: Token localToken;
191: label_1: while (true) {
192: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
193: case INTEGER_LITERAL:
194: case FLOATING_POINT_LITERAL:
195: case STRING_LITERAL:
196: case IDENTIFIER:
197: case KEY_IDENTIFIER:
198: case IMMEDIATE_IDENTIFIER:
199: case LBRACE:
200: case RBRACE:
201: case LBRACKET:
202: case RBRACKET:
203: ;
204: break;
205: default:
206: jj_la1[0] = jj_gen;
207: break label_1;
208: }
209: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
210: case INTEGER_LITERAL:
211: localToken = jj_consume_token(INTEGER_LITERAL);
212: try {
213: handler.processLiteral(Integer
214: .parseInt(localToken.image));
215: } catch (NumberFormatException e) {
216: if (true) {
217: throw new ParseException(e.toString());
218: }
219: }
220: break;
221: case FLOATING_POINT_LITERAL:
222: localToken = jj_consume_token(FLOATING_POINT_LITERAL);
223: try {
224: handler.processLiteral(Double
225: .parseDouble(localToken.image));
226: } catch (NumberFormatException e) {
227: if (true) {
228: throw new ParseException(e.toString());
229: }
230: }
231: break;
232: case STRING_LITERAL:
233: localToken = jj_consume_token(STRING_LITERAL);
234: handler.processLiteral(localToken.image.substring(1,
235: localToken.image.length() - 1));
236: break;
237: case IDENTIFIER:
238: localToken = jj_consume_token(IDENTIFIER);
239: handler.processIdentifier(localToken.image);
240: break;
241: case KEY_IDENTIFIER:
242: localToken = jj_consume_token(KEY_IDENTIFIER);
243: handler.processKeyIdentifier(localToken.image
244: .substring(1, localToken.image.length()));
245: break;
246: case IMMEDIATE_IDENTIFIER:
247: localToken = jj_consume_token(IMMEDIATE_IDENTIFIER);
248: handler.processImmediateIdentifier(localToken.image
249: .substring(2, localToken.image.length()));
250: break;
251: case LBRACE:
252: jj_consume_token(LBRACE);
253: handler.processStartProcedure();
254: break;
255: case RBRACE:
256: jj_consume_token(RBRACE);
257: handler.processEndProcedure();
258: break;
259: case LBRACKET:
260: jj_consume_token(LBRACKET);
261: handler.processStartArray();
262: break;
263: case RBRACKET:
264: jj_consume_token(RBRACKET);
265: handler.processEndArray();
266: break;
267: default:
268: jj_la1[1] = jj_gen;
269: jj_consume_token(-1);
270: throw new ParseException();
271: }
272: }
273: }
274:
275: public void ReInit(java.io.InputStream stream) {
276: ReInit(stream, null);
277: }
278:
279: public void ReInit(java.io.InputStream stream, String encoding) {
280: try {
281: jj_input_stream.ReInit(stream, encoding, 1, 1);
282: } catch (java.io.UnsupportedEncodingException e) {
283: throw new RuntimeException(e);
284: }
285: token_source.ReInit(jj_input_stream);
286: token = new Token();
287: jj_ntk = -1;
288: jj_gen = 0;
289: for (int i = 0; i < 2; i++)
290: jj_la1[i] = -1;
291: }
292:
293: public void ReInit(java.io.Reader stream) {
294: jj_input_stream.ReInit(stream, 1, 1);
295: token_source.ReInit(jj_input_stream);
296: token = new Token();
297: jj_ntk = -1;
298: jj_gen = 0;
299: for (int i = 0; i < 2; i++)
300: jj_la1[i] = -1;
301: }
302:
303: public void ReInit(ParserTokenManager tm) {
304: token_source = tm;
305: token = new Token();
306: jj_ntk = -1;
307: jj_gen = 0;
308: for (int i = 0; i < 2; i++)
309: jj_la1[i] = -1;
310: }
311: }
|