[antlr-interest] cgram: typedef name vs function name questio
ns
mzukowski at yci.com
mzukowski at yci.com
Tue Feb 3 09:08:46 PST 2004
Well, the first question is why are you cheating around this? Because
you're not parsing header files or something?
There is a method boolean isTypedefName(String name) which you could tweak
to act the way you want.
I think that parenthesis are used for grouping, so you can't assume that A
(B) is a function call, but I'd have to dig into the spec to really know.
Monty
-----Original Message-----
From: edcjones [mailto:edcjones at yahoo.com]
Sent: Monday, February 02, 2004 7:26 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] cgram: typedef name vs function name questions
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/
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