Download presentation
Presentation is loading. Please wait.
Published byEmil Wright Modified over 6 years ago
1
Parsing and Parser Parsing methods: top-down & bottom-up
2
Parsing and Parser Parsing -- the process of determining if a string of tokens can be generated by a grammar. Parser -- a software module in a compiler input: tokens, output: parse tree. Parsing methods: top-down root ---> leaves bottom-up leaves ---> root
3
Lexical and Syntax Analysis
Lexical analysis -- linear analysis or scanning in a compiler design. Syntax analysis -- hierarchical analysis and it is represented by a parse tree. Example: position := initial + rate*60 tokens: a meaningful unit -- position, :=, +, 60 parse tree: root -- assignment statement, leaves -- all the tokens, internal nodes -- nonterminals, such as expression, identifier, and number
4
Parsing Method I Deterministic top-down parser
using the information available to make a correct choice (exposed input string, production rules, frontier) a finite practical table, T row: a nonterminal node (i) column: the left-most exposed token (j) T[i, j]: a fixed choice for next production rule
5
Left / Right most Derivation
Left/right most derivation -- a derivation in which only the left /right most nonterminal in any sentential form is replaced at each step. Ambiguous grammar: a grammar that produces more than one left most or right most derivation for the same string.
6
Parsing Method II Deterministic bottom-up parser
rootline -- the left-to-right sequence of roots for the subtrees (see Fig. 2.12) LR(1) parser, a bottom-up parsing machine for G3 -- L to R, right most, observe 1 symbol in input each time. Read, v, and look ahead transition, {v} Apply state #i
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.