Search code examples
pegpegjs

Peg left recursion removing


I have this pegjs grammar. How can I remove the left recursion from?

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

Solution

  • It should be something like that...

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