我正在为表达式制作一个简单的解析器,这是我的代码:
import parsimonious as parmon
parser = parmon.Grammar(r"""
E = E "+" E / id
id = "0"/"1"/"2"/"3"/"4"/"5"/"6"/"7"/"8"/"9"
""")
code = "2+2"
print(parser.parse(code))
我收到此错误:
IncompleteParseError(text, node.end, self)
parsimonious.exceptions.IncompleteParseError: Rule 'rules' matched in its entirety, but it didn't consume all the text. The non-matching portion of the text begins with '/ id
id = "0"/"1"' (line 2, column 16).
我也尝试过 Lark-parser,但也无法解决这个问题。帮助表示赞赏。