cse443 compilers
play

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis - PowerPoint PPT Presentation

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei Phases of a Syntactic compiler structure Figure 1.6,


  1. CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei

  2. Phases of a Syntactic compiler structure Figure 1.6, page 5 of text

  3. Table-driven predictive parsing Here we trade the implicit stack that the recursing parsing algorithm uses for an explicit stack.

  4. Recall the parse-table M NON id + * ( ) $ TERMINALS E E -> T E' E -> T E' E' E' -> 𝜁 E' -> 𝜁 E' -> + T E' T T -> F T' T -> F T' T' T' -> 𝜁 T' -> 𝜁 T' -> 𝜁 T' -> * F T F F -> id F -> ( E )

  5. Algorithm 4.34 [p. 226] INPUT: A string 𝜕 and a parsing table M for a grammar G=(N,T,P,S). OUTPUT: If 𝜕∈𝓜 (G), a leftmost derivation of 𝜕 , error otherwise input $ 𝜕 stack S M parser $ output

  6. Algorithm 4.34 [p. 226] Let a be the first symbol of 𝜕 Let X be the top stack symbol while (X ≠ $) { if (x == a) { pop the stack, advance a in 𝜕 } else if (X is a terminal) { error } else if (M[X,a] is blank) { error } else if (M[X,a] is X -> Y 1 Y 2 … Y k ) { output X -> Y 1 Y 2 … Y k pop the stack push Y k … Y 2 Y 1 onto the stack } Let X be the top stack symbol } Accept if a == X == $

  7. INPUT (a) STACK (X) OUTPUT id + id * id $ E $ E -> T E' id + id * id $ T E' $ T -> F T' id + id * id $ F T' E' $ F -> id id + id * id $ id T' E' $ id + id * id $ T' E' $ T' -> 𝜁 id + id * id $ E' $ E' -> + T E' id + id * id $ + T E' $ id + id * id $ T E' $ T -> F T' id + id * id $ F T' E' $ F -> id id + id * id $ id T' E' $ id + id * id $ T' E' $ T' -> * F T' id + id * id $ * F T' E' $ id + id * id $ F T' E' $ F -> id id + id * id $ id T' E' $ id + id * id $ T' E' $ T' -> 𝜁 id + id * id $ E' $ E' -> 𝜁 id + id * id $ $ Since both a and X are $, accept

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend