Skip to content

Commit

Permalink
Throw compilation exception if there are unmatching loops
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Dec 10, 2016
1 parent 2223b0c commit c3f90c8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/groovy/net/zomis/brainf/model/ast/tree/Parser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.zomis.brainf.model.ast.tree;

import net.zomis.brainf.BrainfuckCompilationException;
import net.zomis.brainf.model.ast.BFToken;
import net.zomis.brainf.model.ast.CommentToken;
import net.zomis.brainf.model.ast.GroovyToken;
Expand Down Expand Up @@ -69,6 +70,11 @@ public SyntaxTree parse(List<Token> tokens) {
inner.syntax.add(syntax);
}

if (depth.size() > 1) {
int tooManyStartedLoops = depth.size() - 1;
throw new BrainfuckCompilationException("There are " + tooManyStartedLoops + " too many started loops.");
}

return depth.pop();
}

Expand Down

0 comments on commit c3f90c8

Please sign in to comment.