C Tokens

|

In a C source program, the basic element recognized by the compiler is the "token." A token is source-program text that the compiler does not break down into component elements.

TOKENS:
 
  • Keyword   
  • Identifier    
  • Constant\Literal 
  • Variable    
  • Operator
  • Punctuator  
 
1. KEYWORD :
"Keywords" are words that have special meaning to the C compiler. An identifier cannot have the same spelling and case as a C keyword. C language uses the following keywords:
autodoubleintstruct
breakelselongswitch
caseenumregistertypedef
charexternreturnunion
constfloatshortunsigned
continueforsignedvoid
defaultgotosizeofvolatile
doifstaticwhile
You cannot redefine keywords. However, you can specify text to be substituted for keywords before compilation by using C preprocessor directives.
                                                                                                                 
2. IDENTIFIERS :
       "Identifiers" or "symbols" are the names you supply for variables, types, 
        functions, and labels in your program. Identifier names must differ in   
        spelling andcase from any keywords. You cannot use keywords (either C 
        or Microsoft) as identifiers; they are reserved for special use. You create
        an identifier by specifying it in the declaration of a variable, type, or
        function.        
       Once declared, you can use the identifier in later program statements to
       refer to the associated value.
       A special kind of identifier, called a statement label, can be used in goto
       statements. (Declarations are described in Declarations and Types
       Statement  labels are described in The goto and Labeled Statements.) 
Syntax
       identifier:
  nondigit identifier      nondigit identifier digit
       nondigit: one of
_ a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
       digit: one of
0 1 2 3 4 5 6 7 8 9
       The first character of an identifier name must be a nondigit (that is,
       the first character must be an underscore or an uppercase or lowercase
       letter). ANSI allows six significant characters in an external identifier's
       name and 31 for names of internal (within a function) identifiers. External
       identifiers (ones declared at global scope or declared with storage class
       extern) may be subject to additional naming restrictions because these
       identifiers have to be processed by other software such as linkers.

Characteristic of identifier:
  • The first character must be an alphabet or an underscore.
  • It must consist of only letters, digits or underscore.
  • Only first 31 characters are significant, i.e. if the user enters an identifier of more than 31 characters, the compiler considers only first 31 characters & deletes the others.
  • A keyword cannot be used as an identifier name. 
  • It cannot contain any spaces

                                                                                                               
    3. CONSTANTS :
            A constant value is the one which does not change during the execution
            of a program. C supports several types of constants.
    1. Integer Constants     
    2. Real Constants     
    3. Single Character Constants      
    4. String Constants
    Integer Constants
           An integer constant is a sequence of digits. There are 3 types of integers
           namely decimal integer, octal integers and hexadecimal integer.

    Decimal Integers :
           Decimal integer constant consists of a set of digits 0 to 9 preceded by an
           optional + or - sign. Spaces, commas and non digit characters are not
           permitted between digits. Example for valid decimal integer constants
           are
           123
           -310562321
           +78
           Some examples for invalid integer constants are
           15 750
           20, 000
           Rs. 1000

    Octal Integers :
           Octal integer constant consists of any combination of digits from 0
           through 7 with a O at the beginning. Some examples of octal integers
           are
           O26O
           O347
           O676

    Hexadecimal integer:
           Hexadecimal integer constant is preceded by OX or Ox, they may
           contain alphabets from A to F or a to f. The alphabets A to F refers
           to 10 to 15 in decimal digits. Example of valid hexadecimal integers
           are
           OX2
           OX8C
           OXbcd
           Ox

    Real Constants

           Real Constants consists of a fractional part in their representation.
           Integer constants are inadequate to represent quantities that vary
           continuously. These quantities are represented by numbers containing
           fractional parts like 26.082. Example of real constants are 0.0026
          -0.974 35.29 +487.0. Real Numbers can also be represented by
           exponential notation. The general form for exponential notation is
           mantissa exponent. The mantissa is either a real number expressed in
           decimal notation or an integer. The exponent is an integer number with
           an optional plus or minus sign

    Single Character constants

           A Single Character constant represent a single character which is
           enclosed in a pair of quotation symbols.Example for character
           constants are

                  '5'

                  'x'

                  ';'

                  ' '

           All character constants have an equivalent integer value which are
           called ASCII Values.

    String Constants
           A string is a sequence of characters enclosed in double quotes. The
           sequence of characters may contain letters, numbers, special characters
           & blank spaces.
           For eg:-

                       “HELLO!”
                       “1987”
                       “Well Done”
                       “?.....!”
                       “x”

            A subtype of strings are Escape Sequences/Backslash character
            constants. They are string s that do not get printed on screen but
            have their own importance when executed.

             \a - audible alert(bell)
             \b - back space
             \f - form feed
             \n - new line
             \r - carriage return
             \t - horizontal tab
             \v - vertical tab
             \' - single quote
             \” - double quote
             \? - question mark
             \\ - backslash
             \0 - null
                                                                                                              
    4. VARIABLE :
            For details : click here
                                                                                                              
    5. OPERATOR :
            For details : click here
                                                                                                              



    0 comments:

    Post a Comment