Tuesday 3 March 2015

C Tokens


The smallest element identified by the compiler in a source file is called a token. It may be a single character or a sequence of characters to form a single item. Tokens can be classified as keywords, literals, identifiers, operators, etc. Literals can be further classified as numeric constants, character constants and string constants.

Language specific tokens used by a programming language are called keywords. Keywords are also called as reserved words. They are defined as a part of the programming language therefore cannot be used for anything else. Any user defined literals or identifiers should not conflict with keywords or compiler directives. Table 2.1 lists keywords supported by the C language.

                                                  Table 2.1 – The C language keywords


Literals are factual data represented in a language. Numeric constants are an uninterrupted sequence of digits (possibly contain ing a period). Numerical values such as 123, 10000 and 99.99 are examples. Character constants represents a single character and it is surrounded by single quotation mark (‘). Characters such as ‘a’, ‘A’, ‘$’ and ‘4’ are examples. A sequence of characters surrounded by double quotation marks (inverted comma “”) is called a string constant. A statement such as “I like ice cream.” is a string constant.

Identifiers are also referred as names. A valid identifier is composed of a letter followed by a sequence of letters, digits or underscore (_) symbols. An identifier must begin with a letter and the rest can be letters, digits or underscores. Identifies are case sensitive; therefore the identifier abc is different from ABC or Abc.

C identifiers can be very long and so it allows descriptive names like “number_of_students” and “Total_number_of_cars_produced_per_year”. Sometimes a C compiler may consider only the first 32 characters in an identifier. While defining identifiers programmers should follow some of the naming standards for better readability of the program. One such standard is the use of underscores symbol (_) to combine two words (example: sub_total).

Operators are used with operands to build expressions. For example “4+5” is an expression containing two operands (4 and 5) and one operator (+ symbol). C supports large number of mathematical and logical operators such as +, -, *, /, %, ^, &, && , |, ||, etc. Operators will be discussed in chapter 3.

The C language uses several symbols such as semicolons (;), colons (:), commas (,), apostrophes (‘), quotation marks (“”), braces ([]), brackets ({}), and parentheses (()) to group block of code as a single unit.



No comments:

Post a Comment