3.1 What is a syntax error?

A syntax error is essentially a grammatical mistake in program code. In natural language communication, a grammatical mistake is often not cripping. The main idea can still be conveyed even with a significant number of grammatical mistakes.

In programming, however, a syntax error is always crippling, no matter how trivial it may seem. For example, if you use a semi-colon where a comma is expected, most compilers or interpreters will not be able to understand the code any more. This is mainly because programming languages are very “fragile”, and compilers/interpreters are not very smart.

A compiler is a translator that reads programs in a specific programming language, and outputs code that can be executed by a system.

Let us consider the conditional statement as follows:

If (x > y  
  x = y;  
End  
    

If contains a number of syntax errors.

First, the line “If (x > y ” should have been If (x > y) Then. The original code missed the close parenthesis and the reserved word Then.

The second line should not have a semi-colon at the end.

The last line should be “End If”.