SYNTAX
ANALYSIS: PARSER
Ø The
next phase is called syntax analysis or parsing. It takes the token produced by
lexical analysis as input and generates a parse tree orsyntaxtree. In these
phase, token arrangements are checked against the source code grammer, i.e. the
parser checks if the expression made by tokens is syntactically correct
Ø Check
whether the tokens streams meets the grammatical specification of the language
and generates the syntax tree.
§ A
syntax error is produced by the compiler when the program does not meet the grammatical
specification.
§ For
grammatical correct program, this phase generate an internal representation
that is easy to manipulate in later phases.
Typically a syntax tree (also called a
parse tree).
Ø
A grammer of programming language is
typically described by a context free grammer , which also defines the
structure of the parse tree.
Context Free Grammers
Ø
A context free grammer defines the
syntax of a programming language.
Ø
Syntax defines the syntactic categories
for language constructs.
§ Statements
§ Expression
§ Declaration
Ø
Categories are subdivided into more
detailed categories.
A
statement is a
§ For-Statement
§ If-Statement
§ Assignment