我在 c# 中收到以下错误,此代码“并非所有代码路径都返回值”我正在尝试使用它创建一种编程语言。任何帮助是极大的赞赏。
private Expr ParseExpr()
{
if (this.index == this.tokens.Count)
{
throw new System.Exception("expected expression, got EOF");
}
if (this.tokens[this.index] is Text.StringBuilder)
{
string Value = ((Text.StringBuilder)this.tokens[this.index++]).ToString();
StringLiteral StringLiteral = new StringLiteral();
StringLiteral.Value = Value;
}
else if (this.tokens[this.index] is int)
{
int intvalue = (int)this.tokens[this.index++];
IntLiteral intliteral = new IntLiteral();
intliteral.Value = intvalue;
return intliteral;
}
else if (this.tokens[this.index] is string)
{
string Ident = (string)this.tokens[this.index++];
Variable var = new Variable();
var.Ident = Ident;
return var;
}
else
{
throw new System.Exception("expected string literal, int literal, or variable");
}
}