| 1 |
/* Generated By:JavaCC: Do not edit this line. FormatParser.java */ |
| 2 |
package org.j_paine.formatter; |
| 3 |
|
| 4 |
class FormatParser implements FormatParserConstants { |
| 5 |
|
| 6 |
static final public int Integer() throws ParseException { |
| 7 |
Token t; |
| 8 |
t = jj_consume_token(INTEGER); |
| 9 |
{if (true) return (Integer.valueOf(t.image)).intValue();} |
| 10 |
throw new Error("Missing return statement in function"); |
| 11 |
} |
| 12 |
|
| 13 |
/* I split FormatIOElement into FormatIOElementFloat and |
| 14 |
* FormatIOElementNonFloat because a floating point edit |
| 15 |
* descriptor (F, E, D, or G) may follow a P edit descriptor |
| 16 |
* without a comma. --kgs |
| 17 |
*/ |
| 18 |
static final public FormatElement FormatIOElementFloat() throws ParseException { |
| 19 |
FormatElement fe; |
| 20 |
int w, d, m; |
| 21 |
w = d = m = -1; |
| 22 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 23 |
case F_DESC: |
| 24 |
jj_consume_token(F_DESC); |
| 25 |
w = Integer(); |
| 26 |
jj_consume_token(13); |
| 27 |
d = Integer(); |
| 28 |
fe=new FormatF(w,d); |
| 29 |
break; |
| 30 |
case D_DESC: |
| 31 |
jj_consume_token(D_DESC); |
| 32 |
w = Integer(); |
| 33 |
jj_consume_token(13); |
| 34 |
d = Integer(); |
| 35 |
fe=new FormatE(w,d); |
| 36 |
break; |
| 37 |
case E_DESC: |
| 38 |
jj_consume_token(E_DESC); |
| 39 |
w = Integer(); |
| 40 |
jj_consume_token(13); |
| 41 |
d = Integer(); |
| 42 |
fe=new FormatE(w,d); |
| 43 |
break; |
| 44 |
case G_DESC: |
| 45 |
jj_consume_token(G_DESC); |
| 46 |
w = Integer(); |
| 47 |
jj_consume_token(13); |
| 48 |
d = Integer(); |
| 49 |
fe=new FormatE(w,d); |
| 50 |
break; |
| 51 |
default: |
| 52 |
jj_la1[0] = jj_gen; |
| 53 |
jj_consume_token(-1); |
| 54 |
throw new ParseException(); |
| 55 |
} |
| 56 |
{if (true) return fe;} |
| 57 |
throw new Error("Missing return statement in function"); |
| 58 |
} |
| 59 |
|
| 60 |
static final public FormatElement FormatIOElementNonFloat() throws ParseException { |
| 61 |
FormatElement fe; |
| 62 |
int w, d, m; |
| 63 |
w = d = m = -1; |
| 64 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 65 |
case A_DESC: |
| 66 |
jj_consume_token(A_DESC); |
| 67 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 68 |
case INTEGER: |
| 69 |
w = Integer(); |
| 70 |
break; |
| 71 |
default: |
| 72 |
jj_la1[1] = jj_gen; |
| 73 |
; |
| 74 |
} |
| 75 |
fe=new FormatA(w); |
| 76 |
break; |
| 77 |
case I_DESC: |
| 78 |
jj_consume_token(I_DESC); |
| 79 |
w = Integer(); |
| 80 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 81 |
case 13: |
| 82 |
jj_consume_token(13); |
| 83 |
m = Integer(); |
| 84 |
break; |
| 85 |
default: |
| 86 |
jj_la1[2] = jj_gen; |
| 87 |
; |
| 88 |
} |
| 89 |
fe=new FormatI(w); |
| 90 |
break; |
| 91 |
case L_DESC: |
| 92 |
jj_consume_token(L_DESC); |
| 93 |
w = Integer(); |
| 94 |
fe=new FormatL(w); |
| 95 |
break; |
| 96 |
default: |
| 97 |
jj_la1[3] = jj_gen; |
| 98 |
jj_consume_token(-1); |
| 99 |
throw new ParseException(); |
| 100 |
} |
| 101 |
{if (true) return fe;} |
| 102 |
throw new Error("Missing return statement in function"); |
| 103 |
} |
| 104 |
|
| 105 |
// This represents a format element that transfers one |
| 106 |
// data item. |
| 107 |
static final public FormatElement FormatNonIOElement() throws ParseException { |
| 108 |
jj_consume_token(X_DESC); |
| 109 |
{if (true) return new FormatX();} |
| 110 |
throw new Error("Missing return statement in function"); |
| 111 |
} |
| 112 |
|
| 113 |
// This represents a format element that doesn't transfer |
| 114 |
// any data items. |
| 115 |
static final public FormatElement FormatElement() throws ParseException { |
| 116 |
FormatElement fe; |
| 117 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 118 |
case F_DESC: |
| 119 |
case D_DESC: |
| 120 |
case E_DESC: |
| 121 |
case G_DESC: |
| 122 |
fe = FormatIOElementFloat(); |
| 123 |
break; |
| 124 |
case A_DESC: |
| 125 |
case I_DESC: |
| 126 |
case L_DESC: |
| 127 |
fe = FormatIOElementNonFloat(); |
| 128 |
break; |
| 129 |
case X_DESC: |
| 130 |
fe = FormatNonIOElement(); |
| 131 |
break; |
| 132 |
case P_DESC: |
| 133 |
fe = FormatScale(); |
| 134 |
break; |
| 135 |
default: |
| 136 |
jj_la1[4] = jj_gen; |
| 137 |
jj_consume_token(-1); |
| 138 |
throw new ParseException(); |
| 139 |
} |
| 140 |
{if (true) return fe;} |
| 141 |
throw new Error("Missing return statement in function"); |
| 142 |
} |
| 143 |
|
| 144 |
static final public FormatElement FormatScale() throws ParseException { |
| 145 |
FormatElement fe = null; |
| 146 |
int r=1; |
| 147 |
jj_consume_token(P_DESC); |
| 148 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 149 |
case INTEGER: |
| 150 |
case F_DESC: |
| 151 |
case D_DESC: |
| 152 |
case E_DESC: |
| 153 |
case G_DESC: |
| 154 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 155 |
case INTEGER: |
| 156 |
r = Integer(); |
| 157 |
break; |
| 158 |
default: |
| 159 |
jj_la1[5] = jj_gen; |
| 160 |
; |
| 161 |
} |
| 162 |
fe = FormatIOElementFloat(); |
| 163 |
break; |
| 164 |
default: |
| 165 |
jj_la1[6] = jj_gen; |
| 166 |
; |
| 167 |
} |
| 168 |
{if (true) return new FormatP(r, fe);} |
| 169 |
throw new Error("Missing return statement in function"); |
| 170 |
} |
| 171 |
|
| 172 |
static final public FormatSlash FormatSlash() throws ParseException { |
| 173 |
jj_consume_token(14); |
| 174 |
{if (true) return new FormatSlash();} |
| 175 |
throw new Error("Missing return statement in function"); |
| 176 |
} |
| 177 |
|
| 178 |
// These are a special case. Unlike other format elements, |
| 179 |
// Fortran permits several slashes to be concatenated without |
| 180 |
// commas to separate them, and you can't use a repetition |
| 181 |
// factor on them. |
| 182 |
static final public FormatString FormatString() throws ParseException { |
| 183 |
Token t; |
| 184 |
String s; |
| 185 |
t = jj_consume_token(STRING); |
| 186 |
s = t.image; |
| 187 |
s = s.substring(1,s.length()-1); // Remove the quotes. |
| 188 |
{if (true) return new FormatString(s);} |
| 189 |
throw new Error("Missing return statement in function"); |
| 190 |
} |
| 191 |
|
| 192 |
// Another special case that can't be repeated, and can be |
| 193 |
// concatenated to other elements without commas. |
| 194 |
static final public void OptionalFormatSlashesOrStrings(Format f) throws ParseException { |
| 195 |
FormatUniv fs; |
| 196 |
label_1: |
| 197 |
while (true) { |
| 198 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 199 |
case STRING: |
| 200 |
case 14: |
| 201 |
; |
| 202 |
break; |
| 203 |
default: |
| 204 |
jj_la1[7] = jj_gen; |
| 205 |
break label_1; |
| 206 |
} |
| 207 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 208 |
case 14: |
| 209 |
fs = FormatSlash(); |
| 210 |
break; |
| 211 |
case STRING: |
| 212 |
fs = FormatString(); |
| 213 |
break; |
| 214 |
default: |
| 215 |
jj_la1[8] = jj_gen; |
| 216 |
jj_consume_token(-1); |
| 217 |
throw new ParseException(); |
| 218 |
} |
| 219 |
f.addElement(fs); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
static final public FormatRepeatedItem FormatRepeatedItem() throws ParseException { |
| 224 |
int r=1; |
| 225 |
FormatUniv fu; |
| 226 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 227 |
case INTEGER: |
| 228 |
r = Integer(); |
| 229 |
break; |
| 230 |
default: |
| 231 |
jj_la1[9] = jj_gen; |
| 232 |
; |
| 233 |
} |
| 234 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 235 |
case 15: |
| 236 |
jj_consume_token(15); |
| 237 |
fu = Format(); |
| 238 |
jj_consume_token(16); |
| 239 |
break; |
| 240 |
case A_DESC: |
| 241 |
case P_DESC: |
| 242 |
case X_DESC: |
| 243 |
case I_DESC: |
| 244 |
case F_DESC: |
| 245 |
case D_DESC: |
| 246 |
case E_DESC: |
| 247 |
case G_DESC: |
| 248 |
case L_DESC: |
| 249 |
fu = FormatElement(); |
| 250 |
break; |
| 251 |
default: |
| 252 |
jj_la1[10] = jj_gen; |
| 253 |
jj_consume_token(-1); |
| 254 |
throw new ParseException(); |
| 255 |
} |
| 256 |
/* here we check whether the parsed format element is a P edit |
| 257 |
* descriptor. in that case, it may have parsed a floating point |
| 258 |
* edit descriptor along with it (if it followed without a comma) |
| 259 |
* so return that element here. --kgs |
| 260 |
*/ |
| 261 |
|
| 262 |
if(fu instanceof FormatP) { |
| 263 |
FormatRepeatedItem ritem; |
| 264 |
|
| 265 |
ritem = ((FormatP)fu).getRepeatedItem(); |
| 266 |
|
| 267 |
if(ritem != null) |
| 268 |
{if (true) return ritem;} |
| 269 |
else |
| 270 |
{if (true) return new FormatRepeatedItem( r, fu );} |
| 271 |
} |
| 272 |
else |
| 273 |
{if (true) return new FormatRepeatedItem( r, fu );} |
| 274 |
throw new Error("Missing return statement in function"); |
| 275 |
} |
| 276 |
|
| 277 |
static final public void FormatGroup(Format f) throws ParseException { |
| 278 |
FormatRepeatedItem fri; |
| 279 |
OptionalFormatSlashesOrStrings(f); |
| 280 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 281 |
case INTEGER: |
| 282 |
case A_DESC: |
| 283 |
case P_DESC: |
| 284 |
case X_DESC: |
| 285 |
case I_DESC: |
| 286 |
case F_DESC: |
| 287 |
case D_DESC: |
| 288 |
case E_DESC: |
| 289 |
case G_DESC: |
| 290 |
case L_DESC: |
| 291 |
case 15: |
| 292 |
fri = FormatRepeatedItem(); |
| 293 |
if(fri != null) f.addElement(fri); |
| 294 |
OptionalFormatSlashesOrStrings(f); |
| 295 |
break; |
| 296 |
default: |
| 297 |
jj_la1[11] = jj_gen; |
| 298 |
; |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
// This rather messy syntax allows us to have slashes and/or |
| 303 |
// strings either side of a format element or repeated group |
| 304 |
// without needing to separate them from each other or the element |
| 305 |
// with commas. |
| 306 |
// It also means that we can have empty format groups and format |
| 307 |
// groups that don't transfer any data elements. So for example, |
| 308 |
// the format ,/, is valid under this grammar. |
| 309 |
static final public Format Format() throws ParseException { |
| 310 |
FormatRepeatedItem fri; |
| 311 |
Format f = new Format(); |
| 312 |
FormatGroup(f); |
| 313 |
label_2: |
| 314 |
while (true) { |
| 315 |
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
| 316 |
case 17: |
| 317 |
; |
| 318 |
break; |
| 319 |
default: |
| 320 |
jj_la1[12] = jj_gen; |
| 321 |
break label_2; |
| 322 |
} |
| 323 |
jj_consume_token(17); |
| 324 |
FormatGroup(f); |
| 325 |
} |
| 326 |
{if (true) return f;} |
| 327 |
throw new Error("Missing return statement in function"); |
| 328 |
} |
| 329 |
|
| 330 |
static private boolean jj_initialized_once = false; |
| 331 |
static public FormatParserTokenManager token_source; |
| 332 |
static SimpleCharStream jj_input_stream; |
| 333 |
static public Token token, jj_nt; |
| 334 |
static private int jj_ntk; |
| 335 |
static private int jj_gen; |
| 336 |
static final private int[] jj_la1 = new int[13]; |
| 337 |
static private int[] jj_la1_0; |
| 338 |
static { |
| 339 |
jj_la1_0(); |
| 340 |
} |
| 341 |
private static void jj_la1_0() { |
| 342 |
jj_la1_0 = new int[] {0xf00,0x4,0x2000,0x1090,0x1ff0,0x4,0xf04,0x4008,0x4008,0x4,0x9ff0,0x9ff4,0x20000,}; |
| 343 |
} |
| 344 |
|
| 345 |
public FormatParser(java.io.InputStream stream) { |
| 346 |
this(stream, null); |
| 347 |
} |
| 348 |
public FormatParser(java.io.InputStream stream, String encoding) { |
| 349 |
if (jj_initialized_once) { |
| 350 |
System.out.println("ERROR: Second call to constructor of static parser. You must"); |
| 351 |
System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); |
| 352 |
System.out.println(" during parser generation."); |
| 353 |
throw new Error(); |
| 354 |
} |
| 355 |
jj_initialized_once = true; |
| 356 |
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } |
| 357 |
token_source = new FormatParserTokenManager(jj_input_stream); |
| 358 |
token = new Token(); |
| 359 |
jj_ntk = -1; |
| 360 |
jj_gen = 0; |
| 361 |
for (int i = 0; i < 13; i++) jj_la1[i] = -1; |
| 362 |
} |
| 363 |
|
| 364 |
static public void ReInit(java.io.InputStream stream) { |
| 365 |
ReInit(stream, null); |
| 366 |
} |
| 367 |
static public void ReInit(java.io.InputStream stream, String encoding) { |
| 368 |
try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } |
| 369 |
token_source.ReInit(jj_input_stream); |
| 370 |
token = new Token(); |
| 371 |
jj_ntk = -1; |
| 372 |
jj_gen = 0; |
| 373 |
for (int i = 0; i < 13; i++) jj_la1[i] = -1; |
| 374 |
} |
| 375 |
|
| 376 |
public FormatParser(java.io.Reader stream) { |
| 377 |
if (jj_initialized_once) { |
| 378 |
System.out.println("ERROR: Second call to constructor of static parser. You must"); |
| 379 |
System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); |
| 380 |
System.out.println(" during parser generation."); |
| 381 |
throw new Error(); |
| 382 |
} |
| 383 |
jj_initialized_once = true; |
| 384 |
jj_input_stream = new SimpleCharStream(stream, 1, 1); |
| 385 |
token_source = new FormatParserTokenManager(jj_input_stream); |
| 386 |
token = new Token(); |
| 387 |
jj_ntk = -1; |
| 388 |
jj_gen = 0; |
| 389 |
for (int i = 0; i < 13; i++) jj_la1[i] = -1; |
| 390 |
} |
| 391 |
|
| 392 |
static public void ReInit(java.io.Reader stream) { |
| 393 |
jj_input_stream.ReInit(stream, 1, 1); |
| 394 |
token_source.ReInit(jj_input_stream); |
| 395 |
token = new Token(); |
| 396 |
jj_ntk = -1; |
| 397 |
jj_gen = 0; |
| 398 |
for (int i = 0; i < 13; i++) jj_la1[i] = -1; |
| 399 |
} |
| 400 |
|
| 401 |
public FormatParser(FormatParserTokenManager tm) { |
| 402 |
if (jj_initialized_once) { |
| 403 |
System.out.println("ERROR: Second call to constructor of static parser. You must"); |
| 404 |
System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); |
| 405 |
System.out.println(" during parser generation."); |
| 406 |
throw new Error(); |
| 407 |
} |
| 408 |
jj_initialized_once = true; |
| 409 |
token_source = tm; |
| 410 |
token = new Token(); |
| 411 |
jj_ntk = -1; |
| 412 |
jj_gen = 0; |
| 413 |
for (int i = 0; i < 13; i++) jj_la1[i] = -1; |
| 414 |
} |
| 415 |
|
| 416 |
public void ReInit(FormatParserTokenManager tm) { |
| 417 |
token_source = tm; |
| 418 |
token = new Token(); |
| 419 |
jj_ntk = -1; |
| 420 |
jj_gen = 0; |
| 421 |
for (int i = 0; i < 13; i++) jj_la1[i] = -1; |
| 422 |
} |
| 423 |
|
| 424 |
static final private Token jj_consume_token(int kind) throws ParseException { |
| 425 |
Token oldToken; |
| 426 |
if ((oldToken = token).next != null) token = token.next; |
| 427 |
else token = token.next = token_source.getNextToken(); |
| 428 |
jj_ntk = -1; |
| 429 |
if (token.kind == kind) { |
| 430 |
jj_gen++; |
| 431 |
return token; |
| 432 |
} |
| 433 |
token = oldToken; |
| 434 |
jj_kind = kind; |
| 435 |
throw generateParseException(); |
| 436 |
} |
| 437 |
|
| 438 |
static final public Token getNextToken() { |
| 439 |
if (token.next != null) token = token.next; |
| 440 |
else token = token.next = token_source.getNextToken(); |
| 441 |
jj_ntk = -1; |
| 442 |
jj_gen++; |
| 443 |
return token; |
| 444 |
} |
| 445 |
|
| 446 |
static final public Token getToken(int index) { |
| 447 |
Token t = token; |
| 448 |
for (int i = 0; i < index; i++) { |
| 449 |
if (t.next != null) t = t.next; |
| 450 |
else t = t.next = token_source.getNextToken(); |
| 451 |
} |
| 452 |
return t; |
| 453 |
} |
| 454 |
|
| 455 |
static final private int jj_ntk() { |
| 456 |
if ((jj_nt=token.next) == null) |
| 457 |
return (jj_ntk = (token.next=token_source.getNextToken()).kind); |
| 458 |
else |
| 459 |
return (jj_ntk = jj_nt.kind); |
| 460 |
} |
| 461 |
|
| 462 |
static private java.util.Vector jj_expentries = new java.util.Vector(); |
| 463 |
static private int[] jj_expentry; |
| 464 |
static private int jj_kind = -1; |
| 465 |
|
| 466 |
static public ParseException generateParseException() { |
| 467 |
jj_expentries.removeAllElements(); |
| 468 |
boolean[] la1tokens = new boolean[18]; |
| 469 |
for (int i = 0; i < 18; i++) { |
| 470 |
la1tokens[i] = false; |
| 471 |
} |
| 472 |
if (jj_kind >= 0) { |
| 473 |
la1tokens[jj_kind] = true; |
| 474 |
jj_kind = -1; |
| 475 |
} |
| 476 |
for (int i = 0; i < 13; i++) { |
| 477 |
if (jj_la1[i] == jj_gen) { |
| 478 |
for (int j = 0; j < 32; j++) { |
| 479 |
if ((jj_la1_0[i] & (1<<j)) != 0) { |
| 480 |
la1tokens[j] = true; |
| 481 |
} |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
for (int i = 0; i < 18; i++) { |
| 486 |
if (la1tokens[i]) { |
| 487 |
jj_expentry = new int[1]; |
| 488 |
jj_expentry[0] = i; |
| 489 |
jj_expentries.addElement(jj_expentry); |
| 490 |
} |
| 491 |
} |
| 492 |
int[][] exptokseq = new int[jj_expentries.size()][]; |
| 493 |
for (int i = 0; i < jj_expentries.size(); i++) { |
| 494 |
exptokseq[i] = (int[])jj_expentries.elementAt(i); |
| 495 |
} |
| 496 |
return new ParseException(token, exptokseq, tokenImage); |
| 497 |
} |
| 498 |
|
| 499 |
static final public void enable_tracing() { |
| 500 |
} |
| 501 |
|
| 502 |
static final public void disable_tracing() { |
| 503 |
} |
| 504 |
|
| 505 |
} |