What is the job of Syntax Analyzer in a compiler?
The syntax analyser has two main purposes.


It checks if the program to be compiled is syntactically correct.
It converts the program, which is given as a string of characters,
into an abstract syntax tree, which is a representation of the
program that is much easier to use for the code generator.


The second part is not really necessary as one could, in principle,
generate code directly from the input string, but that would be painful,
both in terms of speed of compilation, and complexity of the code generator.