problem with declaration grammar?
Ellery Newcomer
ellery-newcomer at utulsa.edu
Thu Feb 19 21:22:34 PST 2009
jerry quinn wrote:
> Ellery Newcomer Wrote:
>>> 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.
>
> As I'm looking at this further, there seems to be more issues. In particular, I don't think the grammar can parse:
>
> int (*x)(char);
>
> as specified. Doing so gives (my best attempt)
>
> Decl -> BasicType Declarators ;
> BasicType -> int
> Declarators -> DeclaratorInitializer
> DeclaratorInitializer -> Declarator
> Declarator -> BasicType2 Identifier DeclaratorSuffixes
> BasicType2 -> NULL (assuming that the grammar should be revised like this)
> Identifier -> BAD PARSE
>
>
yeah, if you haven't figured out by now, the grammar is a bunch of hooey.
I spent like a month building an ANTLR grammar based on the above, and
then realized much of it was garbage.
Then I spent two months going through the source code and rewriting most
of the rules. Just got done with it a week or two ago :) That was all
version 1, but it looks the same, so if memory serves the above rules
should look something like this:
BasicType2_x:
*
[ ]
[ Expression ]
[ Expression .. Expression ]
[ Type ]
delegate Parameters FunctionAttributesopt
function Paramters FunctionAttributesopt
BasicType2:
BasicType2_x
BasicType2 BasicType2_x
epsilon
Declarator:
BasicType2 Identifier DeclaratorSuffixesopt
BasicType2 ( Declarator ) DeclaratorSuffixesopt
Apologies for any BNF misuse
More information about the Digitalmars-d
mailing list