然后是 Oz 关键字
我正在尝试编写一个分词器,但遇到解析错误:
%*************************** parse error ************************
%**
%** syntax error, unexpected T_DEFAULT, expecting T_then
%**
%** in file "/Users/xxx/Programmering/Oz/Oving1/Oz_oving1_task8.oz", line 15, column 36
%** ------------------ rejected (1 error)
这是代码,我用 %=ERROR=% 标记了第 15 行和第 36 列
declare
fun {Tokenize L}
Keys Ops Token
in
Keys = ["local", "in", "if", "then", "else", "end"]
Ops = ["+", "-", "*", "/"]
case Tokenize of Head|Tail then
if {Member Head Keys} then
Token = key(Head)
elseif {Member Head Ops} then
Token = op(Head)
else
case Head of Forste|_ then
if Forste >= &a andthen Forste <= &z then % THIS IS LINE 15, COLUMN 36 = ..andthen [here]Forste..
Token = atom(Forste)
elseif
Forste >= &A andthen Forste <= &Z then
Token = id(Forste)
end
end
Token | {Tokenize Tail}
end
else
nil
end
end
知道我做错了什么吗?
I'm trying to write a tokenizer, but I'm getting a parse error:
%*************************** parse error ************************
%**
%** syntax error, unexpected T_DEFAULT, expecting T_then
%**
%** in file "/Users/xxx/Programmering/Oz/Oving1/Oz_oving1_task8.oz", line 15, column 36
%** ------------------ rejected (1 error)
Here's the code, I have marked line 15 and column 36 with %=ERROR=%
declare
fun {Tokenize L}
Keys Ops Token
in
Keys = ["local", "in", "if", "then", "else", "end"]
Ops = ["+", "-", "*", "/"]
case Tokenize of Head|Tail then
if {Member Head Keys} then
Token = key(Head)
elseif {Member Head Ops} then
Token = op(Head)
else
case Head of Forste|_ then
if Forste >= &a andthen Forste <= &z then % THIS IS LINE 15, COLUMN 36 = ..andthen [here]Forste..
Token = atom(Forste)
elseif
Forste >= &A andthen Forste <= &Z then
Token = id(Forste)
end
end
Token | {Tokenize Tail}
end
else
nil
end
end
Any idea what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经找到了解决方案:
我的列表在每个元素之间应该有空格而不是逗号 (
,
)。在《奥兹国》中,你会写
>= 然后 =<
,而不是像我一样写>= 然后 <=
(>
在=
的反面)。我在
Tokenize
上创建了一个case
,case
应该位于输入L
上。干杯!
I found the solution already:
My lists should have whitespace instead of a comma (
,
) between each element.In Oz, you write
>= andthen =<
not>= andthen <=
as I did (>
on wrong side of the=
).I made a
case
onTokenize
, thecase
should be on the inputL
.Cheers!