Help On ROV code (Combining EV3 and Arduino)

What this code does is
->Get data from EV3 ultrasound as either 1 or nothing
->Then it gets the data and if the data is 1, the servo motor turns.

#include "DualMC33926MotorShield.h" //library
#include <Wire.h> //library
#define SLAVE_ADDRESS 0x04
#include <Servo.h> //library

Servo myservo;
void stopIfFault()
{
if (md.getFault())
{
Serial.println("fault");
while(1);
}
}
int state;
int pos = 0; //position
void setup()
{
myservo.attach(9); //pin for the servo
Serial.begin(9600);
pinMode(pos, OUTPUT);
Serial.println("Dual MC33926 Motor Shield");
md.init();
Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveData);
Wire.onRequest(sendData);
Serial.begin(9600);
Serial.println("Ready!");
}

int val,flag = 0;
void loop()
{
if(flag==1)
{
Serial.print("active");
flag=0;
}
}
void receiveData(int byteCount)
{
while(Wire.available()>0)
{
val=Wire.read();
flag=1;
}
}
// callback for sending data
void sendData()
{
Wire.write(0x45);
}
// Serial.flush();
if (Serial.available() > 0) {
if (Serial.peek() == '1') {
Serial.read();
state = Serial.parseInt();
for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
while (Serial.available() > 0) {
Serial.read();
}

Currently I'm getting the message 'recieveData' was not declared in this scope.
I am using the dexter industries EV3 to Arduino connector.

Help.

I can't even Auto Format your code, so there isn't a hope in hell that it will compile.

void sendData()
{
  Wire.write(0x45);
}
    // Serial.flush();
if (Serial.available() > 0) {
    if (Serial.peek() == '1') {
      Serial.read();
      state = Serial.parseInt();
    for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
    }
    while (Serial.available() > 0) {
      Serial.read();
    }

Care to explain what you think you are doing here? ALL executable code MUDT be in a function, not randomly splattered here and there.