3
$\begingroup$

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?

$\endgroup$
7
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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

                    =
                   / \
                  /   \
               Answer  +
                      / \
                     /   \
                  token1 token2

So here priority of operator also matters, so if you want to have a deeper knowledge, click here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.