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 email@example.com. 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Lex code to count total number of tokens
- C/C++ Tokens
- C program to print a string without any quote (singe or double) in the program
- Lex Program to remove comments from C program
- Hello World Program : First program while learning Programming
- Program for Sum of the digits of a given number
- Write a C program to print "Geeks for Geeks" without using a semicolon
- Output of the program | Dereference, Reference, Dereference, Reference....
- Quine - A self-reproducing program
- Program to compute Log n
- Program to print last 10 lines
- Write a C program that does not terminate when Ctrl+C is pressed
- Write a C program that won't compile in C++
- Write a program that produces different results in C and C++
- Printing source code of a C program itself
- C program to demonstrate fork() and pipe()
- Output of C Program | Set 29
- Program to print the diamond shape
- Program to print Happy Birthday
- Write a C program that displays contents of a given file like 'more' utility in Linux