[英]Treetop seems to fail on a simple grammar (5 rules)
我正在嘗試為C的子集編寫一個解析器。
樹頂的行為很難在這種簡單(進一步簡化)的語法上進行分析。
grammar Shyc
rule functionDef
type space identifier '(' ')' bloc
end
rule type
'int'
end
rule bloc
'{' '}'
end
rule identifier
[a-zA-Z] [a-zA-Z_]*
end
rule space
[\s]+
end
end
我的測試用例是“ int main(){}”
並且來自樹梢的錯誤消息是:
error at line 1, column 9
failure reason : Expected [a-zA-Z_] at line 1, column 9 (byte 9) after
compiler.rb:25:in `parse': Parse error (RuntimeError)
from compiler.rb:73:in `<main>'enter
因此問題在於標識符規則...
treetop的版本:1.5.3和Ruby 2.1.1
任何想法 ?
問題是我的測試用例在一個單獨的文件中,在末尾有一個補充的行尾\\ n,並且這里測試的語法沒有指定如何使用它。
這是解決問題的代碼。 正如此處在Treetop的郵件列表上所討論的那樣,該錯誤很奇怪,並且在某種程度上具有誤導性,但是通常很難自動發送清晰的消息。
grammar Shyc
rule functionDef
type space identifier '(' ')' bloc space?
end
rule type
'int'
end
rule bloc
'{' '}'
end
rule identifier
[a-zA-Z] [a-zA-Z_]*
end
rule space
[\s\n]+
end
結束
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.