i prepared grammar mini language creating, getting mutual left recursion error between var
, functioncall
var : name | var '[' exp ']' | var '.' var | functioncall '.' var ; functioncall : name '(' (exp)? (',' exp)* ')' | var '.' functioncall | functioncall '.' functioncall ;
specifically @ var : functioncall '.' functioncall
, functioncall : var '.' functioncall
corresponds somefunction().var
, instanceofclass.function()
.
is there way can achieve this?
edit : grammar should allow var '=' exp
var can instance.var
or function().var
antlr 4 (and not before that) can handle both-side recursion in same rule. like
expr: expr '+' expr | number
is valid.
so can put new rule abstract either var or function call.
value : var | functioncall | value '.' value ; var : name | var '[' exp ']' ; functioncall : name '(' exp? (',' exp)* ')' ;
not grammar simpler parse (to human readers), have no mutual recursion.
note: untested.
Comments
Post a Comment