Once the string of tokens has been generated the compiler must check to see if the sequence of tokens is acceptable.

VARIABLE EQUALS CONSTANT

The above token string is acceptable, the one below is not.

CONSTANT EQUALS VARIABLE

The compiler understands all of the rules of the language and has all of these rules stored within itself. Just like there are rules which must be followed in English, the programmer must also follow the rules of the programming language. If they do not then they will be faced with a syntax error. A syntax error is simply when the tokens passed to the compiler do not match any rule stored within the compiler.

Once syntax has been checked the compiler can then construct the abstract syntax tree. It can not construct the tree unless the syntax is 100% correct.

Technical note -

A grammar is used to store the rules of the language in. The token list is then read in and is compared to the grammar. When a token is read in it will match a single rule in the grammar. If it can not match a rule then it is clearly not part of the grammar and therefore a syntax error. The grammar is normally written in backus naur form (BNF) and is a separate topic on the syllabus.