c06 - CS421 COMPILERS AND INTERPRETERS CS421 Parser...

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

View Full Document Right Arrow Icon
Copyright 1994 - 2010 Zhong Shao, Yale University Parser Generation: Page 1 of 27 Parser Generation •M a i n P r o b l em : given a grammar G , how to build a top-down parser or a bottom-up parser for it ? •p a r s e r : a program that, given a sentence, reconstructs a derivation for that sentence ---- if done sucessfully, it “recognize” the sentence all parsers read their input left-to-right , but construct parse tree differently. •b o t t om - u p p a r s e r s - - - construct the tree from leaves to root shift-reduce, LR, SLR, LALR, operator precedence •t o p - d ow n p a r s e r s - - - construct the tree from root to leaves recursive descent, predictive parsing, LL(1) CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Parser Generation: Page 2 of 27 Bottom-Up Parsing •C o n s t r u c t p a r s e t r e e b o t t om - u p - - - f r om l e a v e s t o t h e r o o t • Bottom-up parsing always constructs right-most derivation • Important parsing algorithms: shift-reduce , LR parsing •LR p a r s e r components: input, stack (strings of grammar symbols and states ), driver routine, parsing tables. LR Parsing output s m X m .. s 1 X 1 s 0 parsing a 1 a 2 a 3 a 4 ...... a n $ input: stack CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Parser Generation: Page 3 of 27 LR Parsing •A s e q u e n c e o f n ew state symbols s 0, s 1,
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/20/2012.

Page1 / 7

c06 - CS421 COMPILERS AND INTERPRETERS CS421 Parser...

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

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