1
2
3
4
5
6
7
8 package cz.cuni.amis.pogamut.ut3.communication.messages.gbinfomessages;
9
10 import java.io.Reader;
11
12
13 import java.util.*;
14 import javax.vecmath.*;
15 import cz.cuni.amis.pogamut.base.communication.translator.*;
16 import cz.cuni.amis.pogamut.base.communication.translator.event.*;
17 import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.*;
18 import cz.cuni.amis.pogamut.base.communication.parser.*;
19 import cz.cuni.amis.pogamut.base.communication.parser.exception.*;
20 import cz.cuni.amis.pogamut.base.communication.parser.impl.yylex.*;
21 import cz.cuni.amis.pogamut.base.communication.messages.*;
22 import cz.cuni.amis.pogamut.base.communication.worldview.*;
23 import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
24 import cz.cuni.amis.pogamut.base.communication.worldview.object.*;
25 import cz.cuni.amis.pogamut.base3d.worldview.object.*;
26 import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;
27 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
28 import cz.cuni.amis.pogamut.ut2004.communication.parser.*;
29 import cz.cuni.amis.pogamut.ut2004.communication.messages.*;
30 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;
31 import cz.cuni.amis.pogamut.ut2004.communication.worldview.objects.*;
32 import cz.cuni.amis.pogamut.ut2004.utils.UnrealUtils;
33 import java.lang.reflect.Method;
34 import cz.cuni.amis.utils.exception.*;
35 import cz.cuni.amis.pogamut.multi.agent.*;
36
37
38
39
40
41
42
43
44
45
46
47 public class Yylex implements IUT2004Yylex {
48
49
50 public static final int YYEOF = -1;
51
52
53 private static final int ZZ_BUFFERSIZE = 16384;
54
55
56 public static final int MSG_BEG = 8;
57 public static final int UNPROCESSED_MESSAGE = 2;
58 public static final int YYINITIAL = 0;
59 public static final int MSG_ALIVE = 6;
60 public static final int MSG_EMP = 4;
61
62
63
64
65
66
67
68 private static final int ZZ_LEXSTATE[] = {
69 0, 0, 1, 1, 2, 2, 3, 3, 4, 4
70 };
71
72
73
74
75 private static final String ZZ_CMAP_PACKED =
76 "\10\0\2\3\1\5\2\0\1\4\22\0\1\23\13\0\1\0\1\7"+
77 "\1\6\1\0\12\2\7\0\1\27\1\33\2\1\1\24\1\15\1\34"+
78 "\1\1\1\31\2\1\1\30\1\25\2\1\1\26\3\1\1\11\1\40"+
79 "\1\32\4\1\4\0\1\0\1\0\1\16\2\1\1\42\1\14\1\15"+
80 "\2\1\1\36\2\1\1\17\1\37\1\1\1\22\1\41\1\1\1\12"+
81 "\1\20\1\21\1\13\5\1\1\35\1\0\1\10\uff82\0";
82
83
84
85
86 private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
87
88
89
90
91 private static final int [] ZZ_ACTION = zzUnpackAction();
92
93 private static final String ZZ_ACTION_PACKED_0 =
94 "\5\1\1\2\1\1\2\3\3\1\3\4\3\5\4\6"+
95 "\4\7\1\10\3\1\4\0\1\11\1\1\1\12\4\0"+
96 "\1\1\1\13\3\0\1\14\16\0\1\15\1\0\1\16"+
97 "\14\0\1\17";
98
99 private static int [] zzUnpackAction() {
100 int [] result = new int[77];
101 int offset = 0;
102 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
103 return result;
104 }
105
106 private static int zzUnpackAction(String packed, int offset, int [] result) {
107 int i = 0;
108 int j = offset;
109 int l = packed.length();
110 while (i < l) {
111 int count = packed.charAt(i++);
112 int value = packed.charAt(i++);
113 do result[j++] = value; while (--count > 0);
114 }
115 return j;
116 }
117
118
119
120
121
122 private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
123
124 private static final String ZZ_ROWMAP_PACKED_0 =
125 "\0\0\0\43\0\106\0\151\0\214\0\257\0\322\0\257"+
126 "\0\365\0\u0118\0\u013b\0\u015e\0\257\0\322\0\u0181\0\257"+
127 "\0\322\0\365\0\257\0\322\0\365\0\u01a4\0\257\0\322"+
128 "\0\365\0\u01c7\0\257\0\u01ea\0\u020d\0\u0230\0\u0253\0\u0276"+
129 "\0\u0299\0\u02bc\0\322\0\u02df\0\322\0\u0302\0\u0325\0\u0348"+
130 "\0\u036b\0\u038e\0\257\0\u03b1\0\u03d4\0\u03f7\0\322\0\u041a"+
131 "\0\u043d\0\u0460\0\u0483\0\u04a6\0\u04c9\0\u04ec\0\u050f\0\u0532"+
132 "\0\u0555\0\u0578\0\u059b\0\u05be\0\u05e1\0\257\0\u0604\0\257"+
133 "\0\u0627\0\u064a\0\u066d\0\u0690\0\u06b3\0\u06d6\0\u06f9\0\u071c"+
134 "\0\u073f\0\u0762\0\u0785\0\u07a8\0\257";
135
136 private static int [] zzUnpackRowMap() {
137 int [] result = new int[77];
138 int offset = 0;
139 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
140 return result;
141 }
142
143 private static int zzUnpackRowMap(String packed, int offset, int [] result) {
144 int i = 0;
145 int j = offset;
146 int l = packed.length();
147 while (i < l) {
148 int high = packed.charAt(i++) << 16;
149 result[j++] = high | packed.charAt(i++);
150 }
151 return j;
152 }
153
154
155
156
157 private static final int [] ZZ_TRANS = zzUnpackTrans();
158
159 private static final String ZZ_TRANS_PACKED_0 =
160 "\1\6\2\7\1\10\1\11\1\10\3\6\12\7\1\10"+
161 "\1\12\2\7\1\13\3\7\1\14\1\7\1\6\5\7"+
162 "\1\15\2\16\1\10\1\11\1\10\3\15\12\16\1\10"+
163 "\11\16\1\17\5\16\1\20\2\21\1\20\1\22\1\10"+
164 "\3\20\12\21\1\20\11\21\1\20\5\21\1\23\2\24"+
165 "\1\23\1\25\1\10\3\23\12\24\1\23\11\24\1\26"+
166 "\5\24\1\27\2\30\1\27\1\31\1\10\3\27\12\30"+
167 "\1\27\11\30\1\32\5\30\44\0\2\7\6\0\12\7"+
168 "\1\0\11\7\1\0\5\7\5\0\1\33\36\0\2\7"+
169 "\6\0\12\7\1\0\1\7\1\34\7\7\1\0\5\7"+
170 "\1\0\2\7\6\0\12\7\1\0\4\7\1\35\4\7"+
171 "\1\0\5\7\1\0\2\7\6\0\12\7\1\0\1\36"+
172 "\10\7\1\0\5\7\10\37\1\0\32\37\11\0\1\40"+
173 "\42\0\1\41\20\0\1\42\11\0\2\7\6\0\12\7"+
174 "\1\0\2\7\1\43\6\7\1\0\5\7\1\0\2\7"+
175 "\6\0\12\7\1\0\5\7\1\44\3\7\1\0\5\7"+
176 "\1\0\2\7\6\0\12\7\1\0\10\7\1\45\1\0"+
177 "\5\7\10\37\1\0\12\37\1\46\17\37\36\0\1\47"+
178 "\42\0\1\50\42\0\1\51\5\0\2\7\6\0\12\7"+
179 "\1\0\6\7\1\52\2\7\1\0\5\7\10\46\1\53"+
180 "\32\46\37\0\1\54\42\0\1\55\23\0\1\56\23\0"+
181 "\2\7\6\0\12\7\1\0\1\57\10\7\1\0\5\7"+
182 "\14\0\1\60\42\0\1\61\66\0\1\62\25\0\1\63"+
183 "\42\0\1\64\60\0\1\65\3\0\1\66\3\0\1\67"+
184 "\1\70\35\0\1\71\3\0\1\72\1\73\75\0\1\74"+
185 "\2\0\1\66\3\0\1\75\1\0\1\76\34\0\1\75"+
186 "\42\0\1\66\3\0\1\67\36\0\1\71\3\0\1\77"+
187 "\1\0\1\100\34\0\1\77\42\0\1\71\3\0\1\72"+
188 "\52\0\1\101\26\0\1\75\5\0\1\76\34\0\1\77"+
189 "\5\0\1\100\53\0\1\102\35\0\1\103\51\0\1\104"+
190 "\30\0\1\105\3\0\1\106\3\0\1\105\33\0\1\107"+
191 "\46\0\1\110\37\0\1\111\46\0\1\112\37\0\1\113"+
192 "\46\0\1\114\32\0\1\115\46\0\1\113\5\0\1\113"+
193 "\20\0";
194
195 private static int [] zzUnpackTrans() {
196 int [] result = new int[1995];
197 int offset = 0;
198 offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
199 return result;
200 }
201
202 private static int zzUnpackTrans(String packed, int offset, int [] result) {
203 int i = 0;
204 int j = offset;
205 int l = packed.length();
206 while (i < l) {
207 int count = packed.charAt(i++);
208 int value = packed.charAt(i++);
209 value--;
210 do result[j++] = value; while (--count > 0);
211 }
212 return j;
213 }
214
215
216
217 private static final int ZZ_UNKNOWN_ERROR = 0;
218 private static final int ZZ_NO_MATCH = 1;
219 private static final int ZZ_PUSHBACK_2BIG = 2;
220
221
222 private static final String ZZ_ERROR_MSG[] = {
223 "Unkown internal scanner error",
224 "Error: could not match input",
225 "Error: pushback value was too large"
226 };
227
228
229
230
231 private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
232
233 private static final String ZZ_ATTRIBUTE_PACKED_0 =
234 "\5\1\1\11\1\1\1\11\4\1\1\11\2\1\1\11"+
235 "\2\1\1\11\3\1\1\11\3\1\1\11\3\1\4\0"+
236 "\3\1\4\0\1\1\1\11\3\0\1\1\16\0\1\11"+
237 "\1\0\1\11\14\0\1\11";
238
239 private static int [] zzUnpackAttribute() {
240 int [] result = new int[77];
241 int offset = 0;
242 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
243 return result;
244 }
245
246 private static int zzUnpackAttribute(String packed, int offset, int [] result) {
247 int i = 0;
248 int j = offset;
249 int l = packed.length();
250 while (i < l) {
251 int count = packed.charAt(i++);
252 int value = packed.charAt(i++);
253 do result[j++] = value; while (--count > 0);
254 }
255 return j;
256 }
257
258
259 private java.io.Reader zzReader;
260
261
262 private int zzState;
263
264
265 private int zzLexicalState = YYINITIAL;
266
267
268
269 private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
270
271
272 private int zzMarkedPos;
273
274
275 private int zzCurrentPos;
276
277
278 private int zzStartRead;
279
280
281
282 private int zzEndRead;
283
284
285 private int yyline;
286
287
288 private int yychar;
289
290
291
292
293
294 private int yycolumn;
295
296
297
298
299 private boolean zzAtBOL = true;
300
301
302 private boolean zzAtEOF;
303
304
305 private boolean zzEOFDone;
306
307
308
309 public static final String DELIMITERS_STANDARD = " {}";
310 public static final String DELIMITERS_EXTENDED = " {},";
311
312
313 protected Map<Integer, Double> mapIntIDDouble = null;
314
315
316 protected Map<Integer, Double> mapIntDouble = null;
317
318
319 protected UnrealIdTranslator translator = null;
320
321
322 protected ItemTranslator itemTranslator = null;
323
324
325 protected IYylexObserver observer = null;
326
327
328 protected ItemTypeTranslator itemTypeTranslator;
329
330
331 protected double ut2004Time = 0;
332
333 public Yylex(){
334 }
335
336 public void setReader(Reader reader) {
337 yyreset(reader);
338 }
339
340 public void close() throws java.io.IOException {
341 yyclose();
342 }
343
344 public void setItemTranslator(ItemTranslator translator) {
345 this.itemTranslator = translator;
346 }
347
348 @Override
349 public void setItemTypeTranslator(ItemTypeTranslator translator) {
350 this.itemTypeTranslator = translator;
351 }
352
353 public void setObserver(IYylexObserver observer) {
354 this.observer = observer;
355 }
356
357
358
359
360
361 public void setTranslator(UnrealIdTranslator translator) {
362 this.translator = translator;
363 }
364
365 public void setTime(IWorldObjectUpdatedEvent obj, double time) {
366
367 setPropertyByReflection( obj, "SimTime", long.class, (long)(ut2004Time*1000) );
368 }
369
370 public void setTime(IWorldEvent obj, double time) {
371
372 setPropertyByReflection( obj, "SimTime", long.class, (long)(ut2004Time*1000) );
373 }
374
375
376
377
378
379
380
381
382
383
384
385 protected <T> void setPropertyByReflection( Object object, String propertyName, Class<T> valueType, T value ) {
386 try {
387 Method m = null;
388
389 Class<?> ancestorClass = object.getClass();
390 Class<?>[] argumentTypes = new Class[]{valueType};
391 String setterName = "set"+propertyName.substring( 0, 1 ).toUpperCase()+propertyName.substring( 1 );
392 while ( m == null ) {
393 try {
394 m = ancestorClass.getDeclaredMethod( setterName, argumentTypes );
395 } catch ( NoSuchMethodException e ) {
396 ancestorClass = ancestorClass.getSuperclass();
397 if ( ancestorClass == null ) {
398 throw e;
399 }
400 }
401 }
402 m.setAccessible( true );
403 m.invoke( object, value );
404 } catch (Exception e) {
405 exceptionOccured(e, "Can't set "+propertyName+" to message " + object.getClass() );
406 }
407 }
408
409
410
411
412
413
414
415
416
417
418 protected void exceptionOccured(Exception e, String info) {
419 IYylexObserver currentObserver = this.observer;
420 if (currentObserver != null) {
421 currentObserver.exception(e, info != null ? info : "--empty info--");
422 } else {
423 System.out.println("Yylex exception: " + info);
424 if (e != null) e.printStackTrace();
425 }
426 }
427
428
429
430
431 protected void warning(String info) {
432 IYylexObserver currentObserver = this.observer;
433 if (currentObserver != null) {
434 currentObserver.warning(info != null ? info : "--empty warning--");
435 } else {
436 System.out.println("Yylex warning: " + info);
437 }
438 }
439
440
441
442
443
444
445
446
447
448
449
450 protected InfoMessage tryParsingUnprocessedMessage(String messageName){
451 return null;
452 }
453
454
455
456
457
458
459
460
461
462
463
464
465 protected boolean tryParsingUnprocessedMessageParameter(String paramName, String wholeParamText){
466 return false;
467 }
468
469
470
471
472
473
474
475
476
477 protected String getToken(String text, String delimiters, int num) {
478 StringTokenizer st = new StringTokenizer(text, delimiters);
479 while (num-- > 0 && st.hasMoreTokens()) {
480 st.nextToken();
481 }
482 try {
483 return st.nextToken();
484 } catch (Exception e) {
485 exceptionOccured(e, "Can't get " + num + "-th token from text '"+text+"' using delimiters '"+delimiters+"'.");
486 return null;
487 }
488 }
489
490
491
492
493
494
495
496
497 protected String getToken(String text, int num) {
498 return getToken(text, DELIMITERS_STANDARD, num);
499 }
500
501
502
503
504
505
506
507
508
509 protected int intValue( String txt ) {
510 if (txt == null || txt.toLowerCase().equals("none")) return UnrealUtils.iNT_NONE;
511 try {
512 return Integer.parseInt(getToken(txt, 1));
513 } catch (NullPointerException e) {
514 warning("Can't get int token from text '"+txt+"'.");
515 return -1;
516 } catch (NumberFormatException e) {
517 exceptionOccured(e, "Wrong int number format in '"+txt+".");
518 return -1;
519 } catch (Exception e) {
520 exceptionOccured(e, "Can't get int token from text '"+txt+"'.");
521 return -1;
522 }
523 }
524
525
526
527
528
529
530
531
532
533 protected long longValue( String txt ) {
534 if (txt == null || txt.toLowerCase().equals("none")) return UnrealUtils.lONG_NONE;
535 try {
536 return Long.parseLong(getToken(txt, 1));
537 } catch (NullPointerException e) {
538 warning("Can't get long token from text '"+txt+"'.");
539 return -1;
540 } catch (NumberFormatException e) {
541 exceptionOccured(e, "Wrong long number format in '"+txt+".");
542 return -1;
543 } catch (Exception e) {
544 exceptionOccured(e, "Can't get long token from text '"+txt+"'.");
545 return -1;
546 }
547 }
548
549
550
551
552
553
554
555
556
557 protected Integer integerValue( String txt ) {
558 if (txt == null || txt.toLowerCase().equals("none")) return UnrealUtils.INT_NONE;
559 try {
560 return Integer.parseInt(getToken(txt, 1));
561 } catch (NullPointerException e) {
562 warning("Can't get int token from text '"+txt+"'.");
563 return null;
564 } catch (NumberFormatException e) {
565 exceptionOccured(e, "Wrong int number format in '"+txt+".");
566 return null;
567 } catch (Exception e) {
568 exceptionOccured(e, "Can't get int token from text '"+txt+"'.");
569 return null;
570 }
571 }
572
573
574
575
576
577
578
579
580
581
582 protected double doubleValue(String txt) {
583 if (txt == null || txt.toLowerCase().equals("none")) return UnrealUtils.dOUBLE_NONE;
584 try {
585 return Double.parseDouble(getToken(txt, 1));
586 } catch (NullPointerException e) {
587 warning("Can't get double token from text '"+txt+"'.");
588 return -1;
589 } catch (NumberFormatException e) {
590 exceptionOccured(e, "Wrong double number format in '"+txt+".");
591 return -1;
592 } catch (Exception e) {
593 exceptionOccured(e, "Can't get double token from text '"+txt+"'.");
594 return -1;
595 }
596 }
597
598
599
600
601
602
603
604
605
606 protected float floatValue(String txt) {
607 if (txt == null || txt.toLowerCase().equals("none")) return UnrealUtils.fLOAT_NONE;
608 try {
609 return Float.parseFloat(getToken(txt, 1));
610 } catch (NullPointerException e) {
611 warning("Can't get float token from text '"+txt+"'.");
612 return -1;
613 } catch (NumberFormatException e) {
614 exceptionOccured(e, "Wrong float number format in '"+txt+".");
615 return -1;
616 } catch (Exception e) {
617 exceptionOccured(e, "Can't get float token from text '"+txt+"'.");
618 return -1;
619 }
620 }
621
622
623
624
625
626
627
628
629 protected double[] getTriple( String txt ) {
630 StringTokenizer st = new StringTokenizer(txt, DELIMITERS_EXTENDED);
631
632 int num = 1;
633 while (num-- > 0 && st.hasMoreTokens()) {
634 st.nextToken();
635 }
636
637
638 try {
639 double t1,t2,t3;
640 t1 = new Double(st.nextToken()).doubleValue();
641 t2 = new Double(st.nextToken()).doubleValue();
642 t3 = new Double(st.nextToken()).doubleValue();
643 return new double[]{t1,t2,t3};
644 } catch (NumberFormatException e) {
645 exceptionOccured(e, "Wrong double number format in '"+txt+".");
646 return null;
647 } catch (Exception e) {
648 exceptionOccured(e, "Can't get triple from text '"+txt+"'.");
649 return null;
650 }
651 }
652
653
654
655
656
657
658
659 protected Location locationValue(String txt) {
660 if (txt == null || txt.toLowerCase().equals("none")) return Location.NONE;
661 double[] triple = getTriple(txt);
662 try {
663 return new Location(triple[0], triple[1], triple[2]);
664 } catch (NullPointerException e) {
665 warning("Can't get Location from text '"+txt+"'.");
666 return Location.ZERO;
667 } catch (Exception e) {
668 exceptionOccured(e, "Can't get Location from text '"+txt+"'.");
669 return null;
670 }
671 }
672
673
674
675
676
677
678
679 protected ItemType itemTypeValue(String txt) {
680 return itemTypeTranslator.get(getToken(txt, 1));
681 }
682
683 protected ItemDescriptor itemDescriptorValue(ItemType type) {
684 return itemTranslator.getDescriptor(type);
685 }
686
687
688
689
690
691
692 protected ItemType.Category categoryValue(String txt) {
693 if (txt == null || txt.toLowerCase().equals("none")) return ItemType.Category.NONE;
694 try {
695 return ItemType.Category.valueOf(getToken(txt, 1).toUpperCase());
696 } catch (IllegalArgumentException e) {
697 return ItemType.Category.OTHER;
698 }
699 }
700
701
702
703
704
705
706
707 protected Velocity velocityValue(String txt) {
708 if (txt == null || txt.toLowerCase().equals("none")) return Velocity.NONE;
709 double[] triple = getTriple(txt);
710 try {
711 return new Velocity(triple[0], triple[1], triple[2]);
712 } catch (NullPointerException e) {
713 warning("Can't get Velocity from text '"+txt+"'.");
714 return Velocity.ZERO;
715 } catch (Exception e) {
716 exceptionOccured(e, "Can't get Velocity from text '"+txt+"'.");
717 return null;
718 }
719 }
720
721
722
723
724
725
726
727 protected Rotation rotationValue(String txt) {
728 if (txt == null || txt.toLowerCase().equals("none")) return Rotation.NONE;
729 double[] triple = getTriple(txt);
730 try {
731 return new Rotation(triple[0], triple[1], triple[2]);
732 } catch (NullPointerException e) {
733 warning("Can't get Rotation from text '"+txt+"'.");
734 return Rotation.ZERO;
735 } catch (Exception e) {
736 exceptionOccured(e, "Can't get Rotation from text '"+txt+"'.");
737 return null;
738 }
739 }
740
741
742
743
744
745
746
747 protected Point3d point3dValue(String txt) {
748 if (txt == null || txt.toLowerCase().equals("none")) return UnrealUtils.POINT3D_NONE;
749 double[] triple = getTriple(txt);
750 try {
751 return new Point3d(triple[0], triple[1], triple[2]);
752 } catch (NullPointerException e) {
753 warning("Can't get Point3d from text '"+txt+"'.");
754 return new Point3d(0,0,0);
755 } catch (Exception e) {
756 exceptionOccured(e, "Can't get Point3d from text '"+txt+"'.");
757 return null;
758 }
759 }
760
761
762
763
764
765
766
767 protected Vector3d vector3dValue(String txt) {
768 if (txt == null || txt.toLowerCase().equals("none")) return UnrealUtils.VECTOR3D_NONE;
769 double[] triple = getTriple(txt);
770 try {
771 return new Vector3d(triple[0], triple[1], triple[2]);
772 } catch (NullPointerException e) {
773 warning("Can't get Vector3d from text '"+txt+"'.");
774 return new Vector3d(0,0,0);
775 } catch (Exception e) {
776 exceptionOccured(e, "Can't get Vector3d from text '"+txt+"'.");
777 return null;
778 }
779 }
780
781
782
783
784
785
786
787 protected String stringValue( String txt ) {
788 try {
789 int index = txt.indexOf(" ");
790 if (index == -1) {
791 warning("Can't get string token from text '" + txt + "'.");
792 return "";
793 }
794 String string = txt.substring(index+1, txt.length()-1);
795 if (string != null) {
796 return string;
797 } else {
798 warning("Can't get string token from text '"+txt+"'.");
799 return "";
800 }
801 } catch (Exception e) {
802 exceptionOccured(e, "Can't get string token from text '"+txt+"'.");
803 return "";
804 }
805 }
806
807
808
809
810
811
812
813 protected UnrealId stringIdValue( String txt ) {
814 if (txt == null || txt.toLowerCase().equals("none")) return UnrealId.NONE;
815 return unrealIdValue(txt);
816 }
817
818
819
820
821
822
823
824
825
826 protected boolean booleanValue(String txt) {
827 try {
828 String token = getToken(txt, 1);
829 if (token.equals("True")) return true;
830 if (token.equals("true")) return true;
831 else return false;
832 } catch (NullPointerException e) {
833 warning("Can't get boolean token from text '"+txt+"'.");
834 return false;
835 } catch (Exception e) {
836 exceptionOccured(e, "Can't get boolean token from text '"+txt+"'.");
837 return false;
838 }
839 }
840
841
842
843
844
845
846
847
848
849 protected UnrealId unrealIdValue(String txt) {
850 if (txt == null || txt.toLowerCase().equals("none")) return UnrealId.NONE;
851 try {
852 String token = getToken(txt, 1);
853 if (token == null) {
854 warning("Can't get UnrealId token from text '"+txt+"'.");
855 return null;
856 }
857 return translator.getId(token);
858 } catch (NullPointerException e) {
859 warning("Can't get UnrealId token from text '"+txt+"' (translator not set?).");
860 return null;
861 } catch (Exception e) {
862 exceptionOccured(e, "Can't get UnrealId token from text '"+txt+"'.");
863 return null;
864 }
865 }
866
867
868
869
870
871
872
873
874
875 protected UnrealId worldObjectIdValue(String txt) {
876 if (txt == null || txt.toLowerCase().equals("none")) return UnrealId.NONE;
877 try {
878 String token = getToken(txt, 1);
879 if (token == null) {
880 warning("Can't get UnrealId token from text '"+txt+"'.");
881 return null;
882 }
883 return translator.getId(token);
884 } catch (NullPointerException e) {
885 warning("Can't get UnrealId token from text '"+txt+"' (translator not set?).");
886 return null;
887 } catch (Exception e) {
888 exceptionOccured(e, "Can't get UnrealId token from text '"+txt+"'.");
889 return null;
890 }
891 }
892
893 private ITeamId teamId;
894
895
896
897
898 public void setTeamId(ITeamId teamId) {
899 this.teamId = teamId;
900 }
901
902 private void setTeamId(IWorldObjectUpdatedEvent obj) {
903 setPropertyByReflection( obj, "TeamId", ITeamId.class, (ITeamId)teamId );
904 }
905
906
907 private int[] stack = new int[10];
908 private int stack_pos = 0;
909
910
911 protected Object actObj;
912
913
914
915
916 private void state_go(int state)
917 {
918 stack[stack_pos++] = yystate();
919 yybegin(state);
920 }
921
922
923
924
925 private void state_return()
926 {
927 yybegin(stack[--stack_pos]);
928 }
929
930
931
932
933
934
935
936
937 public Yylex(java.io.Reader in) {
938 this.zzReader = in;
939 }
940
941
942
943
944
945
946
947 public Yylex(java.io.InputStream in) {
948 this(new java.io.InputStreamReader(in));
949 }
950
951
952
953
954
955
956
957 private static char [] zzUnpackCMap(String packed) {
958 char [] map = new char[0x10000];
959 int i = 0;
960 int j = 0;
961 while (i < 116) {
962 int count = packed.charAt(i++);
963 char value = packed.charAt(i++);
964 do map[j++] = value; while (--count > 0);
965 }
966 return map;
967 }
968
969
970
971
972
973
974
975
976
977 private boolean zzRefill() throws java.io.IOException {
978
979
980 if (zzStartRead > 0) {
981 System.arraycopy(zzBuffer, zzStartRead,
982 zzBuffer, 0,
983 zzEndRead-zzStartRead);
984
985
986 zzEndRead-= zzStartRead;
987 zzCurrentPos-= zzStartRead;
988 zzMarkedPos-= zzStartRead;
989 zzStartRead = 0;
990 }
991
992
993 if (zzCurrentPos >= zzBuffer.length) {
994
995 char newBuffer[] = new char[zzCurrentPos*2];
996 System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
997 zzBuffer = newBuffer;
998 }
999
1000
1001 int numRead = zzReader.read(zzBuffer, zzEndRead,
1002 zzBuffer.length-zzEndRead);
1003
1004 if (numRead > 0) {
1005 zzEndRead+= numRead;
1006 return false;
1007 }
1008
1009 if (numRead == 0) {
1010 int c = zzReader.read();
1011 if (c == -1) {
1012 return true;
1013 } else {
1014 zzBuffer[zzEndRead++] = (char) c;
1015 return false;
1016 }
1017 }
1018
1019
1020 return true;
1021 }
1022
1023
1024
1025
1026
1027 public final void yyclose() throws java.io.IOException {
1028 zzAtEOF = true;
1029 zzEndRead = zzStartRead;
1030
1031 if (zzReader != null)
1032 zzReader.close();
1033 }
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046 public final void yyreset(java.io.Reader reader) {
1047 zzReader = reader;
1048 zzAtBOL = true;
1049 zzAtEOF = false;
1050 zzEOFDone = false;
1051 zzEndRead = zzStartRead = 0;
1052 zzCurrentPos = zzMarkedPos = 0;
1053 yyline = yychar = yycolumn = 0;
1054 zzLexicalState = YYINITIAL;
1055 }
1056
1057
1058
1059
1060
1061 public final int yystate() {
1062 return zzLexicalState;
1063 }
1064
1065
1066
1067
1068
1069
1070
1071 public final void yybegin(int newState) {
1072 zzLexicalState = newState;
1073 }
1074
1075
1076
1077
1078
1079 public final String yytext() {
1080 return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
1081 }
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095 public final char yycharat(int pos) {
1096 return zzBuffer[zzStartRead+pos];
1097 }
1098
1099
1100
1101
1102
1103 public final int yylength() {
1104 return zzMarkedPos-zzStartRead;
1105 }
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122 private void zzScanError(int errorCode) {
1123 String message;
1124 try {
1125 message = ZZ_ERROR_MSG[errorCode];
1126 }
1127 catch (ArrayIndexOutOfBoundsException e) {
1128 message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
1129 }
1130
1131 throw new Error(message);
1132 }
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143 public void yypushback(int number) {
1144 if ( number > yylength() )
1145 zzScanError(ZZ_PUSHBACK_2BIG);
1146
1147 zzMarkedPos -= number;
1148 }
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158 public InfoMessage yylex() throws java.io.IOException {
1159 int zzInput;
1160 int zzAction;
1161
1162
1163 int zzCurrentPosL;
1164 int zzMarkedPosL;
1165 int zzEndReadL = zzEndRead;
1166 char [] zzBufferL = zzBuffer;
1167 char [] zzCMapL = ZZ_CMAP;
1168
1169 int [] zzTransL = ZZ_TRANS;
1170 int [] zzRowMapL = ZZ_ROWMAP;
1171 int [] zzAttrL = ZZ_ATTRIBUTE;
1172
1173 while (true) {
1174 zzMarkedPosL = zzMarkedPos;
1175
1176 yychar+= zzMarkedPosL-zzStartRead;
1177
1178 boolean zzR = false;
1179 for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL;
1180 zzCurrentPosL++) {
1181 switch (zzBufferL[zzCurrentPosL]) {
1182 case '\u000B':
1183 case '\u000C':
1184 case '\u0085':
1185 case '\u2028':
1186 case '\u2029':
1187 yyline++;
1188 zzR = false;
1189 break;
1190 case '\r':
1191 yyline++;
1192 zzR = true;
1193 break;
1194 case '\n':
1195 if (zzR)
1196 zzR = false;
1197 else {
1198 yyline++;
1199 }
1200 break;
1201 default:
1202 zzR = false;
1203 }
1204 }
1205
1206 if (zzR) {
1207
1208 boolean zzPeek;
1209 if (zzMarkedPosL < zzEndReadL)
1210 zzPeek = zzBufferL[zzMarkedPosL] == '\n';
1211 else if (zzAtEOF)
1212 zzPeek = false;
1213 else {
1214 boolean eof = zzRefill();
1215 zzEndReadL = zzEndRead;
1216 zzMarkedPosL = zzMarkedPos;
1217 zzBufferL = zzBuffer;
1218 if (eof)
1219 zzPeek = false;
1220 else
1221 zzPeek = zzBufferL[zzMarkedPosL] == '\n';
1222 }
1223 if (zzPeek) yyline--;
1224 }
1225 zzAction = -1;
1226
1227 zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
1228
1229 zzState = ZZ_LEXSTATE[zzLexicalState];
1230
1231
1232 zzForAction: {
1233 while (true) {
1234
1235 if (zzCurrentPosL < zzEndReadL)
1236 zzInput = zzBufferL[zzCurrentPosL++];
1237 else if (zzAtEOF) {
1238 zzInput = YYEOF;
1239 break zzForAction;
1240 }
1241 else {
1242
1243 zzCurrentPos = zzCurrentPosL;
1244 zzMarkedPos = zzMarkedPosL;
1245 boolean eof = zzRefill();
1246
1247 zzCurrentPosL = zzCurrentPos;
1248 zzMarkedPosL = zzMarkedPos;
1249 zzBufferL = zzBuffer;
1250 zzEndReadL = zzEndRead;
1251 if (eof) {
1252 zzInput = YYEOF;
1253 break zzForAction;
1254 }
1255 else {
1256 zzInput = zzBufferL[zzCurrentPosL++];
1257 }
1258 }
1259 int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
1260 if (zzNext == -1) break zzForAction;
1261 zzState = zzNext;
1262
1263 int zzAttributes = zzAttrL[zzState];
1264 if ( (zzAttributes & 1) == 1 ) {
1265 zzAction = zzState;
1266 zzMarkedPosL = zzCurrentPosL;
1267 if ( (zzAttributes & 8) == 8 ) break zzForAction;
1268 }
1269
1270 }
1271 }
1272
1273
1274 zzMarkedPos = zzMarkedPosL;
1275
1276 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
1277 case 4:
1278 { if (!yytext().equals(" ")) {
1279 warning("State UNPROCESSED_MESSAGE unprocessed: " + yytext());
1280 }
1281 }
1282 case 16: break;
1283 case 13:
1284 { ((AliveMessageMessage)actObj).
1285 Time = doubleValue(yytext());
1286
1287 ((AliveMessageMessage)actObj).Time_Set = true;
1288 }
1289 case 17: break;
1290 case 9:
1291 { actObj = new EmptyMessage();
1292
1293 state_go(MSG_EMP);
1294 }
1295 case 18: break;
1296 case 7:
1297 { if (!yytext().equals(" ")) {
1298 warning("State MSG_BEG unprocessed: " + yytext());
1299 }
1300 }
1301 case 19: break;
1302 case 6:
1303 { if (!yytext().equals(" ")) {
1304 warning("State MSG_ALIVE unprocessed: " + yytext());
1305 }
1306 }
1307 case 20: break;
1308 case 2:
1309 { warning("Illegal character: <" + yytext() + "> + currentstate "+ yystate());
1310 }
1311 case 21: break;
1312 case 11:
1313 { String text = yytext();
1314 if(!tryParsingUnprocessedMessageParameter(getToken(text,0), text)) {
1315 warning("Illegal unprocessed message parameter: <" + yytext() + ">");
1316 }
1317 }
1318 case 22: break;
1319 case 5:
1320 { if (!yytext().equals(" ")) {
1321 warning("State MSG_EMP unprocessed: " + yytext());
1322 }
1323 }
1324 case 23: break;
1325 case 10:
1326 { actObj = new BeginMessage();
1327
1328 state_go(MSG_BEG);
1329 }
1330 case 24: break;
1331 case 12:
1332 { actObj = new AliveMessageMessage();
1333
1334 state_go(MSG_ALIVE);
1335 }
1336 case 25: break;
1337 case 15:
1338 { ((BeginMessage)actObj).
1339 VisUpdate = booleanValue(yytext());
1340 }
1341 case 26: break;
1342 case 8:
1343 {
1344 stack_pos = 0;
1345 yybegin(YYINITIAL);
1346 if (actObj != null)
1347 {
1348 InfoMessage obj = (InfoMessage) actObj;
1349
1350 if (obj instanceof IWorldObjectUpdatedEvent) {
1351 setTeamId((IWorldObjectUpdatedEvent)obj);
1352 }
1353
1354 if (obj instanceof BeginMessage) {
1355 ut2004Time = ((BeginMessage)obj).getTime();
1356 setTime((IWorldEvent)obj, ut2004Time);
1357 } else
1358 if (obj instanceof AliveMessage) {
1359 ut2004Time = ((AliveMessage)obj).getTime();
1360 setTime((IWorldObjectUpdatedEvent)obj, ut2004Time);
1361 } else
1362 if (obj instanceof IWorldObjectUpdatedEvent) {
1363 setTime((IWorldObjectUpdatedEvent)obj, ut2004Time);
1364 } else
1365 if (obj instanceof IWorldEvent) {
1366 setTime((IWorldEvent)obj, ut2004Time);
1367 }
1368
1369 actObj = null;
1370 return obj;
1371 }
1372 }
1373 case 27: break;
1374 case 1:
1375 { InfoMessage obj = tryParsingUnprocessedMessage(yytext());
1376 if(obj != null){
1377 actObj = obj;
1378 state_go(UNPROCESSED_MESSAGE);
1379 } else {
1380 warning("Illegal character sequence: <" + yytext() + "> + currentstate "+ yystate());
1381 }
1382 }
1383 case 28: break;
1384 case 14:
1385 { ((BeginMessage)actObj).
1386 Time = doubleValue(yytext());
1387 }
1388 case 29: break;
1389 case 3:
1390 {
1391 }
1392 case 30: break;
1393 default:
1394 if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
1395 zzAtEOF = true;
1396 { throw new ParserEOFException(this);
1397 }
1398 }
1399 else {
1400 zzScanError(ZZ_NO_MATCH);
1401 }
1402 }
1403 }
1404 }
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415 public static void main(String argv[]) {
1416 if (argv.length == 0) {
1417 System.out.println("Usage : java Yylex <inputfile>");
1418 }
1419 else {
1420 for (int i = 0; i < argv.length; i++) {
1421 Yylex scanner = null;
1422 try {
1423 scanner = new Yylex( new java.io.FileReader(argv[i]) );
1424 while ( !scanner.zzAtEOF ) scanner.yylex();
1425 }
1426 catch (java.io.FileNotFoundException e) {
1427 System.out.println("File not found : \""+argv[i]+"\"");
1428 }
1429 catch (java.io.IOException e) {
1430 System.out.println("IO error scanning file \""+argv[i]+"\"");
1431 System.out.println(e);
1432 }
1433 catch (Exception e) {
1434 System.out.println("Unexpected exception:");
1435 e.printStackTrace();
1436 }
1437 }
1438 }
1439 }
1440
1441
1442 }