คำอธิบาย
Token คือองค์ประกอบเล็กที่สุดของโปรแกรมที่มีความหมายต่อคอมไพเลอร์ คอมไพเลอร์แยกโปรแกรมเป็น Tokens แล้วดำเนินการคอมไพล์ต่อไป Tokens ประกอบด้วย:
- Keywords
- Identifiers
- Constants
- Strings
- Special Symbols
- Operators
ตัวอย่างโปรแกรมพิมพ์ตัวอักษร A-Z
#include <stdio.h>
int main() {
int i;
printf("ASCII ==> Character\n");
for (i = 65; i <= 90; i++)
printf("%d ==> %c\n", i, i);
return 0;
}
Tokens ในโปรแกรมตัวอย่าง
- main - Identifier
- int - Keyword
- { } - Delimiters (Special Symbols)
- a, b, c - Variables (Identifiers)
ทั้งหมดรวมกันเรียกว่า Tokens