HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

What is the job of Syntax Analyzer in a compiler?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
thewhatsyntaxcompilerjobanalyzer

Problem

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?

Solution

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.

Context

StackExchange Computer Science Q#14083, answer score: 7

Revisions (0)

No revisions yet.