TOKENS(LEXICAL UNITS)
The smallest
individual unit in a program is known as a token or a lexical unit.
C++ has the
following tokens:
1.Keywords
2.Identifiers
3.Literals
4.Punctuators
5.Operators
Keywords: Keyword is a word having special
meaning reserved by programming language.
C++ has the
following keyword:
asm class double float inline
private
auto const delete for int
protected
break continue else
friend long register
case default enum goto new return
catch do
extern if
operator short
switch struct typedef void while
Identifiers: Identifiers are fundamental building
blocks of a program and are used as the general terminology for the names given
to different parts of the program.
The
following are some valid identifiers:
Myfile DATE9_7_77
MYFILE _DS
_CHK FILE13
The
following are some invalid identifiers:
DATA-REC contains special character -(other than
A- Z,a-z and -)
29CLCT Starting with a digit
break reserved keyword
My.file contains special character dot
(.)
Literals: Literals are data items that never
change their value during a program run.
C++ allows
several kinds of literals:
1.bool literal
2.integer constant
3.character constant
4.floating constant
5.string literal
Punctuators:
The
following characters are used as punctuators in C++:
[ ] (
) { } ,
; : *
... = #
Brackets[ ]
Opening and
closing brackets indicate single and multidimensional array subscripts.
Parentheses ( )
Opening and
closing parentheses indicate function calls and function parameters.
Parentheses also group expressions and isolate conditional expressions.
Braces {
}
Opening and
closing braces indicate the start and end of a compound statement.
Comma ,
It is used
as a separator in a function argument
list.
Semicolon ;
It is used
as a statement terminator. Every executable statement is terminated by a
semicolon( ; ).
Colon :
It indicate
a labeled statement.
Asterisk
*
It is used
for pointer declaration.
Ellipsis ...
Ellipsis(
... ) are used in the formal argument lists of function prototypes to indicate
a variable number of argument.
Equal to
=
It is used for variable initialisation and as an
assignment operator in expressions.
pound sign #
The pound
sign is used for preprocessor directive and double pound sign (##) is also used
as operators to perform token replacement and merging during the preprocessor
scanning phase.
Operators:
Operators are that trigger some computation
when applied to variables and other objects in an expression.
1.Unary operators
Unary
operator are those operator which contains only single operands.
Following
are some unary operators:
& address operator
* indirection operator
+ unary plus
- unary minus
+ + increment operator
- - decrement operator
! logical negation
2.Binary operators
binary
operator are those which contain two operands.
Following
are some binary operators:
Arithmetic operators Logical operators
+
addition && logical AND
-
subtraction ||
Logical OR
*
multiplication
/ division
% modulus
Bitwise operators Assignment operators
& bitwise AND = assignment
^ bitwise exclusive OR /= assign quotient
| bitwise OR
+= assign sum
Relational operators
< less than
> greater than
<=
less than or equal to
>= greater than or equal to
= = equal to
!=
not equal to
conditional operators
?
:
0 Comments