-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lexer.java
1067 lines (952 loc) · 31 KB
/
Lexer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// DO NOT EDIT
// Generated by JFlex 1.8.2 http://jflex.de/
// source: grammar.jflex
/*-***
* This grammar is defined for the example grammar defined in the
*project part 1 instructions
*/
/*
* NOTE: make sure that the java cup runtime file is in the same directory as this file
* it is also alright if the runtime location is added to to the classpath, but just
* putting in the same file is far easier.
*/
import java_cup.runtime.*;
// See https://github.com/jflex-de/jflex/issues/222
@SuppressWarnings("FallThrough")
class Lexer implements java_cup.runtime.Scanner {
/** This character denotes the end of file. */
public static final int YYEOF = -1;
/** Initial size of the lookahead buffer. */
private static final int ZZ_BUFFERSIZE = 16384;
// Lexical states.
public static final int YYINITIAL = 0;
/**
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
* at the beginning of a line
* l is of the form l = 2*k, k a non negative integer
*/
private static final int ZZ_LEXSTATE[] = {
0, 0
};
/**
* Top-level table for translating characters to character classes
*/
private static final int [] ZZ_CMAP_TOP = zzUnpackcmap_top();
private static final String ZZ_CMAP_TOP_PACKED_0 =
"\1\0\37\u0100\1\u0200\267\u0100\10\u0300\u1020\u0100";
private static int [] zzUnpackcmap_top() {
int [] result = new int[4352];
int offset = 0;
offset = zzUnpackcmap_top(ZZ_CMAP_TOP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackcmap_top(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Second-level tables for translating characters to character classes
*/
private static final int [] ZZ_CMAP_BLOCKS = zzUnpackcmap_blocks();
private static final String ZZ_CMAP_BLOCKS_PACKED_0 =
"\11\0\1\1\1\2\2\3\1\4\22\0\1\5\1\0"+
"\1\6\3\0\1\7\1\10\1\11\1\12\1\13\1\14"+
"\1\15\1\16\1\17\1\20\12\21\1\22\1\23\1\24"+
"\1\25\1\26\1\27\1\0\32\30\1\31\1\32\1\33"+
"\3\0\1\34\1\35\1\36\1\37\1\40\1\41\1\30"+
"\1\42\1\43\2\30\1\44\1\30\1\45\1\46\1\47"+
"\1\30\1\50\1\51\1\52\1\53\1\54\1\55\3\30"+
"\1\56\1\57\1\60\1\61\6\0\1\3\u01a2\0\2\3"+
"\326\0\u0100\3";
private static int [] zzUnpackcmap_blocks() {
int [] result = new int[1024];
int offset = 0;
offset = zzUnpackcmap_blocks(ZZ_CMAP_BLOCKS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackcmap_blocks(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Translates DFA states to action switch labels.
*/
private static final int [] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 =
"\1\0\1\1\1\2\3\1\1\3\1\4\1\5\1\6"+
"\1\7\1\10\1\11\1\12\1\13\1\14\1\15\1\16"+
"\1\17\1\20\1\21\1\22\1\1\1\23\12\21\1\24"+
"\1\1\1\25\1\26\1\0\1\27\1\0\1\30\2\0"+
"\1\31\1\32\1\0\1\33\1\34\1\35\1\36\2\0"+
"\7\21\1\37\6\21\1\40\1\41\1\42\1\0\2\43"+
"\7\21\1\44\6\21\1\0\1\45\1\46\1\21\1\47"+
"\4\21\1\50\1\21\1\51\1\52\1\21\1\0\1\53"+
"\1\54\1\55\1\56\1\57\1\21\1\60\1\43\1\21"+
"\1\61\2\21\1\62";
private static int [] zzUnpackAction() {
int [] result = new int[115];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 =
"\0\0\0\62\0\62\0\144\0\226\0\310\0\62\0\62"+
"\0\62\0\372\0\62\0\u012c\0\62\0\u015e\0\62\0\62"+
"\0\u0190\0\u01c2\0\u01f4\0\62\0\u0226\0\62\0\u0258\0\62"+
"\0\u028a\0\u02bc\0\u02ee\0\u0320\0\u0352\0\u0384\0\u03b6\0\u03e8"+
"\0\u041a\0\u044c\0\62\0\u047e\0\62\0\62\0\144\0\62"+
"\0\u04b0\0\62\0\u04e2\0\u0514\0\62\0\62\0\u0546\0\62"+
"\0\62\0\62\0\62\0\u0578\0\u05aa\0\u05dc\0\u060e\0\u0640"+
"\0\u0672\0\u06a4\0\u06d6\0\u0708\0\u0226\0\u073a\0\u076c\0\u079e"+
"\0\u07d0\0\u0802\0\u0834\0\62\0\62\0\u0546\0\u0866\0\62"+
"\0\u0898\0\u08ca\0\u08fc\0\u092e\0\u0960\0\u0992\0\u09c4\0\u09f6"+
"\0\u0226\0\u0a28\0\u0a5a\0\u0a8c\0\u0abe\0\u0af0\0\u0b22\0\u0b54"+
"\0\u0226\0\u0226\0\u0b86\0\u0226\0\u0bb8\0\u0bea\0\u0c1c\0\u0c4e"+
"\0\u0226\0\u0c80\0\u0226\0\u0226\0\u0cb2\0\u0ce4\0\u0226\0\u0226"+
"\0\u0226\0\u0226\0\u0d16\0\u0d48\0\u0226\0\u0578\0\u0d7a\0\u0226"+
"\0\u0dac\0\u0dde\0\u0226";
private static int [] zzUnpackRowMap() {
int [] result = new int[115];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int high = packed.charAt(i++) << 16;
result[j++] = high | packed.charAt(i++);
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int [] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 =
"\1\2\2\3\1\0\2\3\1\4\1\5\1\6\1\7"+
"\1\10\1\11\1\12\1\13\1\14\1\2\1\15\1\16"+
"\1\17\1\20\1\21\1\22\1\23\1\24\1\25\1\26"+
"\1\27\1\30\1\25\1\31\1\32\1\25\1\33\1\34"+
"\1\25\1\35\3\25\1\36\1\37\1\25\1\40\1\25"+
"\1\41\1\42\1\43\1\44\1\45\1\46\62\0\1\47"+
"\2\0\3\47\1\50\23\47\1\51\27\47\7\0\1\52"+
"\52\0\10\53\1\0\21\53\1\54\27\53\14\0\1\55"+
"\63\0\1\56\62\0\1\57\1\0\1\16\65\0\1\60"+
"\1\61\60\0\1\62\61\0\1\63\55\0\1\25\6\0"+
"\1\25\3\0\22\25\17\0\1\64\16\0\1\65\50\0"+
"\1\25\6\0\1\25\3\0\12\25\1\66\7\25\25\0"+
"\1\25\6\0\1\25\3\0\6\25\1\67\1\25\1\70"+
"\11\25\25\0\1\25\6\0\1\25\3\0\10\25\1\71"+
"\11\25\25\0\1\25\6\0\1\25\3\0\1\72\6\25"+
"\1\73\1\74\11\25\25\0\1\25\6\0\1\25\3\0"+
"\5\25\1\75\3\25\1\76\10\25\25\0\1\25\6\0"+
"\1\25\3\0\14\25\1\77\5\25\25\0\1\25\6\0"+
"\1\25\3\0\4\25\1\100\15\25\25\0\1\25\6\0"+
"\1\25\3\0\14\25\1\101\5\25\25\0\1\25\6\0"+
"\1\25\3\0\12\25\1\102\7\25\25\0\1\25\6\0"+
"\1\25\3\0\6\25\1\103\13\25\63\0\1\104\10\0"+
"\1\47\23\0\1\47\12\0\1\47\4\0\1\47\17\0"+
"\1\105\61\0\1\53\21\0\1\53\12\0\1\53\4\0"+
"\1\53\30\0\1\106\40\0\13\64\1\107\46\64\2\65"+
"\1\110\1\0\1\111\55\65\21\0\1\25\6\0\1\25"+
"\3\0\12\25\1\112\7\25\25\0\1\25\6\0\1\25"+
"\3\0\1\113\21\25\25\0\1\25\6\0\1\25\3\0"+
"\1\114\21\25\25\0\1\25\6\0\1\25\3\0\15\25"+
"\1\115\4\25\25\0\1\25\6\0\1\25\3\0\10\25"+
"\1\116\11\25\25\0\1\25\6\0\1\25\3\0\11\25"+
"\1\117\10\25\25\0\1\25\6\0\1\25\3\0\12\25"+
"\1\120\7\25\25\0\1\25\6\0\1\25\3\0\16\25"+
"\1\121\3\25\25\0\1\25\6\0\1\25\3\0\7\25"+
"\1\122\12\25\25\0\1\25\6\0\1\25\3\0\1\123"+
"\15\25\1\124\3\25\25\0\1\25\6\0\1\25\3\0"+
"\17\25\1\125\2\25\25\0\1\25\6\0\1\25\3\0"+
"\7\25\1\126\12\25\25\0\1\25\6\0\1\25\3\0"+
"\7\25\1\127\12\25\4\0\13\64\1\130\16\64\1\110"+
"\27\64\2\0\1\110\100\0\1\25\6\0\1\25\3\0"+
"\10\25\1\131\11\25\25\0\1\25\6\0\1\25\3\0"+
"\14\25\1\132\5\25\25\0\1\25\6\0\1\25\3\0"+
"\15\25\1\133\4\25\25\0\1\25\6\0\1\25\3\0"+
"\4\25\1\134\15\25\25\0\1\25\6\0\1\25\3\0"+
"\15\25\1\135\4\25\25\0\1\25\6\0\1\25\3\0"+
"\1\136\21\25\25\0\1\25\6\0\1\25\3\0\1\137"+
"\21\25\25\0\1\25\6\0\1\25\3\0\11\25\1\140"+
"\10\25\25\0\1\25\6\0\1\25\3\0\3\25\1\141"+
"\16\25\25\0\1\25\6\0\1\25\3\0\17\25\1\142"+
"\2\25\25\0\1\25\6\0\1\25\3\0\4\25\1\143"+
"\15\25\25\0\1\25\6\0\1\25\3\0\3\25\1\144"+
"\16\25\25\0\1\25\6\0\1\25\3\0\10\25\1\145"+
"\11\25\4\0\13\64\1\146\46\64\21\0\1\25\6\0"+
"\1\25\3\0\15\25\1\147\4\25\25\0\1\25\6\0"+
"\1\25\3\0\4\25\1\150\15\25\25\0\1\25\6\0"+
"\1\25\3\0\10\25\1\151\11\25\25\0\1\25\6\0"+
"\1\25\3\0\16\25\1\152\3\25\25\0\1\25\6\0"+
"\1\25\3\0\16\25\1\153\3\25\25\0\1\25\6\0"+
"\1\25\3\0\14\25\1\154\5\25\25\0\1\25\6\0"+
"\1\25\3\0\4\25\1\155\15\25\4\0\13\64\1\146"+
"\16\64\1\156\27\64\21\0\1\25\6\0\1\25\3\0"+
"\10\25\1\157\11\25\25\0\1\25\6\0\1\25\3\0"+
"\11\25\1\160\10\25\25\0\1\25\6\0\1\25\3\0"+
"\7\25\1\161\12\25\25\0\1\25\6\0\1\25\3\0"+
"\11\25\1\162\10\25\25\0\1\25\6\0\1\25\3\0"+
"\4\25\1\163\15\25\4\0";
private static int [] zzUnpackTrans() {
int [] result = new int[3600];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
value--;
do result[j++] = value; while (--count > 0);
}
return j;
}
/** Error code for "Unknown internal scanner error". */
private static final int ZZ_UNKNOWN_ERROR = 0;
/** Error code for "could not match input". */
private static final int ZZ_NO_MATCH = 1;
/** Error code for "pushback value was too large". */
private static final int ZZ_PUSHBACK_2BIG = 2;
/**
* Error messages for {@link #ZZ_UNKNOWN_ERROR}, {@link #ZZ_NO_MATCH}, and
* {@link #ZZ_PUSHBACK_2BIG} respectively.
*/
private static final String ZZ_ERROR_MSG[] = {
"Unknown internal scanner error",
"Error: could not match input",
"Error: pushback value was too large"
};
/**
* ZZ_ATTRIBUTE[aState] contains the attributes of state {@code aState}
*/
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 =
"\1\0\2\11\3\1\3\11\1\1\1\11\1\1\1\11"+
"\1\1\2\11\3\1\1\11\1\1\1\11\1\1\1\11"+
"\12\1\1\11\1\1\2\11\1\0\1\11\1\0\1\11"+
"\2\0\2\11\1\0\4\11\2\0\16\1\2\11\1\1"+
"\1\0\1\11\17\1\1\0\15\1\1\0\15\1";
private static int [] zzUnpackAttribute() {
int [] result = new int[115];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/** Input device. */
private java.io.Reader zzReader;
/** Current state of the DFA. */
private int zzState;
/** Current lexical state. */
private int zzLexicalState = YYINITIAL;
/**
* This buffer contains the current text to be matched and is the source of the {@link #yytext()}
* string.
*/
private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
/** Text position at the last accepting state. */
private int zzMarkedPos;
/** Current text position in the buffer. */
private int zzCurrentPos;
/** Marks the beginning of the {@link #yytext()} string in the buffer. */
private int zzStartRead;
/** Marks the last character in the buffer, that has been read from input. */
private int zzEndRead;
/**
* Whether the scanner is at the end of file.
* @see #yyatEOF
*/
private boolean zzAtEOF;
/**
* The number of occupied positions in {@link #zzBuffer} beyond {@link #zzEndRead}.
*
* <p>When a lead/high surrogate has been read from the input stream into the final
* {@link #zzBuffer} position, this will have a value of 1; otherwise, it will have a value of 0.
*/
private int zzFinalHighSurrogate = 0;
/** Number of newlines encountered up to the start of the matched text. */
private int yyline;
/** Number of characters from the last newline up to the start of the matched text. */
private int yycolumn;
/** Number of characters up to the start of the matched text. */
@SuppressWarnings("unused")
private long yychar;
/** Whether the scanner is currently at the beginning of a line. */
@SuppressWarnings("unused")
private boolean zzAtBOL = true;
/** Whether the user-EOF-code has already been executed. */
private boolean zzEOFDone;
/* user code: */
/**
* Return a new Symbol with the given token id, and with the current line and
* column numbers.
*/
Symbol newSym(int tokenId) {
return new Symbol(tokenId, yyline, yycolumn);
}
/**
* Return a new Symbol with the given token id, the current line and column
* numbers, and the given token value. The value is used for tokens such as
* identifiers and numbers.
*/
Symbol newSym(int tokenId, Object value) {
return new Symbol(tokenId, yyline, yycolumn, value);
}
/**
* Creates a new scanner
*
* @param in the java.io.Reader to read input from.
*/
Lexer(java.io.Reader in) {
this.zzReader = in;
}
/**
* Translates raw input code points to DFA table row
*/
private static int zzCMap(int input) {
int offset = input & 255;
return offset == input ? ZZ_CMAP_BLOCKS[offset] : ZZ_CMAP_BLOCKS[ZZ_CMAP_TOP[input >> 8] | offset];
}
/**
* Refills the input buffer.
*
* @return {@code false} iff there was new input.
* @exception java.io.IOException if any I/O-Error occurs
*/
private boolean zzRefill() throws java.io.IOException {
/* first: make room (if you can) */
if (zzStartRead > 0) {
zzEndRead += zzFinalHighSurrogate;
zzFinalHighSurrogate = 0;
System.arraycopy(zzBuffer, zzStartRead,
zzBuffer, 0,
zzEndRead - zzStartRead);
/* translate stored positions */
zzEndRead -= zzStartRead;
zzCurrentPos -= zzStartRead;
zzMarkedPos -= zzStartRead;
zzStartRead = 0;
}
/* is the buffer big enough? */
if (zzCurrentPos >= zzBuffer.length - zzFinalHighSurrogate) {
/* if not: blow it up */
char newBuffer[] = new char[zzBuffer.length * 2];
System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
zzBuffer = newBuffer;
zzEndRead += zzFinalHighSurrogate;
zzFinalHighSurrogate = 0;
}
/* fill the buffer with new input */
int requested = zzBuffer.length - zzEndRead;
int numRead = zzReader.read(zzBuffer, zzEndRead, requested);
/* not supposed to occur according to specification of java.io.Reader */
if (numRead == 0) {
throw new java.io.IOException(
"Reader returned 0 characters. See JFlex examples/zero-reader for a workaround.");
}
if (numRead > 0) {
zzEndRead += numRead;
if (Character.isHighSurrogate(zzBuffer[zzEndRead - 1])) {
if (numRead == requested) { // We requested too few chars to encode a full Unicode character
--zzEndRead;
zzFinalHighSurrogate = 1;
} else { // There is room in the buffer for at least one more char
int c = zzReader.read(); // Expecting to read a paired low surrogate char
if (c == -1) {
return true;
} else {
zzBuffer[zzEndRead++] = (char)c;
}
}
}
/* potentially more input available */
return false;
}
/* numRead < 0 ==> end of stream */
return true;
}
/**
* Closes the input reader.
*
* @throws java.io.IOException if the reader could not be closed.
*/
public final void yyclose() throws java.io.IOException {
zzAtEOF = true; // indicate end of file
zzEndRead = zzStartRead; // invalidate buffer
if (zzReader != null) {
zzReader.close();
}
}
/**
* Resets the scanner to read from a new input stream.
*
* <p>Does not close the old reader.
*
* <p>All internal variables are reset, the old input stream <b>cannot</b> be reused (internal
* buffer is discarded and lost). Lexical state is set to {@code ZZ_INITIAL}.
*
* <p>Internal scan buffer is resized down to its initial length, if it has grown.
*
* @param reader The new input stream.
*/
public final void yyreset(java.io.Reader reader) {
zzReader = reader;
zzEOFDone = false;
yyResetPosition();
zzLexicalState = YYINITIAL;
if (zzBuffer.length > ZZ_BUFFERSIZE) {
zzBuffer = new char[ZZ_BUFFERSIZE];
}
}
/**
* Resets the input position.
*/
private final void yyResetPosition() {
zzAtBOL = true;
zzAtEOF = false;
zzCurrentPos = 0;
zzMarkedPos = 0;
zzStartRead = 0;
zzEndRead = 0;
zzFinalHighSurrogate = 0;
yyline = 0;
yycolumn = 0;
yychar = 0L;
}
/**
* Returns whether the scanner has reached the end of the reader it reads from.
*
* @return whether the scanner has reached EOF.
*/
public final boolean yyatEOF() {
return zzAtEOF;
}
/**
* Returns the current lexical state.
*
* @return the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state.
*
* @param newState the new lexical state
*/
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*
* @return the matched text.
*/
public final String yytext() {
return new String(zzBuffer, zzStartRead, zzMarkedPos-zzStartRead);
}
/**
* Returns the character at the given position from the matched text.
*
* <p>It is equivalent to {@code yytext().charAt(pos)}, but faster.
*
* @param position the position of the character to fetch. A value from 0 to {@code yylength()-1}.
*
* @return the character at {@code position}.
*/
public final char yycharat(int position) {
return zzBuffer[zzStartRead + position];
}
/**
* How many characters were matched.
*
* @return the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos-zzStartRead;
}
/**
* Reports an error that occurred while scanning.
*
* <p>In a well-formed scanner (no or only correct usage of {@code yypushback(int)} and a
* match-all fallback rule) this method will only be called with things that
* "Can't Possibly Happen".
*
* <p>If this method is called, something is seriously wrong (e.g. a JFlex bug producing a faulty
* scanner etc.).
*
* <p>Usual syntax/scanner level error handling should be done in error fallback rules.
*
* @param errorCode the code of the error message to display.
*/
private static void zzScanError(int errorCode) {
String message;
try {
message = ZZ_ERROR_MSG[errorCode];
} catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* <p>They will be read again by then next call of the scanning method.
*
* @param number the number of characters to be read again. This number must not be greater than
* {@link #yylength()}.
*/
public void yypushback(int number) {
if ( number > yylength() )
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Contains user EOF-code, which will be executed exactly once,
* when the end of file is reached
*/
private void zzDoEOF() throws java.io.IOException {
if (!zzEOFDone) {
zzEOFDone = true;
yyclose(); }
}
/**
* Resumes scanning until the next regular expression is matched, the end of input is encountered
* or an I/O-Error occurs.
*
* @return the next token.
* @exception java.io.IOException if any I/O-Error occurs.
*/
@Override public java_cup.runtime.Symbol next_token() throws java.io.IOException {
int zzInput;
int zzAction;
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
char[] zzBufferL = zzBuffer;
int [] zzTransL = ZZ_TRANS;
int [] zzRowMapL = ZZ_ROWMAP;
int [] zzAttrL = ZZ_ATTRIBUTE;
while (true) {
zzMarkedPosL = zzMarkedPos;
boolean zzR = false;
int zzCh;
int zzCharCount;
for (zzCurrentPosL = zzStartRead ;
zzCurrentPosL < zzMarkedPosL ;
zzCurrentPosL += zzCharCount ) {
zzCh = Character.codePointAt(zzBufferL, zzCurrentPosL, zzMarkedPosL);
zzCharCount = Character.charCount(zzCh);
switch (zzCh) {
case '\u000B': // fall through
case '\u000C': // fall through
case '\u0085': // fall through
case '\u2028': // fall through
case '\u2029':
yyline++;
yycolumn = 0;
zzR = false;
break;
case '\r':
yyline++;
yycolumn = 0;
zzR = true;
break;
case '\n':
if (zzR)
zzR = false;
else {
yyline++;
yycolumn = 0;
}
break;
default:
zzR = false;
yycolumn += zzCharCount;
}
}
if (zzR) {
// peek one character ahead if it is
// (if we have counted one line too much)
boolean zzPeek;
if (zzMarkedPosL < zzEndReadL)
zzPeek = zzBufferL[zzMarkedPosL] == '\n';
else if (zzAtEOF)
zzPeek = false;
else {
boolean eof = zzRefill();
zzEndReadL = zzEndRead;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
if (eof)
zzPeek = false;
else
zzPeek = zzBufferL[zzMarkedPosL] == '\n';
}
if (zzPeek) yyline--;
}
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = ZZ_LEXSTATE[zzLexicalState];
// set up zzAction for empty match case:
int zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
}
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL) {
zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL, zzEndReadL);
zzCurrentPosL += Character.charCount(zzInput);
}
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
}
else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
boolean eof = zzRefill();
// get translated positions and possibly new buffer
zzCurrentPosL = zzCurrentPos;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
zzEndReadL = zzEndRead;
if (eof) {
zzInput = YYEOF;
break zzForAction;
}
else {
zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL, zzEndReadL);
zzCurrentPosL += Character.charCount(zzInput);
}
}
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMap(zzInput) ];
if (zzNext == -1) break zzForAction;
zzState = zzNext;
zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
if ( (zzAttributes & 8) == 8 ) break zzForAction;
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
zzDoEOF();
{ return new java_cup.runtime.Symbol(sym.EOF); }
}
else {
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 1:
{ System.out.println("Illegal char, '" + yytext() +
"' line: " + yyline + ", column: " + yychar);
}
// fall through
case 51: break;
case 2:
{ /* Ignore whitespace. */
}
// fall through
case 52: break;
case 3:
{ return newSym(sym.L_PAREN, "(");
}
// fall through
case 53: break;
case 4:
{ return newSym(sym.R_PAREN, ")");
}
// fall through
case 54: break;
case 5:
{ return newSym(sym.TIMES, "*");
}
// fall through
case 55: break;
case 6:
{ return newSym(sym.PLUS, "+");
}
// fall through
case 56: break;
case 7:
{ return newSym(sym.COMMA, ",");
}
// fall through
case 57: break;
case 8:
{ return newSym(sym.MINUS, "-");
}
// fall through
case 58: break;
case 9:
{ return newSym(sym.DIVIDE, "/");
}
// fall through
case 59: break;
case 10:
{ return newSym(sym.INTLIT, new Integer(yytext()));
}
// fall through
case 60: break;
case 11:
{ return newSym(sym.COLON, ":");
}
// fall through
case 61: break;
case 12:
{ return newSym(sym.SEMI, ";");
}
// fall through
case 62: break;
case 13:
{ return newSym(sym.LT, "<");
}
// fall through
case 63: break;
case 14:
{ return newSym(sym.ASSMNT, "=");
}
// fall through
case 64: break;
case 15:
{ return newSym(sym.GT, ">");
}
// fall through
case 65: break;
case 16:
{ return newSym(sym.TERNARY, "?");
}
// fall through
case 66: break;
case 17:
{ return newSym(sym.ID, yytext());
}
// fall through
case 67: break;
case 18:
{ return newSym(sym.L_BRACKET, "[");
}
// fall through
case 68: break;
case 19:
{ return newSym(sym.R_BRACKET, "]");
}
// fall through
case 69: break;
case 20:
{ return newSym(sym.L_BRACE, "{");
}
// fall through
case 70: break;
case 21:
{ return newSym(sym.R_BRACE, "}");
}
// fall through
case 71: break;
case 22:
{ return newSym(sym.NEGATION, "~");
}
// fall through
case 72: break;
case 23:
{ return newSym(sym.STRLIT, yytext());
}
// fall through
case 73: break;
case 24:
{ return newSym(sym.AND, "&&");
}
// fall through
case 74: break;
case 25:
{ return newSym(sym.INCREMENT, "++");
}
// fall through
case 75: break;
case 26:
{ return newSym(sym.DECREMENT, "--");
}
// fall through
case 76: break;
case 27:
{ return newSym(sym.LTE, "<=");
}
// fall through
case 77: break;
case 28:
{ return newSym(sym.NOT_EQ, "<>");
}
// fall through
case 78: break;
case 29:
{ return newSym(sym.EQ, "==");
}
// fall through
case 79: break;
case 30:
{ return newSym(sym.GTE, ">=");
}
// fall through
case 80: break;
case 31:
{ return newSym(sym.IF, "if");
}
// fall through
case 81: break;
case 32:
{ return newSym(sym.OR, "||");
}
// fall through
case 82: break;
case 33:
{ return newSym(sym.CHARLIT, yytext());
}
// fall through
case 83: break;
case 34:
{ return newSym(sym.FLOATLIT, new Float(yytext()));
}
// fall through
case 84: break;
case 35:
{ /* For this stand-alone lexer, print out comments. */
}
// fall through
case 85: break;
case 36:
{ return newSym(sym.INT, "int");
}
// fall through
case 86: break;
case 37:
{ return newSym(sym.BOOL, "bool");
}
// fall through
case 87: break;
case 38:
{ return newSym(sym.CHAR, "char");
}
// fall through
case 88: break;
case 39:
{ return newSym(sym.ELSE, "else");