Example #1
0
/**
==================== Stmt =============================================
   Grammar:
      stmt : loc '=' bool ';' | 'if' '(' bool ')' stmt | 'if' '(' bool ')' stmt 'else' stmt | 'while' '(' bool ')' stmt | 'do' stmt 'while' '(' bool ')' ';' | 'break' ';' | block | 'read' loc ';' | 'write' bool ';' 
*/
static TreeStmt p_stmt(void) {
   TreeStmt stmt = 0; // set null by default
   TokenCode code = curr()->code;
   // cases
   
   switch (code) {
      case TOK_id: {  //===== REDUCED TOK_loc
         TreeLoc l0loc = p_loc();
         eat('=');
         TreeBool l2bool = p_bool();
         eat(';');
         stmt = t_stmt_loc(l0loc, l2bool);
         break;
      }
      case TOK_if: {  
         eat(TOK_if);
         eat('(');
         TreeBool l2bool = p_bool();
         eat(')');
         TreeStmt l4stmt = p_stmt();
         stmt = t_stmt_if(l2bool, l4stmt);
         break;
      }
      case TOK_if: {  
         eat(TOK_if);
         eat('(');
         TreeBool l2bool = p_bool();
         eat(')');
         TreeStmt l4stmt = p_stmt();
         eat(TOK_else);
         TreeStmt l6stmt = p_stmt();
         stmt = t_stmt_if(l2bool, l4stmt, l6stmt);
         break;
      }
      case TOK_while: {  
         eat(TOK_while);
         eat('(');
         TreeBool l2bool = p_bool();
         eat(')');
         TreeStmt l4stmt = p_stmt();
         stmt = t_stmt_while(l2bool, l4stmt);
         break;
      }
      case TOK_do: {  
         eat(TOK_do);
         TreeStmt l1stmt = p_stmt();
         eat(TOK_while);
         eat('(');
         TreeBool l4bool = p_bool();
         eat(')');
         eat(';');
         stmt = t_stmt_do(l1stmt, l4bool);
         break;
      }
      case TOK_break: {  
         eat(TOK_break);
         eat(';');
         stmt = t_stmt_break();
         break;
      }
      case '{': {  //===== REDUCED TOK_block
         TreeBlock l0block = p_block();
         stmt = t_stmt_block(l0block);
         break;
      }
      case TOK_read: {  
         eat(TOK_read);
         TreeLoc l1loc = p_loc();
         eat(';');
         stmt = t_stmt_read(l1loc);
         break;
      }
      case TOK_write: {  
         eat(TOK_write);
         TreeBool l1bool = p_bool();
         eat(';');
         stmt = t_stmt_write(l1bool);
         break;
      }
      default:
         error_parse("stmt");
         break;
   }   

   
   return stmt;
}
Example #2
0
void
fix_gates()
{
  int where;
  struct exit_view **l;
  int set_one;
  int i;
  int dest;
  int m;

  clear_temps(T_loc);

  loop_province(where) {
    if (!in_hades(where) && !in_clouds(where) && !in_faery(where))
      continue;

    if (!province_gate_here(where))
      continue;

    fprintf(stderr, "Gate in %s\n", box_name(where));

    l = exits_from_loc_nsew(0, where);

    for (i = 0; i < ilist_len(l); i++) {
      if (loc_depth(l[i]->destination) != LOC_province)
        continue;

      if (!province_gate_here(l[i]->destination)) {
        bx[l[i]->destination]->temp = 1;
      }
    }
  }
  next_province;

  m = 1;

  do {
    set_one = FALSE;

    loop_province(where) {
      if (!in_hades(where) && !in_clouds(where) && !in_faery(where))
        continue;

      if (province_gate_here(where) || bx[where]->temp != m)
        continue;

      l = exits_from_loc_nsew(0, where);

      for (i = 0; i < ilist_len(l); i++) {
        dest = l[i]->destination;

        if (loc_depth(dest) != LOC_province)
          continue;

        if (!province_gate_here(dest) && bx[dest]->temp == 0) {
          bx[dest]->temp = m + 1;
          set_one = TRUE;
        }
      }
    }
    next_province;

    m++;
  }
  while (set_one);

  loop_province(where) {
    if (!in_hades(where) && !in_clouds(where) && !in_faery(where))
      continue;

    if (!province_gate_here(where) && bx[where]->temp < 1)
      fprintf(stderr, "error on %d\n", where);
  }
  next_province;

  loop_province(where) {
    if (!in_hades(where) && !in_clouds(where) && !in_faery(where))
      continue;

    p_loc(where)->dist_from_gate = bx[where]->temp;
  }
  next_province;
}