Compilation error: expected primary-expression before '}' token

Got error "Compilation error: expected primary-expression before '}' token" but I cannot find the error

Note this code is not finished, tested, or simplified yet

#include <Stepper.h>
#define X_STP 2 // x -axis stepper control
#define Y_STP 3 // y -axis stepper control
#define Z_STP 4 // z -axis stepper control
#define X_DIR 5 // X -axis stepper motor direction control
#define Y_DIR 6 // y -axis stepper motor direction control
#define Z_DIR 7 // z axis stepper motor direction control
#define EN 8 // stepper motor enable , active low
#define X_ENDSTOP 9
#define Y_ENDSTOP 10
#define Z_ENDSTOP 11

//Move motors and direction
void step (boolean dir, byte dirPin, byte stepperPin, int steps) {
  digitalWrite (dirPin, dir);
  delay (50);
  for (int i = 0; i < steps; i++) {
    digitalWrite (stepperPin, HIGH);
    delayMicroseconds (800);
    digitalWrite (stepperPin, LOW);
    delayMicroseconds (800);
  } 
}

void setup () {
  pinMode (X_DIR, OUTPUT); pinMode (X_STP, OUTPUT);
  pinMode (Y_DIR, OUTPUT); pinMode (Y_STP, OUTPUT);
  pinMode (Z_DIR, OUTPUT); pinMode (Z_STP, OUTPUT);
  pinMode (EN, OUTPUT);
  digitalWrite (EN, LOW);
  int endstopStateZ = 0;
  bool Ready = 0;
  delay(250);
  // Move to Home endstops
  while (endstopStateZ == 0) {
    step (false, Z_DIR, Z_STP, 1);
    endstopStateZ = digitalRead(11);
  }
  int endstopStateY = 0;
  delay(250);
  while (endstopStateY == 0) {
    step (false, Y_DIR, Y_STP, 1);
    endstopStateY = digitalRead(10);
  }
  int endstopStateX = 0;
  delay(250);
  while (endstopStateX == 0) {
    step (false, X_DIR, X_STP, 1);
    endstopStateX = digitalRead(9);
  }
  delay(250);
  // Go to home position
  step (true, X_DIR, X_STP, 100);
  step (true, Y_DIR, Y_STP, 100);
  step (true, Z_DIR, Z_STP, 100);
}

void loop () {
  bool Ready = false;
  char Position1 = 0;
  char Position2 = 0;
  char Position3 = 0;
  char Position4 = 0;
  char Position5 = 0;
  char Position6 = 0;
  char Position7 = 0;
  char Position8 = 0;
  char Position9 = 0;
  char Position10 = 0;
  char Position11 = 0;
  char Position12 = 0;
  char Position13 = 0;
  char Position14 = 0;
  char Position15 = 0;
  char Position16 = 0;
  char Position17 = 0;
  char Position18 = 0;
  char Position19 = 0;
  char Position20 = 0;
  char Position21 = 0;
  char Position22 = 0;
  char Position23 = 0;
  char Position24 = 0;
  char Position25 = 0;
  char Position26 = 0;
  char Position27 = 0;
  char Position28 = 0;
  char Position29 = 0;
  char Position30 = 0;
  char Position31 = 0;
  char Position32 = 0;
  char Position33 = 0;
  char Position34 = 0;
  int spindlePin = 9;
  int endstopStateX = digitalRead(9);
  int endstopStateY = digitalRead(10);
  int endstopStateZ = digitalRead(11);
  if (endstopStateX == 0 && endstopStateY == 0 && endstopStateZ == 0) {
    bool Ready = true;
  }
  if (Ready == true) {
    //Pick up card
    step (true, Z_DIR, Z_STP, 600);
    digitalWrite(12, HIGH);
    step (false, Z_DIR, Y_STP, 600);
    
    //Look for position
    //This array is temporary and will be obtained from a file or given by a serial connection
    const char* myArray [] = {"cmd","a25","ced","cei","lwn","sor"};
    for (char Tempval1 : myArray) {
      Test:
      if (Position1 == Tempval1) {goto P1;}
      if (Position2 == Tempval1) {goto P2;}
      if (Position3 == Tempval1) {goto P3;}
      if (Position4 == Tempval1) {goto P4;}
      if (Position5 == Tempval1) {goto P5;}
      if (Position6 == Tempval1) {goto P6;}
      if (Position7 == Tempval1) {goto P7;}
      if (Position8 == Tempval1) {goto P8;}
      if (Position9 == Tempval1) {goto P9;}
      if (Position10 == Tempval1) {goto P10;}
      if (Position11 == Tempval1) {goto P11;}
      if (Position12 == Tempval1) {goto P12;}
      if (Position13 == Tempval1) {goto P13;}
      if (Position14 == Tempval1) {goto P14;}
      if (Position15 == Tempval1) {goto P15;}
      if (Position16 == Tempval1) {goto P16;}
      if (Position17 == Tempval1) {goto P17;}
      if (Position18 == Tempval1) {goto P18;}
      if (Position19 == Tempval1) {goto P19;}
      if (Position20 == Tempval1) {goto P20;}
      if (Position21 == Tempval1) {goto P21;}
      if (Position22 == Tempval1) {goto P22;}
      if (Position23 == Tempval1) {goto P23;}
      if (Position24 == Tempval1) {goto P24;}
      if (Position25 == Tempval1) {goto P25;}
      if (Position26 == Tempval1) {goto P26;}
      if (Position27 == Tempval1) {goto P27;}
      if (Position28 == Tempval1) {goto P28;}
      if (Position29 == Tempval1) {goto P29;}
      if (Position30 == Tempval1) {goto P30;}
      if (Position31 == Tempval1) {goto P31;}
      if (Position32 == Tempval1) {goto P32;}
      if (Position33 == Tempval1) {goto P33;}
      if (Position34 == Tempval1) {goto P34;}
      if (Position1 == 0) {Position1 = Tempval1; goto Test;}
      if (Position2 == 0) {Position2 = Tempval1; goto Test;}
      if (Position3 == 0) {Position3 = Tempval1; goto Test;}
      if (Position4 == 0) {Position4 = Tempval1; goto Test;}
      if (Position5 == 0) {Position5 = Tempval1; goto Test;}
      if (Position6 == 0) {Position6 = Tempval1; goto Test;}
      if (Position7 == 0) {Position7 = Tempval1; goto Test;}
      if (Position8 == 0) {Position8 = Tempval1; goto Test;}
      if (Position9 == 0) {Position9 = Tempval1; goto Test;}
      if (Position10 == 0) {Position10 = Tempval1; goto Test;}
      if (Position11 == 0) {Position11 = Tempval1; goto Test;}
      if (Position12 == 0) {Position12 = Tempval1; goto Test;}
      if (Position13 == 0) {Position13 = Tempval1; goto Test;}
      if (Position14 == 0) {Position14 = Tempval1; goto Test;}
      if (Position15 == 0) {Position15 = Tempval1; goto Test;}
      if (Position16 == 0) {Position16 = Tempval1; goto Test;}
      if (Position17 == 0) {Position17 = Tempval1; goto Test;}
      if (Position18 == 0) {Position18 = Tempval1; goto Test;}
      if (Position19 == 0) {Position19 = Tempval1; goto Test;}
      if (Position20 == 0) {Position20 = Tempval1; goto Test;}
      if (Position21 == 0) {Position21 = Tempval1; goto Test;}
      if (Position22 == 0) {Position22 = Tempval1; goto Test;}
      if (Position23 == 0) {Position23 = Tempval1; goto Test;}
      if (Position24 == 0) {Position24 = Tempval1; goto Test;}
      if (Position25 == 0) {Position25 = Tempval1; goto Test;}
      if (Position26 == 0) {Position26 = Tempval1; goto Test;}
      if (Position27 == 0) {Position27 = Tempval1; goto Test;}
      if (Position28 == 0) {Position28 = Tempval1; goto Test;}
      if (Position29 == 0) {Position29 = Tempval1; goto Test;}
      if (Position30 == 0) {Position30 = Tempval1; goto Test;}
      if (Position31 == 0) {Position31 = Tempval1; goto Test;}
      if (Position32 == 0) {Position32 = Tempval1; goto Test;}
      if (Position33 == 0) {Position33 = Tempval1; goto Test;}
      if (Position34 == 0) {Position34 = Tempval1; goto Test;}
      goto P34;


      //Move to X Y position
      //modify distances as needed
      P1:
      step (true, X_DIR, X_STP, 100);
      step (true, Y_DIR, Y_STP, 0);
      goto Drop;
      step (false, X_DIR, X_STP, 100);
      step (false, Y_DIR, Y_STP, 0);
      goto EndArrayLoop;

      P2:
      step (true, X_DIR, X_STP, 200);
      step (true, Y_DIR, Y_STP, 0);
      goto Drop;
      step (false, X_DIR, X_STP, 200);
      step (false, Y_DIR, Y_STP, 0);
      goto EndArrayLoop;

      P3:
      step (true, X_DIR, X_STP, 300);
      step (true, Y_DIR, Y_STP, 0);
      goto Drop;
      step (false, X_DIR, X_STP, 300);
      step (false, Y_DIR, Y_STP, 0);
      goto EndArrayLoop;

      P4:
      step (true, X_DIR, X_STP, 400);
      step (true, Y_DIR, Y_STP, 0);
      goto Drop;
      step (false, X_DIR, X_STP, 400);
      step (false, Y_DIR, Y_STP, 0);
      goto EndArrayLoop;

      P5:
      step (true, X_DIR, X_STP, 500);
      step (true, Y_DIR, Y_STP, 0);
      goto Drop;
      step (false, X_DIR, X_STP, 500);
      step (false, Y_DIR, Y_STP, 0);
      goto EndArrayLoop;

      P6:
      step (true, X_DIR, X_STP, 600);
      step (true, Y_DIR, Y_STP, 0);
      goto Drop;
      step (false, X_DIR, X_STP, 600);
      step (false, Y_DIR, Y_STP, 0);
      goto EndArrayLoop;

      P7:
      step (true, X_DIR, X_STP, 0);
      step (true, Y_DIR, Y_STP, 200);
      goto Drop;
      step (false, X_DIR, X_STP, 0);
      step (false, Y_DIR, Y_STP, 200);
      goto EndArrayLoop;

      P8:
      step (true, X_DIR, X_STP, 100);
      step (true, Y_DIR, Y_STP, 200);
      goto Drop;
      step (false, X_DIR, X_STP, 100);
      step (false, Y_DIR, Y_STP, 200);
      goto EndArrayLoop;

      P9:
      step (true, X_DIR, X_STP, 200);
      step (true, Y_DIR, Y_STP, 200);
      goto Drop;
      step (false, X_DIR, X_STP, 200);
      step (false, Y_DIR, Y_STP, 200);
      goto EndArrayLoop;

      P10:
      step (true, X_DIR, X_STP, 300);
      step (true, Y_DIR, Y_STP, 200);
      goto Drop;
      step (false, X_DIR, X_STP, 300);
      step (false, Y_DIR, Y_STP, 200);
      goto EndArrayLoop;

      P11:
      step (true, X_DIR, X_STP, 400);
      step (true, Y_DIR, Y_STP, 200);
      goto Drop;
      step (false, X_DIR, X_STP, 400);
      step (false, Y_DIR, Y_STP, 200);
      goto EndArrayLoop;

      P12:
      step (true, X_DIR, X_STP, 500);
      step (true, Y_DIR, Y_STP, 200);
      goto Drop;
      step (false, X_DIR, X_STP, 500);
      step (false, Y_DIR, Y_STP, 200);
      goto EndArrayLoop;

      P13:
      step (true, X_DIR, X_STP, 600);
      step (true, Y_DIR, Y_STP, 200);
      goto Drop;
      step (false, X_DIR, X_STP, 600);
      step (false, Y_DIR, Y_STP, 200);
      goto EndArrayLoop;

      P14:
      step (true, X_DIR, X_STP, 0);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 0);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P15:
      step (true, X_DIR, X_STP, 100);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 100);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P16:
      step (true, X_DIR, X_STP, 200);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 200);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P17:
      step (true, X_DIR, X_STP, 300);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 300);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P18:
      step (true, X_DIR, X_STP, 400);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 400);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P19:
      step (true, X_DIR, X_STP, 500);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 500);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P20:
      step (true, X_DIR, X_STP, 600);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 600);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P21:
      step (true, X_DIR, X_STP, 0);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 0);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P22:
      step (true, X_DIR, X_STP, 100);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 100);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P23:
      step (true, X_DIR, X_STP, 200);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 200);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P24:
      step (true, X_DIR, X_STP, 300);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 300);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P25:
      step (true, X_DIR, X_STP, 400);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 400);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P26:
      step (true, X_DIR, X_STP, 500);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 500);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P27:
      step (true, X_DIR, X_STP, 600);
      step (true, Y_DIR, Y_STP, 400);
      goto Drop;
      step (false, X_DIR, X_STP, 600);
      step (false, Y_DIR, Y_STP, 400);
      goto EndArrayLoop;

      P28:
      step (true, X_DIR, X_STP, 0);
      step (true, Y_DIR, Y_STP, 600);
      goto Drop;
      step (false, X_DIR, X_STP, 0);
      step (false, Y_DIR, Y_STP, 600);
      goto EndArrayLoop;

      P29:
      step (true, X_DIR, X_STP, 100);
      step (true, Y_DIR, Y_STP, 600);
      goto Drop;
      step (false, X_DIR, X_STP, 100);
      step (false, Y_DIR, Y_STP, 600);
      goto EndArrayLoop;

      P30:
      step (true, X_DIR, X_STP, 200);
      step (true, Y_DIR, Y_STP, 600); 
      goto Drop;
      step (false, X_DIR, X_STP, 200);
      step (false, Y_DIR, Y_STP, 600);
      goto EndArrayLoop;

      P31:
      step (true, X_DIR, X_STP, 300);
      step (true, Y_DIR, Y_STP, 600); 
      goto Drop;
      step (false, X_DIR, X_STP, 300);
      step (false, Y_DIR, Y_STP, 600);
      goto EndArrayLoop;

      P32:
      step (true, X_DIR, X_STP, 400);
      step (true, Y_DIR, Y_STP, 600);
      goto Drop;
      step (false, X_DIR, X_STP, 400);
      step (false, Y_DIR, Y_STP, 600); 
      goto EndArrayLoop;

      P33:
      step (true, X_DIR, X_STP, 500);
      step (true, Y_DIR, Y_STP, 600);
      goto Drop;
      step (false, X_DIR, X_STP, 500); 
      step (false, Y_DIR, Y_STP, 600); 
      goto EndArrayLoop;

      P34:
      step (true, X_DIR, X_STP, 600);
      step (true, Y_DIR, Y_STP, 600);
      goto Drop; 
      step (false, X_DIR, X_STP, 600); 
      step (false, Y_DIR, Y_STP, 600);
      goto EndArrayLoop;
      
      Drop:
      //Drop card
      step (true, Z_DIR, Z_STP, 600);
      digitalWrite(12, LOW);
      step (false, Z_DIR, Y_STP, 600);
      return;
      EndArrayLoop:
    }
  } 
}

I think the last time I saw that many goto's in a program, it was written in BASIC.

Consider this sentence from cppreference.com on labels and the cause of your error message should be obvious:

Any statement can be labeled , by providing a name followed by a colon before the statement itself.

Bolding emphasis is mine.

By the way, I don't think this will do what you think it will:

Nor, I think, will any of these statements once you fix the previous problem:

I figured it out. It's because my last Label was empty. I'm not expect this to work yet and it's still very ugly but i've only been working on it for 2 days so far

Please take this advice. Stop what you are doing. You are like a blind man wandering far off the path. I can sort of see where you're headed and in about two or three steps it is going to become nearly impossible.

Until you can write what you have now without any goto or labels, you are not ready yet. You still need to learn how to use the language.

There is a very good reason that the goto concept got replaced with loops like while and for a long time ago. And nobody uses them anymore except in very rare and particular circumstances. What lies further down the road you are on is frustration.

Even BASIC ended up having GOSUB that you could return from. Because GOTO is so hard to program with.

Read about arrays, functions

Where’s the erred message ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.