Search code examples
javacompiler-constructionantlrxtextlexical-analysis

Left Recursion: ANTLR


I am trying to do Lexical Analysis in Java grammar, but got stack in that error. I am in expression part right now, doing it in parts (just using string_expression):

expression:
    ( expression8)
;

expression8:
    {Expression8Action}
    ((  
      ( "+" 
      | "+=" ) 
      e2=expression )e1=expression8)?
;

Solution

  • Solved with turning on backtrack (file .mwe2):

    language = StandardLanguage {
            name = "org.xtext.example.mydsl.MyDsl"
            fileExtensions = "mydsl"
    
            serializer = {
                generateStub = false
            }
            validator = {
                // composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
            }
            parserGenerator = {
                options = {
                    backtrack = true
                }
            }
        }