Dec 8, 2011

Getting Started & C++ Tokens

 Getting Started

For Execute your C++ Code, You Need a Compiler (Download Now). Source file are Extension with .CPP & Executable File have the .EXE Extension(in Windows). Compiler convert your Source file into execution file By converting your C++ written source code into low level machine code, which made it easy to execute by OS(Operating System).

BEFORE Make your First Program You Must Know Something About Rules of C++ language.


 C++ Character Set

Character set is a set of valid characters that a language can recognize. A character represents any letter, digit  or any other Sign. The C++ has the following character set:

LEtters         A-Z, a-z

Digits           0-9

Special         Space  +  -  * / ^ \ ( ) [ ] { } = != <  >  . ' " $ , ; : % ! & ?
Symbols       _(underscore) # <= >= @

Other Character   C++ can process any of the 256 ASCII characters as data or as Literals



There is Token(smallest individual unit in a program)
C++ has following TOKEN:
  • Keywords
  • Identifiers
  • Literals
  • Punctuators
  • Operators

Keywords : These are reserved for special purpose and must not be used as normal identifier  
                    names
                    Followings are C++ KeyWords:

Identifiers : Identifiers are self given name to your Variable, objects , classes, Functions , arrays etc.

Identifiers has some Rules :-

1. An identifier can be combination of letters, numbers, and underscores with following restrictions:

a) It should start with a letter or underscore. E.g. height, my_height,_myHeight are allowed but not 1isGod
b) If it starts with a underscore then the first letter should not be capital because such names are reserved for implementation. E.g. _Height not allowed

2. It should be unique in a program taking care that C++ is case sensitive. E.g. age and Age are different variables

3. A keyword cannot be used as an identifier.

4. There is no restriction on length of the identifier. E.g. h and h_represents_my height are both valid.

Literals: The terms "literal" and "constant" are used interchangeably here. Literals fall into four major categories: integer, character, floating-point, and string literals.


 A literal may be any of the following:
  •  Integer-Constant
  • Character-Constant
  • Floating-Constant
  • String-Literal

 
 
FOR Example 
    
157 // integer constant
0xFE // integer constant
'c' // character constant
0.2 // floating constant
0.2E-01 // floating constant
"dog" // string literal
 

 Punctuators : Punctuators in C++ have syntactic and semantic meaning to the compiler but do not, of themselves, specify an operation that yields a value. Some punctuators, either alone or in combination, can also be C++ operators or be significant to the preprocessor.

Following characters are considered punctuators:

! % ^ & * ( ) – + = { } | ~
[ ] \ ; ' : " < > ? , . / #
 
 

 
Operators: Operators are tokens that trigger some computation when applied to variable and other objects in a expression.

Go to Type of Operators For more Details about operators




0 comments:

Post a Comment