Skip to content

Commit 50d8d45

Browse files
committed
Fixed a very little bug into the StandardParser class
1 parent dc5ca82 commit 50d8d45

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

jar/JointyC-v2.0.0.jar

-2.18 KB
Binary file not shown.

src/jointyc/analysis/parser/StandardParser.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package jointyc.analysis.parser;
1919

20+
import java.io.EOFException;
2021
import java.util.ArrayList;
2122
import java.util.Arrays;
2223
import 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;

0 commit comments

Comments
 (0)