Vous êtes sur la page 1sur 3

TOKEN SEPERATION AIM: To separate the tokens (5 types) of tokens in a given C program file.

ALGORITHM 1) Read the character from the file. 2) If the character is an alphabet, goto step 5. 3) Check whether the character is an operator a. If yes, identify the character as an operator. b. Otherwise, identify it as special character. 4) Go to step 8. 5) Read character until we encounter a non-alphabetical character and form a string. 6) If the string is define of const identify the variable next to it as a constant and go to step 8. Otherwise go to step 7. 7) Check whether, the string is keyword. If yes, identify the string as keyword. Otherwise, identify the string as identifier. 8) If end of file is reached stop program, otherwise goto step 1. SAMPLE INPUT: #include<stdio.h> #define max 10 const int n = 10; void main() { int a; int b = 5; a = b * n; printf(%d,a); } OUTPUT: MENU 1. IDENTIFIERS 2. KEYWORDS 3. CONSTANTS 4. OPERATORS

5. SPECIAL CHARACTERS 6. EXIT ENTER YOUR CHOICE: 1 a b MENU 1. IDENTIFIERS 2. KEYWORDS 3. CONSTANTS 4. OPERATORS 5. SPECIAL CHARACTERS 6. EXIT ENTER YOUR CHOICE: 2 int const void main MENU 1. IDENTIFIERS 2. KEYWORDS 3. CONSTANTS 4. OPERATORS 5. SPECIAL CHARACTERS 6. EXIT ENTER YOUR CHOICE: 3 max n MENU 1. IDENTIFIERS 2. KEYWORDS 3. CONSTANTS 4. OPERATORS 5. SPECIAL CHARACTERS 6. EXIT ENTER YOUR CHOICE: 4 = * MENU 1. IDENTIFIERS 2. KEYWORDS 3. CONSTANTS 4. OPERATORS 5. SPECIAL CHARACTERS 6. EXIT ENTER YOUR CHOICE: 5 # ; ( ) { MENU 1. IDENTIFIERS 2. KEYWORDS 3. CONSTANTS 4. OPERATORS 5. SPECIAL CHARACTERS

6. EXIT ENTER YOUR CHOICE:

RESULT: Thus the 5 types of tokens in the given c program is separated successfully.

Vous aimerez peut-être aussi