
void write_comment() {
  printf("; ");
  return;
}

void write_comment_no_blank() {
  printf(";");
  return;
}

void display_errors() {
  int i;
  if (error_idx == 0) {
    write_comment();
    printf("no errors found");
  }
  else {
    write_comment();
    write_int(error_idx);
    printf(" errors found");
    writeln();
    for (i = 0; i < error_idx; i++) {
      write_comment();
      printf("*** ERROR on line ");
      write_int(errors_line_number[i]);
      write_char(' ');
      switch (errors[i]) {
      case IDENTIFIER_EXPECTED:
        printf("identifier expected");
        break;
      case REST_OF_PROGRAM_IGNORED:
        printf("rest of program ignored");
        break;
      case EXPECT_TOKEN:
        {
          string_write(errors_token[i]);
          printf(" expected");
        }
        break;
      case BAD_STATEMENT:
        printf("bad statement");
        break;
      case EXPRESSION_TOO_LONG:
        printf("expression too long");
        break;
      case CONTROL_VAR_MISMATCH:
        printf("control and increment var not the same");
        break;
      case EXPECTING_INCR_DECR:
        printf("expecting ++ or --");
        break;
      case NUMBER_EXPECTED: {
          printf("number expected instead of: ");
          string_write(errors_token[i]);
        }
        break;
      case MAX_ALLOWED_FORMAL_PARAMETERS:
        printf("maximum number of allowed formal parameters exceeded");
        break;
      case MISMATCHED:
        printf("mismatched parentheses");
        break;
      case MISMATCHED2:
        printf("mismatched parentheses or misplaced comma");
        break;
      case STACK_UNDERFLOW:
        printf("stack underflow");
        break;
      case BAD_EXPRESSION:
        printf("bad expression");
        break;
      case VECTOR_POOL_EXHAUSTION:
        printf("vector pool exhaustion");
        break;
      case MAX_NUMBER_OF_CONS_CELLS:
        printf("maximum number of allowed cons cells exceeded");
        break;
      case UNDECLARED_IDENTIFIER: {
          printf("undeclared identifier: ");
          string_write(errors_token[i]);
        }
        break;
      case UNDEFINED_CONSTANT: {
          printf("undefined constant: ");
          string_write(errors_token[i]);
        }
        break;
      case BAD_HEX_NUMBER: {
          printf("bad hex number: ");
          string_write(errors_token[i]);
        }
        break;
      case HASH_TABLE_EXHAUSTION:
        printf("hash table exhaustion");
        break;
      case VECTOR_REFERENCE_OUT_OF_RANGE:
        printf("vector reference out of range");
        break;
      }
      writeln();
    }
  }
  writeln();
  return;
}

void log_error(int error, int token) {
  int i;
  if (error_idx < ERRORS_SIZE) {
    if (token_ring_idx == 0)
      i = MAX_TOKEN_RING;
    else
      i = token_ring_idx - 1;
    errors[error_idx] = error;
    errors_token[error_idx] = token;
    errors_line_number[error_idx] = token_ring_line_count[i] - 1;
    error_idx = error_idx + 1;
  }
  return;
}
