I'm trying to use grako to describe a simple left-recursive grammar but I have trouble to do so.
Right-recursion does work without any problem :
symbol = /[a-z]/ ;
condition = symbol "AND" condition | symbol ;
start = condition $ ;
According to all examples I found, left-recursion should be described this way :
symbol = /[a-z]/ ;
condition = condition "AND" symbol | symbol ;
start = condition $ ;
However, it does not work for the rule given below :
a AND b AND c
I get this error :
grako.exceptions.FailedParse: srecur(1:3) Expecting end of text. :
a AND b AND c
^
start
What I understand at this point is that first character of rule matches symbol
and not condition "AND" symbol
, so grako would like to use it. But my start rule forces that all characters have been consumed.
I've tried to use many workarounds yet but I've not been able to find one that fits.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.