以下代码按预期编译并运行:
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 "*")
是什么给出了?
答案 0 :(得分:1)
如果case语句中有多个分支,则必须将它们与[]
分开。例如:
case Head of "+" then
operator(type:plus)|{Tokenize Tail}
[] "*" then
operator(type:multiply)|{Tokenize Tail}
end