Chapter 1

Parsing Bottom-Up Review Bottom-up Parsing is often called what? Shift-Reduce Parsing What is a Handle? Def: a handle is a right hand side of a production that we can reduce to get to the preceding step in the derivation. What Parser did we cover last time?

Operator Precedence Parser Parsing Bottom-Up 2 Parsing Bottom-Up 3 The LR Parser The most powerful of all parsers that we

will consider (Knuth, 1965) They can handle the widest variety of CFG's (including everything that predictive parsers and precedence parsers can handle) Parsing Bottom-Up 4 They work fast, and can detect errors

as soon as possible. (as soon as the first incorrect token is encountered) It is also easy to extend LR parsers to incorporate intermediate code generation. Parsing Bottom-Up 5

Def: LR(k) -- Left to right scan of the tokens, Rightmost derivation, kcharacter lookahead. The larger the lookahead (k) the larger the table. Hopcroft and Ullman (1979) have shown that any deterministic CFL can be handled by an LR(1) parser, so that is the kind we will learn. Parsing Bottom-Up

6 Table Layout: states | <- Terminals -> | <- Non-Term. -> ------------------------------------------------- 0 | | 1 | Action

| go-to 2 | part | part ... | | LR Parser tables tend to be large. For

economy, we don't place the productions themselves in the table; instead, we number them and refer to them in the table by number. 7 Parsing Bottom-Up place $ at end of input, state 0 on stack. Repeat Until input is accepted or an error Let qm be the current state (at the top of the

stack) and let ai be the incoming token. Enter the action part of the table; X=Table[ qm,ai] Case X of Shift qn: Shift (that is, push) ai onto the stack and enter State qn. (We mark the fact that we have entered that state by pushing it onto the stack along with ai Reduce n: Reduce by means of production #n. (We do the reduction in essentially the same was as in the operator-precedence parser, except for

managing the states.) When the left-hand side has been pushed, we must also place a new state on the stack using the go-to part of the table. Accept: parse is complete 8 Parsing Bottom-Up Error: Indicate input error The only complicated thing is reducing. 1. If the right hand side of the indicated

production has k symbols, pop the top k things off the stack (that is, k state-symbol pairs). This is the handle. If the right hand side is epsilon, nothing is popped.) 2. Next, note the state on the top of the stack (after the handle has been popped). Suppose it is qj.

Parsing Bottom-Up 9 3. Suppose the left-hand side is X. Enter the go-to part of the table at [qj, X] and note the entry. It will be a state; suppose it is qk 4. Push X and the new state qk onto the stack.

Parsing Bottom-Up 10 We will use our familiar grammar for expressions: (with productions numbered) (1) E -> E + T (2) E -> E - T (3) E -> T

(4) T -> T * F (5) T -> T / F (6) T -> F (7) F -> ( E ) (8) F -> I Parsing Bottom-Up 11 Parse (i+i)/i Parsing Bottom-Up

12 Parsing Bottom-Up 13 Parse i*(i-i Parsing Bottom-Up

14 Parsing Bottom-Up 15 Parsing Bottom-Up 16

Recently Viewed Presentations

  • Soft tissue injuries - PDHPE

    Soft tissue injuries - PDHPE

    Soft tissue injuries. Research and Review. 1 Describe the differences between a sprain and. a strain. 2 Explain the acute inflammatory response.. 3 Outline the aims of the immediate. management of soft-tissue injuries. 4 Identify the problems that can sometimes....
  • North West Housing LIN Meeting 3rd July 2013

    North West Housing LIN Meeting 3rd July 2013

    North West Housing LIN Meeting 3rd July 2013 Beatrix House, Dukinfield Damian Utton, Partner POZZONI LLP Architects * * * * * * * * * * * * * * * * * * Site area 0.60ha = 1.48acre...
  • PRESENTATION TITLE - Cloudinary

    PRESENTATION TITLE - Cloudinary

    Strong recovery early in decade, pause in late 12/early 13 and picks back up late 13 into 14.
  • The Contract Review And Approval Form

    The Contract Review And Approval Form

    The approved Payables Contract includes at Terms and Conditions attachment that includes 17 terms. If you need a copy of the approved template, it is located on the Business Contracts Intranet. Please DO NOT use the template found on the...
  • PPT Main Title

    PPT Main Title

    Radiculopathy is usually caused by herniated disc pressure on the nerve root near the spinal cord. It is common for pain to occur with radiculopathy indicating that small fibers also became irritated QST can be used to explore the different...
  • PowerPoint Presentation

    PowerPoint Presentation

    6.1 The Study of Genetics in Humans Is Constrained by Special Features of Human Biology and Culture, 135 6.2 Geneticists Often Use Pedigrees to Study the Inheritance of Characteristics in Humans, 136 6.3 Analysis of Pedigrees Requires Recognizing Patterns Associated...
  • Let My People Go - Christian and Missionary Alliance

    Let My People Go - Christian and Missionary Alliance

    Let My People Go. Margaret's Birthday Surprise! ... Margaret slipped her hand into her daddy's big hand as they pushed their way through the crowds of people on the narrow Chinese street. ... you could see a big, tall man,...
  • Data-Driven Websites

    Data-Driven Websites

    (e.g. 'Back' button) Different than GUI programming! Standard WinApp GUI: One user (per executable) 'Global' state data Client = server UI and back-end are same executable Solutions in ASPX Provides user 'session' awareness (a) Recognizes users by cookies (b) Maintains...