0

I'm making a scripting language for one of my Arduino projects, and I needed an eval function from python. So I spent forever coding one and I think I finally did it, but there's one issue, it won't work since I'm getting the error " 'evals' does not name a type.", even though I defined it earlier on in the sketch.

I've tried changing everything about the struct and nothing is working. (eg. I tried moving the * signs for the char variables, I tried changing the spacing, removing and adding back the ";" after the struct, adding and removing typedef before, etc..)

struct evals {
  char *pointer;
  bool boolout;
  char *charout;
  int intout;
  float floatout;
};
evals eval(String input) {
  evals output;
  String inputs = input;
  char input2[inputs.length() + 1];
  inputs.toCharArray(input2, inputs.length());
  if (input[0] == '"' and input[-1] == '"') {
    inputs.remove(0, 1);
    inputs.remove(-1, 1);
    output.pointer = "charout";
    char input2[inputs.length() + 1];
    inputs.toCharArray(input2, inputs.length());
    output.charout = input2;
    return output;
  } else if (input == "true") {
    output.pointer = "boolout";
    output.boolout = true;
    return output;
  } else if (input == "false") {
    output.pointer = "boolout";
    output.boolout = false;
    return output;
  } else {
    String inputss = inputs;
    inputss.replace("0", "");
    inputss.replace("1", "");
    inputss.replace("2", "");
    inputss.replace("3", "");
    inputss.replace("4", "");
    inputss.replace("5", "");
    inputss.replace("6", "");
    inputss.replace("7", "");
    inputss.replace("8", "");
    inputss.replace("9", "");
    if (inputss.length() == 0) {
      output.pointer = "intout";
      output.intout = inputs.toInt();
      return output;
    } else {
      if (inputss[0] == "." and inputss.length() == 0) {
        output.pointer = "floatout";
        output.floatout = inputs.toFloat();
        return output;
      } else {
        for (int Variable = 0; Variable < 50; Variable++) {
          if (LocalVariables[Variable] == "") {
            break;
          } else  {
            output.pointer = "variableout";
            output.intout = Variable;
            return output;
          }
        }
      }
    }
  }
}

I expect it to return a variable of type "evals" but it just gives that error.

PyPylia
  • 387
  • 3
  • 14

1 Answers1

2

You'd have to use struct evals instead of evals as the type, unless you specify something like:

typedef struct evals evals;

(This sets the type evals equal to the type struct evals)

See the answer to this question for a decent explanation of why this is needed (TL;DR it's a holdover from c that doesn't make a ton of sense if you're new to the language).

Leo Adberg
  • 342
  • 2
  • 18
  • Do note that this isn't necessary in C++. It might be necessary in an Arduino dialect of C++ (I wouldn't know), or the OP might be using a C compiler. – chris May 05 '19 at 02:54
  • Ahhh yep you're probably right. I bet OP is actually using C + some Arduino libraries that add C++-like objects like String. – Leo Adberg May 05 '19 at 03:38
  • I'm using the standard Arduino ide, all I know about this topic is that Arduino code is based on C++ and C but I don't think its exactly the same as both. – PyPylia May 05 '19 at 08:03