problem with declaration grammar?

Ellery Newcomer ellery-newcomer at utulsa.edu
Thu Feb 19 08:48:17 PST 2009


jerry quinn wrote:
> Christopher Wright Wrote:
> 
>> jerry quinn wrote:
>>> Hi there,
>>>
>>> I'm not sure if I'm missing something, but I'm having trouble seeing that a simple declaration will parse correctly with the D grammar.
>>>
>>> If we take a declaration statment like:
>>>
>>> int x = 3;
>>>
>>> we have (my best guess):
>>>
>>> DeclarationStatement -> Declaration
>>> Declaration -> Decl
>>> Decl -> BasicType Declarators ;
>>> BasicType -> int
>>> Declarators -> DeclaratorInitializer
>>> DeclaratorInitializer -> Declarator = Initializer
>>> Declarator -> BasicType2 Identifier
>>> BasicType2 -> ????
>>>
>>> I'm thinking that BasicType2 is optional here, rather than required as the grammar shows.  Is that correct?
>>>
>>> Thanks
>>> Jerry
>> . Declaration -> Decl
>> . Decl -> BasicType Declarators
>> . BasicType -> "int"
>> . Declarators -> DeclaratorInitializer
>> . DeclaratorInitializer -> Declarator "=" Initializer
>> We agree up to here.
>>
>> . Declarator -> Identifier
>> Here, you don't need BasicType2, and if you use it, you recurse, so 
>> using the rule Declarator -> BasicType2 Declarator here is useless.
> 
> What you describe sounds like what I'd expect.
> 
> Maybe I'm missing something.  The grammar shown in http://www.digitalmars.com/d/2.0/declaration.html has the following rules:
> 
> BasicType2:
>         *
>         [ ]
>         [ Expression ]
>         [ Expression .. Expression ]
>         [ Type ]
>         delegate Parameters FunctionAttributesopt
>         function Parameters FunctionAttributesopt
> 
> Declarator:
>         BasicType2 Declarator DeclaratorSuffixesopt
>         BasicType2 Identifier DeclaratorSuffixesopt
> 
> With this definition, I don't see how you can get Declarator->Identifier.
> 
> Jerry
> 

You are correct. BasicType2 can match nothing. It should also be able to 
match what it does above multiple times.



More information about the Digitalmars-d mailing list