[antlr-interest] C Grammar - Symbol Suffix Related..

Sarnath K - ERS, HCLTech k_sarnath at hcl.com
Mon Dec 6 00:46:19 PST 2010


Hi There! Compiler Gurus!

I have a doubt on the following productions of the C grammar.

If you look at "direct_declarator", it tries to specify a multi-dimensional array (or) a function.
The "*" on the declarator_suffix ensures that multi-dimensional arrays can  be handled.
However "*" does not serve any purpose for functions. We don't declare functions like "f(...)(...)(...)"
Moreover "C" does NOT allow functions to return arrays (int  unsupported()[]);

Any ideas why the grammar is so? I am planning to modify it to suit "C" style correctly - so I can setup the symbol table pretty easily.
Any help? Many Thanks,

"
direct_declarator
        :   (     IDENTIFIER  |  ('(' declarator ')')     )
            (declarator_suffix)*
        ;

declarator_suffix
    :   '[' constant_expression ']'
    |   '[' ']'
    |   '(' parameter_type_list ')'
    |   '(' identifier_list ')'
    |   '(' ')'
    ;
"

Best Regards,
Sarnath

________________________________
::DISCLAIMER::
-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.
It shall not attach any liability on the originator or HCL or its affiliates. Any views or opinions presented in
this email are solely those of the author and may not necessarily reflect the opinions of HCL or its affiliates.
Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of
this message without the prior written consent of the author of this e-mail is strictly prohibited. If you have
received this email in error please delete it and notify the sender immediately. Before opening any mail and
attachments please check them for viruses and defect.

-----------------------------------------------------------------------------------------------------------------------


More information about the antlr-interest mailing list