Fix tokens after main function
This commit is contained in:
parent
2edeaaaee3
commit
e1aefeba40
2 changed files with 9 additions and 1 deletions
|
|
@ -40,7 +40,11 @@ public class Parser {
|
|||
}
|
||||
|
||||
public ProgramTree parseProgram() {
|
||||
return new ProgramTree(List.of(parseFunction()));
|
||||
ProgramTree programTree = new ProgramTree(List.of(parseFunction()));
|
||||
if (this.tokenSource.hasMore()) {
|
||||
throw new ParseException("expected end of input but got " + this.tokenSource.peek());
|
||||
}
|
||||
return programTree;
|
||||
}
|
||||
|
||||
private FunctionTree parseFunction() {
|
||||
|
|
|
|||
|
|
@ -75,6 +75,10 @@ public class TokenSource {
|
|||
return token;
|
||||
}
|
||||
|
||||
public boolean hasMore() {
|
||||
return this.idx < this.tokens.size();
|
||||
}
|
||||
|
||||
private void expectHasMore() {
|
||||
if (this.idx >= this.tokens.size()) {
|
||||
throw new ParseException("reached end of file");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue