As defined by C standards, the for loop syntax is:
for (initialisation; condition; increment/decrement) ...
Syntactically, there should be two semicolons, one opening paranthesis, one closing paranthesis, 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 paranthesis “)” ends.
- Presence of an opening paranthesis “(” after the “for” keyword, and presence of a closing paranthesis “)” 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 paranthesis absent after for keyword
- Compiler Theory | Set 1
- Compiler Theory | Set 2
- Compiler Design | Lexical Analysis
- Compiler Design | Introduction to Syntax Analysis
- Compiler Design | Why FIRST and FOLLOW?
- Compiler Design | FIRST Set in Syntax Analysis
- Compiler Design | FOLLOW Set in Syntax Analysis
- Compiler Design | Ambiguous Grammar
- Compiler Design | Runtime Environments
- Compiler Design | Syntax Directed Translation
- Compiler Design | Intermediate Code Generation
- Compiler Design | Peephole Optimization
- C++ Program to implement Symbol Table
- Language Processors: Assembler, Compiler and Interpreter
- C program to detect tokens in a C program
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.