The smallest parts of program which are recognized as atomic unit by compiler during parsing are tokens. All a C program contain is bunch of tokens. Each and Individual words and punctuation marks are called tokens which are also called lexical units. Similarly, the smallest individual unit in a c program is known as a token or a lexical unit. C tokens can be of following types:
- Keywords
- Identifiers
- Operators
- Constants
- Special Symbols(punctuators)
- Strings
Every thing in a c program are tokens. Lets do anatomy of following code.
int fact(int n){
if(n <=1){
return 1;
}
else {
return n * fact(n-1);
}
- int, if, else, return :- Keywords
- fact, n :- Identifiers
- (, {, ;, ), } :- symbol, punctuation
- <=, *, – :- Operators
- 1 :- Constant
In this way compiler recognize each token from a program.