antlr - ANTLR4 - Mutually left-recursive grammar -


i getting error: the following sets of rules mutually left-recursive [symbolexpression]. in grammar, symbolexpression directly left-recursive shouldn't antlr4 handling this?

here relevant parts of parser:

operation:         operator '(' (operation | values | value | symbolexpression) ')'                       #operatorexpression      | bracketedsymbolexpression                                                              #bracketedoperatorexpression      ;  symbolexpression:      (operation | values | value | symbolexpression) symbol (operation | values | value | symbolexpression);  bracketedsymbolexpression:      '(' (operation | values | value | symbolexpression) symbol (operation | values | value | symbolexpression) ')';  list: '[' (operation | value) (',' (operation | value))* ']';  values: (operation | value) (',' (operation | value))+;  value:      number    | identifier    | list    | object; 

the elements 'symbolexpression' , 'operation' in rule 'symbolexpression' interdependently left recursive.

without knowing language specification, impossible whether language irrecoverably ambiguous.

nonetheless, 1 avenue try refactor grammar move repeated clauses,

( operation | value ) 

and

(operation | values | value | symbolexpression) 

to own rules goal of unifying 'operation' , 'symbolexpression' (and perhaps 'bracketedsymbolexpression') rules single rule -- rule @ self left-recursive. like

a : value   | lparen a* rparen   | lbrack a* lbrack   | symbol   | ( comma )+   ; 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -