File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
src/jointyc/analysis/parser Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 1717
1818package jointyc .analysis .parser ;
1919
20+ import java .io .EOFException ;
2021import java .util .ArrayList ;
2122import java .util .Arrays ;
2223import java .util .Collections ;
@@ -219,6 +220,8 @@ public boolean equals(Object obj) {
219220
220221 private int unexpectedPosition ;
221222
223+ private boolean unexpectedEOF ;
224+
222225 /**
223226 * Store the detected direct recursions (without forwarding the lexer).
224227 * Used to detect infinite recursions.
@@ -320,13 +323,14 @@ public void setAxiom(String axiom){
320323 public SyntaxTree parse () throws UnexpectedSymbolException {
321324 expected = new HashSet <>();
322325 lexer .setStart (0 );
326+ unexpectedEOF = false ;
323327
324328 SyntaxTree root = parse (axiom );
325329
326330 cache .clear ();
327331 lruBuffer .clear ();
328332
329- if (!lexer .next ()) {
333+ if (!lexer .next () && ! unexpectedEOF ) {
330334 return root ;
331335 }
332336
@@ -357,6 +361,7 @@ private SyntaxNode parse(String ruleHead) {
357361
358362 for (String product : rule ) {
359363 lexer .setStart (lexerPos );
364+
360365 lexer .next ();
361366
362367 if (product .startsWith (TERMINAL_PREFIX )) { //terminal
@@ -383,6 +388,9 @@ private SyntaxNode parse(String ruleHead) {
383388 continue ;
384389 }
385390 }
391+ else {
392+ unexpectedEOF = true ;
393+ }
386394
387395 if (unexpectedPosition < lexer .start ())
388396 expected .clear ();
@@ -419,8 +427,10 @@ private SyntaxNode parse(String ruleHead) {
419427
420428 }
421429
422- if (accept )
430+ if (accept ) {
431+ unexpectedEOF = false ;
423432 break ;
433+ }
424434 else {
425435 node .nexts .clear ();
426436 lexerPos = lexerStart ;
You can’t perform that action at this time.
0 commit comments