[antlr-interest] cgram: typedef name vs function name questions

edcjones edcjones at yahoo.com
Mon Feb 2 19:26:06 PST 2004


I am interested in parsing C code is a consistent manner but the
output does not need to be suitable for a compiler. How can I cheat my
way around the following difficulty?

The following one line C file causes an error message in cgram (and
also gcc):

    xxx obj;

Correct parsing sometimes depends on knowing whether "xxx" is a
typedef name or a function name. Harbison & Steele say

    ... consider the program line

         A ( *B ) ;

    If "A" has been defined as a typedef name, then the line is a
    declaration of a variable "B" of type "pointer to A". (The
    parentheses surrounding "*B" are ignored.) If "A" is not a
    type name, then the line is a call of the function "A" with the
    single parameter "*B". This ambiguity cannot be resolved
grammatically.

This determination is somehow carried out in the "initDecl" rule in
"GnuCParser.g". How is this done? Is "xxx obj;" unambiguous because
there are no parentheses? If "B" has already been declared or there in
no "*", must "A" be a function name? I would like the grammar to
assume "xxx" is a typedef name unless it can deduce otherwise. How can
this be done?



 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/antlr-interest/

To unsubscribe from this group, send an email to:
 antlr-interest-unsubscribe at yahoogroups.com

Your use of Yahoo! Groups is subject to:
 http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list