[Python-Dev] funcdef grammar production (original) (raw)
Greg Ewing greg at cosc.canterbury.ac.nz
Wed Mar 17 18:48:45 EST 2004
- Previous message: [Python-Dev] funcdef grammar production
- Next message: [Python-Dev] dateutil
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Jewett, Jim J" <jim.jewett at eds.com>:
one possible path is
(defparameter ",")* (defparameter [","])
Even that seems unnecessarily obtuse. I would write it as
defparameter ("," defparameter)* [","]
Under my formulation, it would be ambiguous whether "a" was a defparameter or a (regular) parameter, which are different productions. Looking ahead for the "=" violates a no-lookahead rule.
If the grammar is only for documentation, none of that matters -- it doesn't have to be LL(1) or anything in particular, as long as it unambiguously specifies the language.
By the way, it occurs to me that BNF on its own doesn't seem to be up to the task of specifying this sort of thing clearly to a human reader. If it weren't for the commas, we could say something like
defparams ::= name* (name "=" expr)* ["*" name] ["**" name]
All we need to say on top of that is "separate this list of things with commas", which could perhaps be expressed as
defparams ::= (name* (name "=" expr)* ["*" name] ["**" name]) separated_by ","
with some sort of meta-rule like
ITEM* separated_by SEP ::= [ITEM ("," ITEM*) [","]]
Hmmm, this is starting to look dangerously like a two-level grammar...
Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg at cosc.canterbury.ac.nz +--------------------------------------+
- Previous message: [Python-Dev] funcdef grammar production
- Next message: [Python-Dev] dateutil
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]