Thanks a lot Ron! I think I have understood the essence of it. Interestingly, I had earlier tried such a function declaration in C and got the same error message - which is very readable. I think I can get such a good error message working with the original ANTLR grammar. Thanks for pointing out!
www.cdecl.org was very helpful to me in understanding complex C declarations - just in case, if any1 is looking for. Best Regards, Sarnath -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Ron Burk Sent: Monday, December 06, 2010 10:55 PM Cc: [email protected] Subject: Re: [antlr-interest] C Grammar - Symbol Suffix Related.. > I have a doubt on the following productions of the C grammar. What version of C are you shooting for? > Any ideas why the grammar is so? Maybe it's just reproducing a specification grammar? For example, in the C99 spec, section A.2.2, the 6.75 construct is: direct-declarator: identifier ( declarator ) direct-declarator [ type-qualifier-list.opt assignment-expression.opt ] ... direct-declarator ( parameter-type-list ) direct-declarator ( identifier-list.opt ) Transforming that to ANTLR would look pretty much like what you posted. (Ironically, if ANTLR simply automatically performed the transformations for direct left recursion and left factoring, a shocking percentage of the C99 language spec would slide through unchanged as LL(1).) Not all constraints can (or should) be implemented via grammar syntax, as the people who worked on the C language knew. In fact, I speculate that tools like ANTLR, by offering ever-expanding feature sets, result in less and less readable grammars, as the everything-looks-like-a-nail syndrome causes people to try to cram every constraint into the grammar, foregoing more modular, understandable, and functional divisions of labor. So, for example, given a construct like: int foo(int a)(int b); Visual C++ says: error C2091: function returns function A highly readable and to the point error message. I suspect that if they instead had tried to contort their grammar to reflect every constraint under the sun, the message would have come out more like "Unexpected left parenthesis after parameter declaration list." I know which I prefer (and I also prefer the ability to directly match a syntactically plausible but semantically erroneous construct so that there's no need to rely on "error recovery" mechanisms to guess where to continue the parse). IMHO :-). List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address ::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. ----------------------------------------------------------------------------------------------------------------------- List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
