Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Bottom up Parsing - Compiler Construction - Lecture Notes, Study notes of Compiler Construction

Bottom up parsing, Shift parsing, Reduce parsing, Kinds of action, Large class of grammars, LR parsing, Tokens, Right most derivation, Left recursive grammars are the points from this lecture. You can find series of lecture notes for compiler construction here.

Typology: Study notes

2011/2012

Uploaded on 11/06/2012

asim.amjid
asim.amjid 🇵🇰

4.4

(46)

40 documents

1 / 3

Toggle sidebar

Related documents


Partial preview of the text

Download Bottom up Parsing - Compiler Construction - Lecture Notes and more Study notes Compiler Construction in PDF only on Docsity! 63 Lecture 20 Bottom-up Parsing Bottom-up parsing is more general than top-down parsing. Bottom-up parsers handle a large class of grammars. It is the preferred method in practice. It is also called LR parsing; L means that tokens are read left to right and R means that the parser constructs a rightmost derivation. LR parsers do not need left-factored grammars. LR parsers can handle left-recursive grammars. LR parsing reduces a string to the start symbol by inverting productions.A derivation consists of a series of rewrite steps S>yw>n>.. > Int => Yn > sentence Each yj is a sentential form. If y contains only terminals, y is a sentence in L(G). Ify contains = 1 nonterminals, y is a sentential form. A bottom-up parser builds a derivation by working from input sentence back towards the start symbol S. Consider the grammar S > aABe A — Abc| b B > d The sentence abbcde can be reduced to S: abbcde aAbcde aAde aABe Ss These reductions, in fact, trace out the following right-most derivation in reverse: Ss => aABe => aAde => aAbcde => abbcde S => aBy = ayy > xy Sohail Aslam Compiler Construction Notes Set:3-63 64 rule: B= y Qa Y Es x y UY Terminals only Consider the grammar 1 E >E+(E) | int N The bottom-up parse of the string int + (int) + (int) would be int + (int) + (int) E + (int) + (int) E + (E) + (int) E + (int) E+ (E) E The consequence of an LR parser tracing a rightmost derivation in reverse is that given ay be a step of a bottom-up parse, assuming that next reduction is A > B then y is a string of terminals. The reason is that wAy > ay is a step in a rightmost derivation. This observation provides a strategy for building bottom up parsers: split the input string into two substrings. Right substring (a string of terminals) is as yet unexamined by parser and left substring has terminals and non-terminals. The dividing point is marked by a > (the > is not part of the string). Initially, all input is unexamined: P X1 X1. « . Xn. Shift-Reduce Parsing Bottom-up parsing uses only two kinds of actions: 1. Shift 2. Reduce Sohail Aslam Compiler Construction Notes Set:3-64
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved