-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.java
More file actions
1097 lines (893 loc) · 32 KB
/
syntax.java
File metadata and controls
1097 lines (893 loc) · 32 KB
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
/* A Bison parser, made by GNU Bison 3.8.2. */
/* Skeleton implementation for Bison LALR(1) parsers in Java
Copyright (C) 2007-2015, 2018-2021 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
especially those whose name start with YY_ or yy_. They are
private implementation details that can be changed or removed. */
import java.text.MessageFormat;
import java.util.ArrayList;
/* "%code imports" blocks. */
/* "src/syntax/syntax.y":9 */
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.IOException;
/* "syntax.java":51 */
/**
* A Bison parser, automatically generated from <tt>src/syntax/syntax.y</tt>.
*
* @author LALR (1) parser skeleton written by Paolo Bonzini.
*/
public class LISPParser
{
/** Version number for the Bison executable that generated this parser. */
public static final String bisonVersion = "3.8.2";
/** Name of the skeleton that generated this parser. */
public static final String bisonSkeleton = "lalr1.java";
/**
* True if verbose error messages are enabled.
*/
private boolean yyErrorVerbose = true;
/**
* Whether verbose error messages are enabled.
*/
public final boolean getErrorVerbose() { return yyErrorVerbose; }
/**
* Set the verbosity of error messages.
* @param verbose True to request verbose error messages.
*/
public final void setErrorVerbose(boolean verbose)
{ yyErrorVerbose = verbose; }
public enum SymbolKind
{
S_YYEOF(0), /* "end of file" */
S_YYerror(1), /* error */
S_YYUNDEF(2), /* "invalid token" */
S_Literal(3), /* Literal */
S_Identifier(4), /* Identifier */
S_LeftBracket(5), /* LeftBracket */
S_RightBracket(6), /* RightBracket */
S_YYACCEPT(7), /* $accept */
S_Program(8), /* Program */
S_List(9), /* List */
S_Elements(10), /* Elements */
S_Element(11), /* Element */
S_Atom(12); /* Atom */
private final int yycode_;
SymbolKind (int n) {
this.yycode_ = n;
}
private static final SymbolKind[] values_ = {
SymbolKind.S_YYEOF,
SymbolKind.S_YYerror,
SymbolKind.S_YYUNDEF,
SymbolKind.S_Literal,
SymbolKind.S_Identifier,
SymbolKind.S_LeftBracket,
SymbolKind.S_RightBracket,
SymbolKind.S_YYACCEPT,
SymbolKind.S_Program,
SymbolKind.S_List,
SymbolKind.S_Elements,
SymbolKind.S_Element,
SymbolKind.S_Atom
};
static final SymbolKind get(int code) {
return values_[code];
}
public final int getCode() {
return this.yycode_;
}
/* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
that double-quoting is unnecessary unless the string contains an
apostrophe, a comma, or backslash (other than backslash-backslash).
YYSTR is taken from yytname. */
private static String yytnamerr_(String yystr)
{
if (yystr.charAt (0) == '"')
{
StringBuffer yyr = new StringBuffer();
strip_quotes: for (int i = 1; i < yystr.length(); i++)
switch (yystr.charAt(i))
{
case '\'':
case ',':
break strip_quotes;
case '\\':
if (yystr.charAt(++i) != '\\')
break strip_quotes;
/* Fall through. */
default:
yyr.append(yystr.charAt(i));
break;
case '"':
return yyr.toString();
}
}
return yystr;
}
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
private static final String[] yytname_ = yytname_init();
private static final String[] yytname_init()
{
return new String[]
{
"\"end of file\"", "error", "\"invalid token\"", "Literal",
"Identifier", "LeftBracket", "RightBracket", "$accept", "Program",
"List", "Elements", "Element", "Atom", null
};
}
/* The user-facing name of this symbol. */
public final String getName() {
return yytnamerr_(yytname_[yycode_]);
}
};
/**
* Communication interface between the scanner and the Bison-generated
* parser <tt>LISPParser</tt>.
*/
public interface Lexer {
/* Token kinds. */
/** Token "end of file", to be returned by the scanner. */
static final int YYEOF = 0;
/** Token error, to be returned by the scanner. */
static final int YYerror = 256;
/** Token "invalid token", to be returned by the scanner. */
static final int YYUNDEF = 257;
/** Token Literal, to be returned by the scanner. */
static final int Literal = 258;
/** Token Identifier, to be returned by the scanner. */
static final int Identifier = 259;
/** Token LeftBracket, to be returned by the scanner. */
static final int LeftBracket = 260;
/** Token RightBracket, to be returned by the scanner. */
static final int RightBracket = 261;
/** Deprecated, use YYEOF instead. */
public static final int EOF = YYEOF;
/**
* Method to retrieve the semantic value of the last scanned token.
* @return the semantic value of the last scanned token.
*/
TreeNode getLVal();
/**
* Entry point for the scanner. Returns the token identifier corresponding
* to the next token and prepares to return the semantic value
* of the token.
* @return the token identifier corresponding to the next token.
*/
int yylex() throws java.io.IOException;
/**
* Emit an errorin a user-defined way.
*
*
* @param msg The string for the error message.
*/
void yyerror(String msg);
}
/**
* The object doing lexical analysis for us.
*/
private Lexer yylexer;
/**
* Instantiates the Bison-generated parser.
* @param yylexer The scanner that will supply tokens to the parser.
*/
public LISPParser(Lexer yylexer)
{
this.yylexer = yylexer;
}
private int yynerrs = 0;
/**
* The number of syntax errors so far.
*/
public final int getNumberOfErrors() { return yynerrs; }
/**
* Print an error message via the lexer.
*
* @param msg The error message.
*/
public final void yyerror(String msg) {
yylexer.yyerror(msg);
}
private final class YYStack {
private int[] stateStack = new int[16];
private TreeNode[] valueStack = new TreeNode[16];
public int size = 16;
public int height = -1;
public final void push(int state, TreeNode value) {
height++;
if (size == height) {
int[] newStateStack = new int[size * 2];
System.arraycopy(stateStack, 0, newStateStack, 0, height);
stateStack = newStateStack;
TreeNode[] newValueStack = new TreeNode[size * 2];
System.arraycopy(valueStack, 0, newValueStack, 0, height);
valueStack = newValueStack;
size *= 2;
}
stateStack[height] = state;
valueStack[height] = value;
}
public final void pop() {
pop(1);
}
public final void pop(int num) {
// Avoid memory leaks... garbage collection is a white lie!
if (0 < num) {
java.util.Arrays.fill(valueStack, height - num + 1, height + 1, null);
}
height -= num;
}
public final int stateAt(int i) {
return stateStack[height - i];
}
public final TreeNode valueAt(int i) {
return valueStack[height - i];
}
// Print the state stack on the debug stream.
public void print(java.io.PrintStream out) {
out.print ("Stack now");
for (int i = 0; i <= height; i++) {
out.print(' ');
out.print(stateStack[i]);
}
out.println();
}
}
/**
* Returned by a Bison action in order to stop the parsing process and
* return success (<tt>true</tt>).
*/
public static final int YYACCEPT = 0;
/**
* Returned by a Bison action in order to stop the parsing process and
* return failure (<tt>false</tt>).
*/
public static final int YYABORT = 1;
/**
* Returned by a Bison action in order to start error recovery without
* printing an error message.
*/
public static final int YYERROR = 2;
/**
* Internal return codes that are not supported for user semantic
* actions.
*/
private static final int YYERRLAB = 3;
private static final int YYNEWSTATE = 4;
private static final int YYDEFAULT = 5;
private static final int YYREDUCE = 6;
private static final int YYERRLAB1 = 7;
private static final int YYRETURN = 8;
private int yyerrstatus_ = 0;
/**
* Whether error recovery is being done. In this state, the parser
* reads token until it reaches a known state, and then restarts normal
* operation.
*/
public final boolean recovering ()
{
return yyerrstatus_ == 0;
}
/** Compute post-reduction state.
* @param yystate the current state
* @param yysym the nonterminal to push on the stack
*/
private int yyLRGotoState(int yystate, int yysym) {
int yyr = yypgoto_[yysym - YYNTOKENS_] + yystate;
if (0 <= yyr && yyr <= YYLAST_ && yycheck_[yyr] == yystate)
return yytable_[yyr];
else
return yydefgoto_[yysym - YYNTOKENS_];
}
private int yyaction(int yyn, YYStack yystack, int yylen)
{
/* If YYLEN is nonzero, implement the default value of the action:
'$$ = $1'. Otherwise, use the top of the stack.
Otherwise, the following line sets YYVAL to garbage.
This behavior is undocumented and Bison
users should not rely upon it. */
TreeNode yyval = (0 < yylen) ? yystack.valueAt(yylen - 1) : yystack.valueAt(0);
switch (yyn)
{
case 2: /* Program: Elements */
if (yyn == 2)
/* "src/syntax/syntax.y":36 */
{ node = new TreeNode().addChild(yystack.valueAt (0)); yyval = node; };
break;
case 3: /* List: LeftBracket Elements RightBracket */
if (yyn == 3)
/* "src/syntax/syntax.y":38 */
{ yyval = new TreeNode("List").addChild(new TreeNode("LeftBracket")).addChild(yystack.valueAt (1)).addChild(new TreeNode("RightBracket"));};
break;
case 4: /* Elements: Element */
if (yyn == 4)
/* "src/syntax/syntax.y":40 */
{ yyval = new TreeNode("Elements").addChild(yystack.valueAt (0)); };
break;
case 5: /* Elements: Elements Element */
if (yyn == 5)
/* "src/syntax/syntax.y":40 */
{ TreeNode) yystack.valueAt (1); yyval = elem.addChild(yystack.valueAt (0)); };
break;
case 6: /* Element: Atom */
if (yyn == 6)
/* "src/syntax/syntax.y":42 */
{ yyval = yystack.valueAt (0); };
break;
case 7: /* Element: List */
if (yyn == 7)
/* "src/syntax/syntax.y":42 */
{ yyval = yystack.valueAt (0); };
break;
case 8: /* Element: Literal */
if (yyn == 8)
/* "src/syntax/syntax.y":42 */
{ yyval = new TreeNode(yystack.valueAt (0).token); };
break;
case 9: /* Atom: Identifier */
if (yyn == 9)
/* "src/syntax/syntax.y":44 */
{ yyval = new TreeNode(yystack.valueAt (0).token); };
break;
/* "syntax.java":462 */
default: break;
}
yystack.pop(yylen);
yylen = 0;
/* Shift the result of the reduction. */
int yystate = yyLRGotoState(yystack.stateAt(0), yyr1_[yyn]);
yystack.push(yystate, yyval);
return YYNEWSTATE;
}
/**
* Parse input from the scanner that was specified at object construction
* time. Return whether the end of the input was reached successfully.
*
* @return <tt>true</tt> if the parsing succeeds. Note that this does not
* imply that there were no syntax errors.
*/
public boolean parse() throws java.io.IOException
{
/* Lookahead token kind. */
int yychar = YYEMPTY_;
/* Lookahead symbol kind. */
SymbolKind yytoken = null;
/* State. */
int yyn = 0;
int yylen = 0;
int yystate = 0;
YYStack yystack = new YYStack ();
int label = YYNEWSTATE;
/* Semantic value of the lookahead. */
TreeNode yylval = null;
yyerrstatus_ = 0;
yynerrs = 0;
/* Initialize the stack. */
yystack.push (yystate, yylval);
for (;;)
switch (label)
{
/* New state. Unlike in the C/C++ skeletons, the state is already
pushed when we come here. */
case YYNEWSTATE:
/* Accept? */
if (yystate == YYFINAL_)
return true;
/* Take a decision. First try without lookahead. */
yyn = yypact_[yystate];
if (yyPactValueIsDefault (yyn))
{
label = YYDEFAULT;
break;
}
/* Read a lookahead token. */
if (yychar == YYEMPTY_)
{
yychar = yylexer.yylex ();
yylval = yylexer.getLVal();
}
/* Convert token to internal form. */
yytoken = yytranslate_ (yychar);
if (yytoken == SymbolKind.S_YYerror)
{
// The scanner already issued an error message, process directly
// to error recovery. But do not keep the error token as
// lookahead, it is too special and may lead us to an endless
// loop in error recovery. */
yychar = Lexer.YYUNDEF;
yytoken = SymbolKind.S_YYUNDEF;
label = YYERRLAB1;
}
else
{
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken.getCode();
if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode()) {
label = YYDEFAULT;
}
/* <= 0 means reduce or error. */
else if ((yyn = yytable_[yyn]) <= 0)
{
if (yyTableValueIsError(yyn)) {
label = YYERRLAB;
} else {
yyn = -yyn;
label = YYREDUCE;
}
}
else
{
/* Shift the lookahead token. */
/* Discard the token being shifted. */
yychar = YYEMPTY_;
/* Count tokens shifted since error; after three, turn off error
status. */
if (yyerrstatus_ > 0)
--yyerrstatus_;
yystate = yyn;
yystack.push(yystate, yylval);
label = YYNEWSTATE;
}
}
break;
/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state. |
`-----------------------------------------------------------*/
case YYDEFAULT:
yyn = yydefact_[yystate];
if (yyn == 0)
label = YYERRLAB;
else
label = YYREDUCE;
break;
/*-----------------------------.
| yyreduce -- Do a reduction. |
`-----------------------------*/
case YYREDUCE:
yylen = yyr2_[yyn];
label = yyaction(yyn, yystack, yylen);
yystate = yystack.stateAt(0);
break;
/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
case YYERRLAB:
/* If not already recovering from an error, report this error. */
if (yyerrstatus_ == 0)
{
++yynerrs;
if (yychar == YYEMPTY_)
yytoken = null;
yyreportSyntaxError(new Context(this, yystack, yytoken));
}
if (yyerrstatus_ == 3)
{
/* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= Lexer.YYEOF)
{
/* Return failure if at end of input. */
if (yychar == Lexer.YYEOF)
return false;
}
else
yychar = YYEMPTY_;
}
/* Else will try to reuse lookahead token after shifting the error
token. */
label = YYERRLAB1;
break;
/*-------------------------------------------------.
| errorlab -- error raised explicitly by YYERROR. |
`-------------------------------------------------*/
case YYERROR:
/* Do not reclaim the symbols of the rule which action triggered
this YYERROR. */
yystack.pop (yylen);
yylen = 0;
yystate = yystack.stateAt(0);
label = YYERRLAB1;
break;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
case YYERRLAB1:
yyerrstatus_ = 3; /* Each real token shifted decrements this. */
// Pop stack until we find a state that shifts the error token.
for (;;)
{
yyn = yypact_[yystate];
if (!yyPactValueIsDefault (yyn))
{
yyn += SymbolKind.S_YYerror.getCode();
if (0 <= yyn && yyn <= YYLAST_
&& yycheck_[yyn] == SymbolKind.S_YYerror.getCode())
{
yyn = yytable_[yyn];
if (0 < yyn)
break;
}
}
/* Pop the current state because it cannot handle the
* error token. */
if (yystack.height == 0)
return false;
yystack.pop ();
yystate = yystack.stateAt(0);
}
if (label == YYABORT)
/* Leave the switch. */
break;
/* Shift the error token. */
yystate = yyn;
yystack.push (yyn, yylval);
label = YYNEWSTATE;
break;
/* Accept. */
case YYACCEPT:
return true;
/* Abort. */
case YYABORT:
return false;
}
}
/**
* Information needed to get the list of expected tokens and to forge
* a syntax error diagnostic.
*/
public static final class Context {
Context(LISPParser parser, YYStack stack, SymbolKind token) {
yyparser = parser;
yystack = stack;
yytoken = token;
}
private LISPParser yyparser;
private YYStack yystack;
/**
* The symbol kind of the lookahead token.
*/
public final SymbolKind getToken() {
return yytoken;
}
private SymbolKind yytoken;
static final int NTOKENS = LISPParser.YYNTOKENS_;
/**
* Put in YYARG at most YYARGN of the expected tokens given the
* current YYCTX, and return the number of tokens stored in YYARG. If
* YYARG is null, return the number of expected tokens (guaranteed to
* be less than YYNTOKENS).
*/
int getExpectedTokens(SymbolKind yyarg[], int yyargn) {
return getExpectedTokens (yyarg, 0, yyargn);
}
int getExpectedTokens(SymbolKind yyarg[], int yyoffset, int yyargn) {
int yycount = yyoffset;
int yyn = yypact_[this.yystack.stateAt(0)];
if (!yyPactValueIsDefault(yyn))
{
/* Start YYX at -YYN if negative to avoid negative
indexes in YYCHECK. In other words, skip the first
-YYN actions for this state because they are default
actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST_ - yyn + 1;
int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS;
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck_[yyx + yyn] == yyx && yyx != SymbolKind.S_YYerror.getCode()
&& !yyTableValueIsError(yytable_[yyx + yyn]))
{
if (yyarg == null)
yycount += 1;
else if (yycount == yyargn)
return 0; // FIXME: this is incorrect.
else
yyarg[yycount++] = SymbolKind.get(yyx);
}
}
if (yyarg != null && yycount == yyoffset && yyoffset < yyargn)
yyarg[yycount] = null;
return yycount - yyoffset;
}
}
private int yysyntaxErrorArguments(Context yyctx, SymbolKind[] yyarg, int yyargn) {
/* There are many possibilities here to consider:
- If this state is a consistent state with a default action,
then the only way this function was invoked is if the
default action is an error action. In that case, don't
check for expected tokens because there are none.
- The only way there can be no lookahead present (in tok) is
if this state is a consistent state with a default action.
Thus, detecting the absence of a lookahead is sufficient to
determine that there is no unexpected or expected token to
report. In that case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this
state is a consistent state with a default action. There
might have been a previous inconsistent state, consistent
state with a non-default action, or user semantic action
that manipulated yychar. (However, yychar is currently out
of scope during semantic actions.)
- Of course, the expected token list depends on states to
have correct lookahead information, and it depends on the
parser not to perform extra reductions after fetching a
lookahead from the scanner and before detecting a syntax
error. Thus, state merging (from LALR or IELR) and default
reductions corrupt the expected token list. However, the
list is correct for canonical LR with one exception: it
will still contain any token that will not be accepted due
to an error action in a later state.
*/
int yycount = 0;
if (yyctx.getToken() != null)
{
if (yyarg != null)
yyarg[yycount] = yyctx.getToken();
yycount += 1;
yycount += yyctx.getExpectedTokens(yyarg, 1, yyargn);
}
return yycount;
}
/**
* Build and emit a "syntax error" message in a user-defined way.
*
* @param ctx The context of the error.
*/
private void yyreportSyntaxError(Context yyctx) {
if (yyErrorVerbose) {
final int argmax = 5;
SymbolKind[] yyarg = new SymbolKind[argmax];
int yycount = yysyntaxErrorArguments(yyctx, yyarg, argmax);
String[] yystr = new String[yycount];
for (int yyi = 0; yyi < yycount; ++yyi) {
yystr[yyi] = yyarg[yyi].getName();
}
String yyformat;
switch (yycount) {
default:
case 0: yyformat = "syntax error"; break;
case 1: yyformat = "syntax error, unexpected {0}"; break;
case 2: yyformat = "syntax error, unexpected {0}, expecting {1}"; break;
case 3: yyformat = "syntax error, unexpected {0}, expecting {1} or {2}"; break;
case 4: yyformat = "syntax error, unexpected {0}, expecting {1} or {2} or {3}"; break;
case 5: yyformat = "syntax error, unexpected {0}, expecting {1} or {2} or {3} or {4}"; break;
}
yyerror(new MessageFormat(yyformat).format(yystr));
} else {
yyerror("syntax error");
}
}
/**
* Whether the given <code>yypact_</code> value indicates a defaulted state.
* @param yyvalue the value to check
*/
private static boolean yyPactValueIsDefault(int yyvalue) {
return yyvalue == yypact_ninf_;
}
/**
* Whether the given <code>yytable_</code>
* value indicates a syntax error.
* @param yyvalue the value to check
*/
private static boolean yyTableValueIsError(int yyvalue) {
return yyvalue == yytable_ninf_;
}
private static final byte yypact_ninf_ = -4;
private static final byte yytable_ninf_ = -1;
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
private static final byte[] yypact_ = yypact_init();
private static final byte[] yypact_init()
{
return new byte[]
{
5, -4, -4, 5, 6, -4, 5, -4, -4, -3,
-4, -4, -4
};
}
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
Performed when YYTABLE does not specify something else to do. Zero
means the default is an error. */
private static final byte[] yydefact_ = yydefact_init();
private static final byte[] yydefact_init()
{
return new byte[]
{
0, 8, 9, 0, 0, 7, 2, 4, 6, 0,
1, 5, 3
};
}
/* YYPGOTO[NTERM-NUM]. */
private static final byte[] yypgoto_ = yypgoto_init();
private static final byte[] yypgoto_init()
{
return new byte[]
{
-4, -4, -4, 2, -2, -4
};
}
/* YYDEFGOTO[NTERM-NUM]. */
private static final byte[] yydefgoto_ = yydefgoto_init();
private static final byte[] yydefgoto_init()
{
return new byte[]
{
0, 4, 5, 6, 7, 8
};
}
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule whose
number is the opposite. If YYTABLE_NINF, syntax error. */
private static final byte[] yytable_ = yytable_init();
private static final byte[] yytable_init()
{
return new byte[]
{
1, 2, 3, 12, 11, 9, 10, 11, 1, 2,
3
};
}
private static final byte[] yycheck_ = yycheck_init();
private static final byte[] yycheck_init()
{
return new byte[]
{
3, 4, 5, 6, 6, 3, 0, 9, 3, 4,
5
};
}
/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
state STATE-NUM. */
private static final byte[] yystos_ = yystos_init();
private static final byte[] yystos_init()
{
return new byte[]
{
0, 3, 4, 5, 8, 9, 10, 11, 12, 10,
0, 11, 6
};
}
/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
private static final byte[] yyr1_ = yyr1_init();
private static final byte[] yyr1_init()
{
return new byte[]
{
0, 7, 8, 9, 10, 10, 11, 11, 11, 12
};
}
/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
private static final byte[] yyr2_ = yyr2_init();
private static final byte[] yyr2_init()
{
return new byte[]
{
0, 2, 1, 3, 1, 2, 1, 1, 1, 1
};
}
/* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
as returned by yylex, with out-of-bounds checking. */
private static final SymbolKind yytranslate_(int t)
{
// Last valid token kind.
int code_max = 261;
if (t <= 0)
return SymbolKind.S_YYEOF;
else if (t <= code_max)
return SymbolKind.get(yytranslate_table_[t]);
else
return SymbolKind.S_YYUNDEF;
}
private static final byte[] yytranslate_table_ = yytranslate_table_init();
private static final byte[] yytranslate_table_init()
{
return new byte[]
{
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,