eliben wrote:
> I've ended up with this concoction:
> 
> class PLYParser(object):
>     def _create_opt_rule(self, rulename):
>         """ Given a rule name, creates an optional ply.yacc rule
>             for it. The name of the optional rule is
>             <rulename>_opt
>         """
>         optname = rulename + '_opt'
> 
>         def optrule(self, p):
>             p[0] = p[1]
> 
>         optrule.__doc__ = '%s : empty\n| %s' % (optname, rulename)
>         optrule.__name__ = 'p_%s' % optname
>         setattr(self.__class__, optrule.__name__, optrule)

Can you explain what 'empty' is?


The usual way to write optional rules is

X_opt :
       | X

In this situation, 'p[0] = p[1]' will fail in the case of the empty alternative.





Before we jump to implementation, it may be good to first define what we 
should be able to express, and how to do that.


The one thing that bothers me with these extensions, is that we may loose the 
power to express all cases explicitly.

In the case of 'X?', how does one distinguish between both cases?

In particular when 'None' is a legal associated value for X?




Sincerely,
Albert


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to