WP-Parsing - COT 4210 Bottom-Up Parsing Discrete Structures...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COT 4210 Discrete Structures II Fall 1998 Bottom-Up Parsing In contrast with Top-down parsing algorithms and grammars, the family of Bottom-up parsing algorithms and grammars can be characterized by those algorithms that attempt to produce the reverse of a rightmost derivation with respect to some underlying context-free grammar, G. A rightmost derivation in a context-free grammar tends to expand the final terminal string in a right-to-left fashion. Whereas a Top-down parsing algorithms apply grammar rules in the natural way – by expanding the leftside (nonterminal) of the rule with the rightside (handle) – a Bottom-up parser reverses this process by pushing input symbols into the stack (shift action) until the rightside of some rule can be recognized in the stack. The Bottom-up parser then “reduces the stack” by replacing the rightside of some rule (in the stack) with the corresponding leftside (nonterminal) of the rule. This process continues until one of two conditions occur: (1) an erroneous symbol or token is recognized as not being consistent with the grammar (in some way), or (2) the entire input has been successfully reduced to just the start symbol of the grammar (S). Figure 1 illustrates the conceptual model of a Bottom-up parse. Figure 1. Conceptual Model of a Bottom-up Parser. The family of deterministic Bottom-up parsers and grammars is larger and more powerful than the family of deterministic Top-down parsers. The most commonly used family of grammars for defining programming languages and building Bottom-up parsers is the family of LR(k) grammars. UNIX tools such as YACC produce a parser as output when presented with an LR(1) grammar as input. In general, LR(k) parsers are very complicated and their parsers are quite complex. However, there is a sub-family of LR(1) grammars, the Weak Precedence Grammars, that are easier to understand and much less difficult to parse. We therefore continue with a discussion of these grammars and their parsing algorithms. 4/29/2009 Page 1 © D. A. Workman
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COT 4210 Discrete Structures II Fall 1998 Weak Precedence Grammars DEFINITION (LEFT and RIGHT sets) Let G = (N, Σ , P, S) be a reduce context-free grammar. We define the LEFT and RIGHT sets for each nonterminal, X N, as follows. LEFT(X) = { Y V G | X ⇒+ Y α , for some α V G * } RIGHT(X) = { Y V G | X ⇒+ α Y, for some α V G * } Example G = (N, Σ , P, S), where N = {S, X, Y, B}, Σ = {a, b, c} P = { 1: S XY 2: X a X B 3: X a b 4: B b 5: Y Y c 6: Y c } Symbol LEFT RIGHT B { b } { b } Y { Y, c } { c } X { a } { b, B } S { X, a } { Y, c } DEFINITION (Wirth-Weber Precedence Relations) Let G = (N, Σ , P, S) be a reduce context-free grammar. For X,Y V G , the relations O are defined on the vocabulary V G as follows: (a) X Y if and only if 5 (A uXYv P), where u,v are any strings. (b) X OY
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/09/2011 for the course COT 4210 taught by Professor Staff during the Spring '08 term at University of Central Florida.

Page1 / 9

WP-Parsing - COT 4210 Bottom-Up Parsing Discrete Structures...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online