I’m trying to figure out why I’m getting this error:
switch (token.type.GetName())
{
case PascalTokenType.BEGIN.name: // ERROR: A CONSTANT VALUE IS EXPECTED
{
CompoundStatementParser compoundParser = new CompoundStatementParser(this);
statementNode = compoundParser.parse(token);
break;
}
}
GetName() and name both return strings. This is what the object looks like:
public static readonly PascalTokenType BEGIN = new PascalTokenType("BEGIN");
I know I could get around this problem by changing it to an if statement but when this is complete I’m going to have at least 20 conditions so I’d rather not. I’m supposing it’s because BEGIN.name isn’t assigned until runtime?
Yeah, you have the right idea. The problem is that this value could change at runtime, which the compiler doesn’t like.