crazy4s
asked on
error: not all code paths return a value
Hi all,
I'm getting this error for the below program, can anyone figure where is the issue?
error CS0161: 'AbstractSyntax.Parser.typ e()': not all code paths return a value
in my parser.cs:
in my abstractsyntax.cs:
I'm getting this error for the below program, can anyone figure where is the issue?
error CS0161: 'AbstractSyntax.Parser.typ
in my parser.cs:
private Type type() <-- error
{
Type t = null;
switch (current_token.getType())
{
case Token.TokenType.Int:
case Token.TokenType.Char:
case Token.TokenType.Float:
case Token.TokenType.Bool:
t = new Type(current_token.toString());
current_token = mylexer.next();
return t;
default:
Console.WriteLine("Syntax error: line " + mylexer.getCurrentLine() + " expecting: int, char, bool, or float" + "; saw: " + current_token.getType() + "value is " + current_token.toString());
current_token = mylexer.next();
error_flag = true;
break;
}
}
in my abstractsyntax.cs:
public class Type
{
readonly static String INTEGER = "int";
readonly static String BOOLEAN = "bool";
readonly static String FLOAT = "float";
readonly static String CHAR = "char";
String id;
public Type(String t)
{
id = t;
}
public bool isInt()
{
return id.Equals(INTEGER);
}
public bool isBool()
{
return id.Equals(BOOLEAN);
}
public bool isFloat()
{
return id.Equals(FLOAT);
}
public bool isChar()
{
return id.Equals(CHAR);
}
public String toString()
{
return toStringIndented("");
}
public String toStringIndented(String indent)
{
return indent + "Type(" + id + ")";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
instead of Console.Write should i return the error string?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so the return t outside of the switch case will return a null if is an error, right?
You can return it from within the switch statement if you wished.
Currently it either returns from within the switch exlpicitly (line 12: return t;) or it exits the switch (default) because there is no explicit return statement
Currently it either returns from within the switch exlpicitly (line 12: return t;) or it exits the switch (default) because there is no explicit return statement
ASKER