0% found this document useful (0 votes)
45 views5 pages

Constructing SLR Parsing Table

The document discusses constructing an SLR parsing table by first building the set of LR items for an augmented grammar, then using those items to determine the parsing actions and state transitions, with actions including shift, reduce, accept, and error, and with conflicts resolved using lookahead. The table is constructed by examining the items in each state to determine the parsing action for each terminal or non-terminal based on whether the item is of the form [A α.aB] or [A α.] and setting the initial state to that containing [S' .S].

Uploaded by

hasanen1985
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views5 pages

Constructing SLR Parsing Table

The document discusses constructing an SLR parsing table by first building the set of LR items for an augmented grammar, then using those items to determine the parsing actions and state transitions, with actions including shift, reduce, accept, and error, and with conflicts resolved using lookahead. The table is constructed by examining the items in each state to determine the parsing action for each terminal or non-terminal based on whether the item is of the form [A α.aB] or [A α.] and setting the initial state to that containing [S' .S].

Uploaded by

hasanen1985
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 5

CONSTRUCTING SLR PARSING TABLE

Viable Prefix
In shift-reduce parsing , the stack always a viable prefix

that is, a prefix of some right-sentential form that ends no further right than the end of the handle of that rightsentential form E F * id (E) * id Valid Item An item is a production with dot somewhere in the body. An item is valid for valid prefix if the production of that item is used to generate the handle

Viable Prefix
Valid Items: an item A 1. 2 is valid for a viable prefix 1 if there is a derivation: S' =>*rm A =>*rm 1 2 Suppose A 1.2 is valid for 1, and B1 is on the parsing stack if 2 != , we should shift if 2 = , A 1 is the handle, and we should reduce by this production Note: two valid items may tell us to do different things for the same viable prefix. Some of these conflicts can be resolved using lookahead on the input string.

Constructing an SLR Parsing Table


Given a grammar G, construct the augmented grammar by

adding the production S' S. Construct C = {I0, I1, In}, the set of sets of LR items for G'. State I is constructed from Ii, with parsing action determined as follows: 1. [A .aB] is in Ii, where a is a terminal; goto(Ii,a) = Ij : set action[i,a] = "shift j" 2. [A .] is in Ii : set action[i,a] to "reduce A x" for all a in FOLLOW(A), where A != S' 3. [S' S.] is in Ii : set action[i,$] to "accept" 4. goto transitions constructed as follows: for all non-terminals: if goto(Ii, A) = Ij , then goto[i,A] = j . 5. All entries not defined by (3) & (4) are made "error". If there are any multiply defined entries, grammar is not SLR. 6. Initial state S0 of parser: that constructed from I0 or [S' .S]

SLR parse table

You might also like