Grammar

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:

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:

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:

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:

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:

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