【问题标题】:Peg left recursion removingPeg左递归删除
【发布时间】:2014-08-24 08:52:43
【问题描述】:

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

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

【问题讨论】:

    标签: peg pegjs


    【解决方案1】:

    应该是这样的……

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-08
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多