Download presentation
Presentation is loading. Please wait.
Published byJesse Daniel Modified over 8 years ago
1
Compiler1 5.1.3 Syntactic Analysis r Two general classes of parsing techniques m Bottom-up (Operator-Precedence parsing) Begin with the terminal nodes of the tree, and attempt to combine these into successively higher-level nodes until the root is reached. m Top-down (Recursive-Descent parsing) Begin with the rule of the grammar that specifies the goal of the analysis, and attempt to construct the tree so that the terminal nodes match the statements being analyzed.
2
Compiler2 r Examining pairs of consecutive operators in the source program, and making decisions about which operation should be performed first. r Example: A + B * C – D Note: * and / have higher precedence than + and -. Operator-Precedence Parsing
3
Compiler3 Operator-Precedence Parsing (cont.) r Define the precedence relations for every terminal, by using =. r E.g., PROGRAM =. VAR BEGIN <. FOR
4
Compiler4 Operator-Precedence Parsing (cont.)
5
Compiler5 Sample for operator-precedence parsing
6
Compiler6 Sample for operator-precedence parsing (cont.)
7
Compiler7 Sample for operator-precedence parsing (cont.)
8
Compiler8 Sample for operator-precedence parsing (cont.)
9
Compiler9 Sample for operator-precedence parsing (cont.)
10
Compiler10 Sample for operator-precedence parsing (cont.)
11
Compiler11 Shift-reduce process
12
Compiler12 Shift-reduce process (cont.)
13
Compiler13 Recursive-Descent Parsing r A top-down method. r When a procedure is called, it attempt to find a substring of the input, beginning with the current token, that can be interpreted as the nonterminal with which the procedure is associated. r Problem of left recursion: m Rule 6. ::= id |, id (Unable to decide between its two alternative since both id and can begin with id ) m Rule 7. ::= | ; m …
14
Compiler14 Remove the left recursion
15
Compiler15 Recursive-Descent Parsing (cont.)
16
Compiler16 Recursive-Descent Parsing (cont.)
17
Compiler17 Recursive-Descent Parsing (cont.)
18
Compiler18 Recursive-Descent Parsing (cont.)
19
Compiler19 Recursive-Descent Parsing (cont.)
20
Compiler20 Recursive-Descent Parsing (cont.)
21
Compiler21 Recursive-Descent Parsing (cont.)
22
Compiler22 Recursive-Descent Parsing (cont.)
23
Compiler23 Recursive-Descent Parsing (cont.)
24
Compiler24 Recursive-Descent Parsing (cont.)
25
Compiler25 Recursive-Descent Parsing (cont.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.