11-08-2012, 03:04 PM
Syntax Analysis
syntax analysis.pptx (Size: 275.82 KB / Downloads: 29)
Syntax analysis processes the string of tokens built by lexical analysis to determine the statement class, e.g. assignment statement. if statement, etc. It then builds an IC which represents the structure of the statement.The IC is passed to semantic analysis to determine the meaning of the statement.Syntax analysis is devoted to parsing methods that are typically used in compilers. We examine the way the parser fits into a typical compiler
Context- free grammars
Grammars are used to systematically describe the syntax of programming language constructs like expressions & statements like
stmt→ if (expr) stmt else stmt
It specify the structure of conditional statement
Other productions will specify expr and stmt
The formal definition of cfg
CFG consists of terminals, non terminals, a start symbol and productions.
Terminals are basic symbols from which strings are formed.
Token name is a synonym for terminal
Nonterminals are syntactic variables that denote sets of strings.
Eg stmt or expr
Start Symbol, a distinguished nonterminal
Productions of a grammar specify the manner in which the terminals and nonterminals can be combined to form strings. Each production consists of
A nonterminal called head or left side of production
The symbol → sometime ::=
A body or right consisting of zero or more terminals or nonterminals.
Top down parsing
Constructing a parse tree for the input string, starting from the root and creating the nodes of the parse tree in pre-order.(PLR)
Can be viewed as finding a leftmost derivation for an input string.
Different parsing
Recursive decent parsing
Predictive parsing
syntax analysis.pptx (Size: 275.82 KB / Downloads: 29)
Syntax analysis processes the string of tokens built by lexical analysis to determine the statement class, e.g. assignment statement. if statement, etc. It then builds an IC which represents the structure of the statement.The IC is passed to semantic analysis to determine the meaning of the statement.Syntax analysis is devoted to parsing methods that are typically used in compilers. We examine the way the parser fits into a typical compiler
Context- free grammars
Grammars are used to systematically describe the syntax of programming language constructs like expressions & statements like
stmt→ if (expr) stmt else stmt
It specify the structure of conditional statement
Other productions will specify expr and stmt
The formal definition of cfg
CFG consists of terminals, non terminals, a start symbol and productions.
Terminals are basic symbols from which strings are formed.
Token name is a synonym for terminal
Nonterminals are syntactic variables that denote sets of strings.
Eg stmt or expr
Start Symbol, a distinguished nonterminal
Productions of a grammar specify the manner in which the terminals and nonterminals can be combined to form strings. Each production consists of
A nonterminal called head or left side of production
The symbol → sometime ::=
A body or right consisting of zero or more terminals or nonterminals.
Top down parsing
Constructing a parse tree for the input string, starting from the root and creating the nodes of the parse tree in pre-order.(PLR)
Can be viewed as finding a leftmost derivation for an input string.
Different parsing
Recursive decent parsing
Predictive parsing