I suppose one could revisit the question of rules that allow
repeats (e.g., TOKEN*) as well. Hmmm. Interesting.
Cheers,
Dave
On Mon 09/02/09 1:25 PM , eliben eli...@gmail.com sent:
>
> Hello,
>
> In complex grammars I find myself writing dozens of productions of the
> type:
>
> def p_XXX_opt(self, p):
> """ XXX_opt : empty
> | XXX
> """
> p[0] = p[1]
>
> For many different XXXs.
> It really gets tiresome, and I was wondering about the alternatives.
>
> * Has anyone attempted some meta-programming magic to generate such
> methods automatically from a list of productions?
> * Dave, have you considered adding "optional" as a feature to
> PLY? Itwould be really useful, not hard to implement, and the syntax is
> really simple:
>
> """ YYY : XXX?"""
>
> The question mark can mean "XXX or empty", and in case of empty
> therelevant item of the p[] array just gets None.
>
> Eli
>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups
> "ply-hack" group.To post to this group, send email to ply
> -h...@googlegroups.comTo unsubscribe from this group, send email to ply-hack+
> unsub...@googlegroups.comFor more options, visit this group at http://groups.google.com/group/ply-hack?hl=en-~----------~----~----~----
~------~----~------~--~---
>
>
>
>
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