As it is known that Lexical Analysis is the first phase of compiler also known as scanner. It converts the input program into a sequence of Tokens.
A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.
1) Keywords: Examples- for, while, if etc. 2) Identifier Examples- Variable name, function name etc. 3) Operators: Examples- '+', '++', '-' etc. 4) Separators: Examples- ', ' ';' etc
Below is a C program to print all the keywords, literals, valid identifiers, invalid identifiers, integer number, real number in a given C program:
'int' IS A KEYWORD 'a' IS A VALID IDENTIFIER '=' IS AN OPERATOR 'b' IS A VALID IDENTIFIER '+' IS AN OPERATOR '1c' IS NOT A VALID IDENTIFIER
This article is contributed by MAZHAR IMAM KHAN. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- C program to print a string without any quote (singe or double) in the program
- C/C++ Tokens
- Hello World Program : First program while learning Programming
- Lex code to count total number of tokens
- Lex Program to remove comments from C program
- Output of C Program | Set 29
- How to compile 32-bit program on 64-bit gcc in C and C++
- How does a C program executes?
- Program to compute Log n
- OpenMP | Hello World program
- Lex program to check whether a given number is even or odd
- Program to check if two strings are same or not
- Program error signals
- Splint -- A C program verifier
- Lex Program For checking a valid URL
- C program to delete a file
- Write a C program that won't compile in C++
- Program to validate an IP address
- Program to print last 10 lines
- Program for Sum of the digits of a given number