Syntax error

Syntax errors are bugs which are any bugs which prevent the program from compiling. More specifically it is when the code written does not match the grammatical rules of the programming language. Every language has a specific grammar which the programmer must work within. The rules for the language are very specific (non-ambiguous). They are defined in a context-free grammar known as Backus naur form.

IF A=10 THEN PRINT A

The above is grammatically correct. We know that an if statement takes the form

IF <CONDITION> THEN <EXPRESSION>

Where the < CONDITION > will be some expression which evaluates to a Boolean value and < EXPRESSION > is any standard code which is accepted. It is possible, using BNF, to define exactly what is meant by a condition and an expression. For now we will just follow the loose definitions already.

THEN a=IF > ELSE

Above is an example of code which does not match the grammar for an IF statement. It is fairly obvious why this code does not match. IF statements must always start with the keyword IF . The above expression starts with the keyword THEN . This is an example of a syntax error. If you tried to compile this code you would get a compile error. The translator diagnostics would then point to this line and say that it does not match the form for an IF statement or some other comment. It is important to note that the compiler may not guess what you were trying to do. As such the error returned may be ambiguous. It should, however, point out exactly where the error was.