foo123 / editor-grammar

invariant codebase of editor-grammar (codemirror-grammar, ace-grammar,prism-grammar,syntaxhighlighter-grammar, highlightjs-grammar,..)
https://foo123.github.io/
19 stars 7 forks source link

Left-recursive in syntax not working #2

Closed zcao closed 6 years ago

zcao commented 7 years ago

In the manual, it says

a syntax token can contain (direct or indirect) recursive references to itself ( note: some rule factoring may be needed, to avoid grammar left-recursion or ambiguity )

When I define left-recursive rule in Syntax, I got the exception: Uncaught RangeError: Maximum call stack size exceeded

What do you mean by " some rule factoring may be needed"? Do you mean I need to convert left-recursion to non-left-recursion following rules like this: https://web.cs.wpi.edu/~kal/PLT/PLT4.1.2.html ?

foo123 commented 7 years ago

Left-recursive grammars, can be transformed to right-recursive grammars which is not problematic for the grammar parser. Left-recursion in the grammar will NOT work. Factoring some grammar rules, helps with this.