在 case 语句中应为 'end'
Expected 'end' in case statement
以下代码按预期编译和运行:
fun {Tokenize Lexemes}
case Lexemes of
Head|Tail then
case Head of
"+" then
operator(type:plus)|{Tokenize Tail}
else
if {String.isFloat Head} then
number(Head)|{Tokenize Tail}
else
nil
end
end
else
nil
end
end
但是,如果我添加另一个 case 子句,如下面的代码,我在编译时会收到有关缺少 'end' 语句的错误。
fun {Tokenize Lexemes}
case Lexemes of
Head|Tail then
case Head of
"+" then
operator(type:plus)|{Tokenize Tail}
"*" then
operator(type:multiply)|{Tokenize Tail}
else
if {String.isFloat Head} then
number(Head)|{Tokenize Tail}
else
nil
end
end
else
nil
end
end
错误:
** expected 'end'
** inside case phrase (at the line of the "*")
什么给了?
如果一个 case 语句中有多个分支,则必须用 []
将它们分开。例如:
case Head of "+" then
operator(type:plus)|{Tokenize Tail}
[] "*" then
operator(type:multiply)|{Tokenize Tail}
end
以下代码按预期编译和运行:
fun {Tokenize Lexemes}
case Lexemes of
Head|Tail then
case Head of
"+" then
operator(type:plus)|{Tokenize Tail}
else
if {String.isFloat Head} then
number(Head)|{Tokenize Tail}
else
nil
end
end
else
nil
end
end
但是,如果我添加另一个 case 子句,如下面的代码,我在编译时会收到有关缺少 'end' 语句的错误。
fun {Tokenize Lexemes}
case Lexemes of
Head|Tail then
case Head of
"+" then
operator(type:plus)|{Tokenize Tail}
"*" then
operator(type:multiply)|{Tokenize Tail}
else
if {String.isFloat Head} then
number(Head)|{Tokenize Tail}
else
nil
end
end
else
nil
end
end
错误:
** expected 'end'
** inside case phrase (at the line of the "*")
什么给了?
如果一个 case 语句中有多个分支,则必须用 []
将它们分开。例如:
case Head of "+" then
operator(type:plus)|{Tokenize Tail}
[] "*" then
operator(type:multiply)|{Tokenize Tail}
end