Syntax Error
During the syntax analysis phase, this type of error appears. Syntax error is found during the execution of the program.
Some syntax error can be:
- Error in structure
- Missing operators
- Unbalanced parenthesis
When an invalid calculation enters into a calculator then a syntax error can also occurs. This can be caused by entering several decimal points in one number or by opening brackets without closing them.
For example 1: Using "=" when "==" is needed.
The following warning message will be displayed by many compilers:
Syntax Warning: assignment operator used in if expression line 16 of program firstprog.cpp
In this code, if expression used the equal sign which is actually an assignment operator not the relational operator which tests for equality.
Due to the assignment operator, number is set to 200 and the expression number=200 are always true because the expression's value is actually 200. For this example the correct code would be:
Example 2: Missing semicolon:
Compiler message:
Example 3: Errors in expressions:
0 Comments