Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| creating:actions [2025/08/26 22:40] – Use goToState() instead of setNextState() and step() ahelwer | creating:actions [2025/11/03 23:08] (current) – One more instanceof-cast ahelwer | ||
|---|---|---|---|
| Line 198: | Line 198: | ||
| This requires modifying the '' | This requires modifying the '' | ||
| If the '' | If the '' | ||
| - | <code java [highlight_lines_extra=" | + | <code java [highlight_lines_extra=" |
| case EQUAL: | case EQUAL: | ||
| - | if (left instanceof UnboundVariable) { | + | if (left instanceof UnboundVariable |
| - | UnboundVariable var = (UnboundVariable)left; | + | |
| next.put(var.name().lexeme, | next.put(var.name().lexeme, | ||
| return true; | return true; | ||
| Line 339: | Line 338: | ||
| Actions like '' | Actions like '' | ||
| Add the following code to the '' | Add the following code to the '' | ||
| - | <code java [highlight_lines_extra=" | + | <code java [highlight_lines_extra=" |
| case IN: | case IN: | ||
| checkSetOperand(expr.operator, | checkSetOperand(expr.operator, | ||
| - | if (left instanceof UnboundVariable) { | + | if (left instanceof UnboundVariable |
| - | UnboundVariable var = (UnboundVariable)left; | + | |
| Map< | Map< | ||
| for (Object element : (Set<?> | for (Object element : (Set<?> | ||
| Line 410: | Line 408: | ||
| private void checkIsValue(Object... operands) { | private void checkIsValue(Object... operands) { | ||
| for (Object operand : operands) { | for (Object operand : operands) { | ||
| - | if (operand instanceof UnboundVariable) { | + | if (operand instanceof UnboundVariable |
| - | UnboundVariable var = (UnboundVariable)operand; | + | |
| throw new RuntimeError(var.name(), | throw new RuntimeError(var.name(), | ||
| } | } | ||
| Line 420: | Line 417: | ||
| In our '' | In our '' | ||
| Also, two values can only be compared for equality if they are both defined: | Also, two values can only be compared for equality if they are both defined: | ||
| - | <code java [highlight_lines_extra=" | + | <code java [highlight_lines_extra=" |
| case EQUAL: | case EQUAL: | ||
| - | if (left instanceof UnboundVariable) { | + | if (left instanceof UnboundVariable |
| - | UnboundVariable var = (UnboundVariable)left; | + | |
| checkIsValue(right); | checkIsValue(right); | ||
| next.put(var.name().lexeme, | next.put(var.name().lexeme, | ||
| Line 476: | Line 472: | ||
| if (replMode && statements.size() == 1 | if (replMode && statements.size() == 1 | ||
| - | && statements.get(0) instanceof Stmt.Print) { | + | && statements.get(0) instanceof Stmt.Print |
| - | tryStep((Stmt.Print)statements.get(0)); | + | tryStep(action); |
| } else { | } else { | ||
| interpreter.interpret(statements); | interpreter.interpret(statements); | ||
| Line 571: | Line 567: | ||
| Now we can put it all together and build a real model checker in [[creating: | Now we can put it all together and build a real model checker in [[creating: | ||
| - | [[creating: | + | [[creating: |