This appendix presents a formal grammar for the Objective-C extensions to the C language—as the Objective-C language is implemented for the Cocoa development environment. It adds to the grammar for ANSI standard C found in Appendix A of The C Programming Language (second edition, 1988) by Brian W. Kernighan and Dennis M. Ritchie, published by Prentice Hall, and should be read in conjunction with that book.
The Objective-C extensions introduce some new symbols (such as class interface), but also make use of symbols (such as function definition) that are explained in the standard C grammar. The symbols mentioned but not explained here are listed below:
compound-statement
constant
declaration
declaration-list
enum-specifier
expression
function-definition
identifier
parameter-type-list
string
struct-declaration-list
struct-or-union
typedef-name
type-name
Of these, identifier and string are undefined terminal symbols. Objective-C adds no undefined terminal symbols of its own.
Two notational conventions used here differ from those used in The C Programming Language:
Literal symbols are shown in code font.
Brackets enclose optional elements.
Otherwise, this appendix attempts to follow the conventions of The C Programming Language. Each part of the grammar consists of a symbol and a colon in bold and a list of mutually-exclusive possibilities for expanding the symbol. For example:
receiver:
expression
class-name
super
However, there is an exception: Even though they’re not mutually exclusive, the constituents of classes, categories, protocols, and blocks are listed on separate lines to clearly show the ordering of elements. For example:
protocol-declaration:
@protocol protocol-name
[ protocol-reference-list ]
[ interface-declaration-list ]
@end
This exception to the general rule is easily recognized since each list terminates with @end or the symbol name ends with “-block”.
There are six entry points where the Objective-C language modifies the rules defined for standard C:
External declarations
Type specifiers
Type qualifiers
Primary expressions
Exceptions
Synchronization
This appendix is therefore divided into six sections corresponding to these points. Where a rule in the standard C grammar is modified by an Objective-C extension, the entire rule is repeated in its modified form.
External Declarations
Type Specifiers
Type Qualifiers
Primary Expressions
Exceptions
Synchronization
Last updated: 2008-02-05