I tried your psuedo code in PLY with and duplicated the 4 shift/reduce
conflicts
-------------------------------
def p_start(p):
"""start :
| startElem
| start startElem
"""
pass
def p_startElem(p):
"""startElem : COMMENT
| GLOBAL '{' varList '}'
"""
pass
def p_varList(p):
"""varList :
| varListElem
| varList varListElem
"""
pass
def p_varListElem(p):
"""varListElem : COMMENT
| INTEGER ID ';'
| INTEGER ID '[' NUMBER ']' ';'
"""
pass
-------------------------------
I then restructured the 'start' production as follows
-------------------------------
def p_start(p):
"""start :
| startElems
"""
pass
def p_startElems(p):
"""startElems : startElem
| startElems startElem
"""
pass
def p_startElem(p):
"""startElem : COMMENT
| GLOBAL '{' varList '}'
"""
pass
-------------------------------
Doing the same for the 'varList' removes all the conflicts. This structure
has the advantage that the <empty> production case only reduces when there
are no start elements in the text being parsed. This would be useful if you
wanted an action to be performed only when there are no start elements.
Similarly you could perform an action when there are 1 or more start
elements,
def p_startEmpty(p):
"""start :
"""
#action(s) for no start elements
def p_start(p):
"""start : startElems
"""
#action(s) for 1 or more start elements
Regards,
John
--
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ply-hack/d5e9d835-7feb-4c96-86dd-1b2256d2f5f0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.