SUBJECT CODE: 203105351
Pratibha Shakya, Assistant Professor
Computer Science & Engineering
, CHAPTER-2
Introduction to syntax analysis
,Syntax Analyzer
• Syntax Analyzer creates the syntactic structure of the given source program.
• This syntactic structure is mostly a parse tree.
• Syntax Analyzer is also known as parser.
• The syntax of a programming is described by a context-free grammar (CFG). We will use BNF (Backu
Naur Form) notation in the description of CFGs.
• The syntax analyzer (parser) checks whether a given source program satisfies the rules implied by a
context-free grammar or not.
– If it satisfies, the parser creates the parse tree of that program.
– Otherwise the parser gives the error messages.
• A context-free grammar
– gives a precise syntactic specification of a programming language.
– the design of the grammar is an initial phase of the design of a compiler.
– a grammar can be directly converted into a parser by some tools.
, Parser
• Parser works on a stream of tokens.
• The smallest item is a token.
Source Lexical token
Program
Parser parse tree
Analyzer get next token