As defined by C standards, the for loop syntax is:
for (initialisation; condition; increment/decrement) ...
Syntactically, there should be two semicolons, one opening parenthesis, one closing parenthesis, and correct spelling of “for”. Hence, to check only the syntax of for loop, what a compiler does is check the following conditions:
- Only “for” is written, and not “For”, “FOR”, “foR” or any of its variants.
- Total statement consists of two semicolons “;” before the closing parenthesis “)” ends.
- Presence of an opening parenthesis “(” after the “for” keyword, and presence of a closing parenthesis “)” at the end of statement.
Input : for (i = 10; i < 20 i++) Output : Semicolon Error Input : for(i = 10; i < 20; i++ Output : Closing parenthesis absent at end
No error Opening parenthesis absent after for keyword
- Introduction to Syntax Analysis in Compiler Design
- FIRST Set in Syntax Analysis
- FOLLOW Set in Syntax Analysis
- Syntax Directed Translation in Compiler Design
- C++ Program to implement Symbol Table
- C program to detect tokens in a C program
- Program to calculate First and Follow sets of given grammar
- Lex Program For checking a valid URL
- Compiler Design | Detection of a Loop in Three Address Code
- S - attributed and L - attributed SDTs in Syntax directed translation
- Lex program to count the number of lines, spaces and tabs
- Lex Program to accept a valid integer and float value
- Lex Program to check valid email
- Lex Program to accept string starting with vowel
- Lex program to find the length of the longest word
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ManasChhabra2