# What is the job of Syntax Analyzer in a compiler?

What exactly is the job of a syntax analyzer? Suppose I have a mathematical expression. Is it true that the order of execution of the operations is found with the help of syntax analyzer?

Any example on exact jobs of Syntax Analyzer?

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.

The syntax analyser checks for the grammers or checks for the meaningfulness of your operation.. As you mentioned about mathematical expression, First it creates PARSE TREE of your expression.

Consider following example,

Answer=token1+token2;


So it will create parse tree of this expression as

                    =
/ \
/   \