creating:actions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
creating:actions [2026/11/19 01:37] – Fixed OR/EXISTS state exploration bug, and made ENABLED accept partial states ahelwercreating:actions [2026/11/19 02:03] (current) – Fixed input handling ahelwer
Line 285: Line 285:
  
 Now we can write the central ''getNextStates()'' loop: Now we can write the central ''getNextStates()'' loop:
-<code java [highlight_lines_extra="2,3,4,5,6,7"]>+<code java [highlight_lines_extra="2,3,4,5,6,7,8,9"]>
       while (!possibleNext.isEmpty()) {       while (!possibleNext.isEmpty()) {
         Map<String, Object> trunk = possibleNext.iterator().next();         Map<String, Object> trunk = possibleNext.iterator().next();
Line 547: Line 547:
 <code java [highlight_lines_extra="8,9,10,11,12"]> <code java [highlight_lines_extra="8,9,10,11,12"]>
     List<Map<String, Object>> nextStates =     List<Map<String, Object>> nextStates =
-      interpreter.getNextStates(action.location, action.expression, 547);+      interpreter.getNextStates(action.location, action.expression, false);
     if (nextStates.isEmpty()) {     if (nextStates.isEmpty()) {
       action.accept(interpreter);       action.accept(interpreter);
Line 573: Line 573:
 If there are multiple possible next states, the user is prompted to choose one: If there are multiple possible next states, the user is prompted to choose one:
 <code java> <code java>
-  private static Map<String, Object> pickNext(List<Map<String, Object>> nextStates) {+  private static Map<String, Object> pickNext(List<Map<String, Object>> nextStates) throws IOException {
     if (nextStates.size() == 1) {     if (nextStates.size() == 1) {
       return nextStates.get(0);       return nextStates.get(0);
Line 583: Line 583:
  
       System.out.print("> ");       System.out.print("> ");
-      try (java.util.Scanner in = new java.util.Scanner(System.in)) { +      return nextStates.get(Integer.parseInt(reader.readLine()));
-        return nextStates.get(in.nextInt()); +
-      }+
     }     }
   }   }
 +</code>
 +
 +Since we are reading from ''System.in'' here, the ''throws IOException'' clause percolates back up the call stack:
 +<code java [highlight_lines_extra="1"]>
 +  private static void tryStep(Stmt.Print action) throws IOException {
 +    Object result = interpreter.executeBlock(action.expression, interpreter.globals);
 +</code>
 +<code java [highlight_lines_extra="1"]>
 +  private static void run(String source, boolean replMode) throws IOException {
 +    Scanner scanner = new Scanner(source);
 </code> </code>
  
  • creating/actions.1795052255.txt.gz
  • Last modified: 2026/11/19 01:37
  • by ahelwer