recursive method - not all code paths return a value!
it says not all code paths return a value
private string Fisrt(string nonTerminal)
{
for (int j = 0; j < 6; j++)
{
if (Tokens[j, 0] == nonTermi开发者_JAVA百科nal)
{
if (char.IsLower((char)Tokens[j, 3][0]))
return (Tokens[j, 3]);
else
Fisrt(Tokens[j, 3]);
}
}
}
private string Fisrt(string nonTerminal)
{
for (int j = 0; j < 6; j++)
{
if (Tokens[j, 0] == nonTerminal)
{
if (char.IsLower((char)Tokens[j, 3][0]))
return (Tokens[j, 3]);
else
return Fisrt(Tokens[j, 3]);
/* ^ add a return here */
}
}
return SOMETHING;
/* ^ You also need to add some return value here */
}
You also need to decide what string value (or null) to return in the event your for
loop exits normally.
For example, what if none of the Tokens[j, 0]
, with j
values 0 to 5, is nonTerminal
?
Or, if Tokens[j, 3][0]
is never lowercase?
You should return the recursive step
`return First(Tokens[j, 3])`
and handle the cases outside the outer for
and if
.
精彩评论