Skip to content

Commit

Permalink
Add initial debug support for the interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
Thihup committed May 8, 2024
1 parent 679c2df commit 7cee6c4
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public Node visitAlgorithm(VisuAlgParser.AlgorithmContext ctx) {

@Override
public Node visitDeclarations(VisuAlgParser.DeclarationsContext ctx) {
if (ctx.children == null) {
return CompundNode.EMPTY;
}
List<Node> list = ctx.children.stream()
.map(this::visit)
.filter(Objects::nonNull)
Expand Down Expand Up @@ -364,7 +367,7 @@ public Node visitExpr(VisuAlgParser.ExprContext ctx) {
if (ctx.parenExpression() instanceof VisuAlgParser.ParenExpressionContext parenExpressionContext) {
return visit(parenExpressionContext.expr());
}
if (ctx.SUB() != null) {
if (ctx.SUB() != null && ctx.expr().size() == 1) {
return new NegNode(visit(ctx.expr(0)), fromRuleContext(ctx));
}
if (ctx.NOT() != null) {
Expand Down Expand Up @@ -469,7 +472,7 @@ public Node visitTimerCommand(VisuAlgParser.TimerCommandContext ctx) {

@Override
public Node visitPausaCommand(VisuAlgParser.PausaCommandContext ctx) {
return new PausaCommandNode(fromRuleContext(ctx));
return new PausaCommandNode(EmptyNode.INSTANCE, fromRuleContext(ctx));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,17 @@ record PowNode(Node left, Node right, Optional<Location> location) implements Bi

sealed interface BooleanNode extends CommandNode, ExpressionNode {}

record AndNode(Node left, Node right, Optional<Location> location) implements BooleanNode, BinaryNode {
sealed interface RelationalNode extends BinaryNode, BooleanNode {}

record AndNode(Node left, Node right, Optional<Location> location) implements RelationalNode {
public AndNode {
Objects.requireNonNull(left);
Objects.requireNonNull(right);
Objects.requireNonNull(location);
}
}

record OrNode(Node left, Node right, Optional<Location> location) implements BooleanNode, BinaryNode {
record OrNode(Node left, Node right, Optional<Location> location) implements RelationalNode {
public OrNode {
Objects.requireNonNull(left);
Objects.requireNonNull(right);
Expand All @@ -466,7 +468,6 @@ record NotNode(Node expr, Optional<Location> location) implements BooleanNode {
}
}

sealed interface RelationalNode extends BinaryNode {}

record EqNode(Node left, Node right, Optional<Location> location) implements RelationalNode {
public EqNode {
Expand Down Expand Up @@ -551,7 +552,7 @@ record TimerCommandNode(boolean on, int value, Optional<Location> location) impl
}
}

record PausaCommandNode(Optional<Location> location) implements CommandNode {
record PausaCommandNode(Node node, Optional<Location> location) implements CommandNode {
public PausaCommandNode {
Objects.requireNonNull(location);
}
Expand Down
5 changes: 5 additions & 0 deletions dev.thihup.jvisualg.ide/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<artifactId>dev.thihup.jvisualg.lsp</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.thihup.jvisualg</groupId>
<artifactId>dev.thihup.jvisualg.interpreter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
Expand Down
Loading

0 comments on commit 7cee6c4

Please sign in to comment.