Lecture-3-C Token
Lecture-3-C Token
C tokens
C tokens are the basic buildings blocks in C
language which are constructed together to write a
C program.
Each and every smallest individual units in a C
program is known as C token or a lexical unit.
C tokens can be classified in six types as follows:
① Keywords (e.g., int, while, do …),
② Identifiers (e.g.,main, total, my_var …),
③ Constants (e.g., 10, 20 , - 25.5 … ),
④ Strings (e.g., “total”, “hello” , “DIU” …),
⑤ Special symbols (e.g., (), {} , [] …),
⑥ Operators (e.g., +, /, - , * …)
C tokens
C tokens example
program
where,
Main, x, y, total – identifier
{,}, (,) – special symbols
Int , return – keyword
10, 20 – constant
=,+ – operator
“Total 30” – String
main, {, }, (, ), int, x, y, total etc– all these are
various tokens
① Keywords
② Identifiers
C Keywords ③
④
Constants
Strings
⑤ Special symbols
⑥ Operators
Keywords ②
③
Identifiers
Constants
④ Strings
⑤ Special symbols
⑥ Operators
There are 32 keywords in C which are given below. keywords
are all lowercase.
① Keywords
② Identifiers
③ Constants
Identifiers ④
⑤
Strings
Special symbols
⑥ Operators
Names given to identify variables, functions etc. are examples for identifiers.
e.g., int x ; here x is a name given to an integer variable.
Constants ②
③
Identifiers
Constants
④ Strings
⑤ Special symbols
⑥ Operators
Integer constants ②
③
Identifiers
Constants
④ Strings
⑤ Special symbols
⑥ Operators
Integer constants are the numeric constants (constant
associated with number) without any fractional part or
exponential part.
There are three types of integer constants in C language:
decimal constant(base 10),
octal constant(base 8) and
hexadecimal constant(base 16).
For example:
Decimal constants: 0, -9 , 22 etc
Octal constants: 021, 077, 033 etc
Hexadecimal constants: 0x7f, 0x2a, 0x521 etc
Single Character ②
③
Identifiers
Constants
Constants ④
⑤
Strings
Special symbols
⑥ Operators
String constants ③
④
Constants
Strings
⑤ Special symbols
⑥ Operators
Constant
② Identifiers
③ Constants
④ Strings
⑤ Special symbols
⑥ Operators
Sequences ②
③
Identifiers
Constants
④ Strings
⑤ Special symbols
⑥ Operators
① Keywords
Special Symbols ②
③
Identifiers
Constants
④ Strings
⑤ Special symbols
⑥ Operators
Operators ④
⑤
Strings
Special symbols
⑥ Operators
C operators are symbols that triggers an action when applied to C variables and other
objects. The data items on which operators act upon are called operands.
Depending on the number of operands that an operator can act upon, operators can be
classified as follows:
Unary Operators: Those operators that require only single operand to act upon are
known as unary operators.
Binary Operators: Those operators that require two operands to act upon are called
binary operators.
Ternary Operators: These operators requires three operands to act upon.
The multiple-character operators can not have white spaces or comments between the
characters.