Metalanguage
Lexical Tokens
The C language has six classes of tokens; they are described in the sections that follow.
Names - Identifiers
Definition
an identifier, also called a name, is one or more letters and may contain digits.
Where
- the first character must be a letter or underscore
- the case of characters is significant
- the minimum number of characters is one
- the maximum number of characters is not specified
Notes:
Identifiers include variables, constants, string literals, functions, typedef names, tags of
enumerations, names of structures, names of unions, names of individual members of
structures and unions, labels, and keywords.
Keywords
Identifiers reserved as
Keywords by the language
| auto |
double |
int |
struct |
| break |
else |
long |
switch |
| case |
enum |
register |
typedef |
| char |
extern |
return |
union |
| const |
float |
short |
unsigned |
| continue |
for |
signed |
void |
| default |
goto |
sizeof |
volatile |
| do |
if |
static |
while |
Constants
- integer constant: #define MAXLINE 1000
- long constant: #define MYCONST 456456456L (or 456456456l)
- unsigned integer constant: #define MYCONST 123123U (or 123123u)
- unsigned long constant: #define MYCONST 123123UL
- character constant with an integer value (depending on the machine)
of 97: #define MYCHAR 'a'
- string constant: #define MYSTR "a"
- string constant: #define MYSTR "abcdefg"
- enumeration constant: enum boolean {FALSE, TRUE};
String Literals
Operators
C has the following operators:
- arithmetic
- relational and logical
- increment and decrement
- bitwise
- assignment
Other Separators - White Space
Statements
- Labeled
- Expression
- Compound
- Selection
- Iteration
- Jump
Scope
Comments
Primitive Types
C has the following primitives, or type-specifiers:
- char - character
- int - integer
- float - floating-point
- double - double floating-point
- void - valueless
- struct or union
- enum
- typedef
C has four basic type modifiers:
- signed - use to force char objects to carry a sign, redundant
otherwise
- unsigned
- long
- short
Type qualifiers - there are two. These control how variables of the above types
may be accessed or modified.
- const - once initialized, const objects may not be assigned to.
- volatile - tells the compiler that the variable's value may change
by outside processes, so it should reexamine the value each time it is referenced in
an expression
These primitives are constructed from the basic types
- arrays
- functions
- pointers
- structures
- unions
Objects
Declarations
Identifiers are interpreted in the context of their storage class
and type; declarations specify those attributes. The identifier
in a declaration is called a declarator.
Declarations require at least one declarator, unless the declared type is a structure tag,
a union tag, or the members of an enumeration. The declarator may be abstract - i.e. the
identifier is not present. This is called a type name declaration, used when the name
of a data type is required. Examples where this usage occurs include casts, function parameter
declarations, and arguments for sizeof.
Storage Class Specifiers
Storage class specifiers are optional, but no more than one may apear in a declaration. Default
rules apply:
- Inside a function -
- objects are auto with no linkage
- functions are extern
- Outside a function -
- objects are static, with external linkage
- declared functions are static, with external
linkage
- extern - inside a function, objects declared as extern specifies that the
object is defined elsewhere.
- static - static local variables retain their value between calls to a function;
static global variables are known only to the file they are declared in.
- register - objects declared with this class are given automatic storage;
may be used within functions only. There are restrictions:
- only certain types of objects are allowed to be placed in registers -
these are implementation-defined.
- you may not apply the unary & operator to these.
- auto - objects declared with this class are given automatic storage;
may be used within functions only.
- typedef
Names
Expressions
Functions
Control Structures
Conversions
References
The C Programming Language, Second Edition, by Brian W. Kernighan and Dennis M. Ritchie,
Prentice Hall, NJ 1988
ISBN 0-13-110370-9
Parts of 'Characteristics of the C Language' modified from C: The Complete Reference,
Third Edition, by Herbert Schildt,
Osborne McGraw-Hill, Berkeley, CA 1995
ISBN 0-07-882101-0