1

我有这个 pegjs 语法。如何删除左递归?

atom   = term
    /  "^"
    /  "_"
    /  "\\"
    /  atom "."
    /  atom "." label
    /  atom ".(" labels ")"
term = [a-zA-Z0-9]+
labels = label ("|" label)*
label  = ("+" / "-")* [A-Za-z0-9]+
4

1 回答 1

1

应该是这样的……

atomStatement =  atom "." /  atom "." label /  atom ".(" labels ")" / atom

atom   = term
/  "^"
/  "_"
/  "\\"

term = [a-zA-Z0-9]+
labels = label ("|" label)*
label  = ("+" / "-")* [A-Za-z0-9]+
于 2014-08-24T00:52:43.757 回答