Uploaded by Saim Safeer

1912260 CC A3

advertisement
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology
COMPUTER SCIENCE DEPARTMENT
Total Marks:
05
Obtained Marks:
Compiler Construction
Assignment # 03
Last date of Submission: 23 May 2022
Submitted To: Muhammad Azeem
_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Student Name: Muhmmad Usman Anwar
______________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Reg. Number:
1912260
______________________________________________________________________________________________________________________________________________________________________________________________________________________________________
CC
BS(CS)-5A
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology
COMPUTER SCIENCE DEPARTMENT
Instructions: Copied or shown assignments will be marked zero. Late submissions are not
entertained in any case.
Question No.1:
Define and explain SLR(1) Parser with the help of suitable example.
ANS)
It is a simple LR parsing. Most of the function of this parsing is the same as LR(0) parsing. The
parsing table for both the parser vary. The SLR(1) parsing use canonical LR(0) item. The
reduce move is placed only in the FOLLOW of those variables whose production is reduced.
Working of SLR:
CC
BS(CS)-5A
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology
COMPUTER SCIENCE DEPARTMENT
Example:
CC
BS(CS)-5A
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology
COMPUTER SCIENCE DEPARTMENT
Question No.2: Define and explain LALR(1) Parser with the help of
suitable example.
ANS) The LALR parsing refers to the "lookahead LR" that has many lesser
steps than typical parsers based on LR(1) items. For constructing the LALR(1)
parsing table, the canonical collection of LR(1) items is used. In the LALR(1)
parsing, the LR(1) items with the same productions but have different
lookahead are grouped together to form a single set of items. It is generally the
same as CLR(1) parsing except for the one difference that is the parsing table
Working of LALR:
CC
BS(CS)-5A
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology
COMPUTER SCIENCE DEPARTMENT
Example:
CC
BS(CS)-5A
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology
COMPUTER SCIENCE DEPARTMENT
Question No.3:
Define and explain CLR(1) Parser with the help of suitable example.
ANS) CLR parsing refers to the canonical lookahead. We will use the
canonical collection of LR(1) items for the construction of the CLR(1) parsing
table. Generally, CLR(1) parsing has more number of states as compared to
SLR(1) parsing. In the CLR(1), the reduced node will be placed only in the
lookahead symbols.
Working of CLR:
CC
BS(CS)-5A
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science &
Technology
COMPUTER SCIENCE DEPARTMENT
Example:
CC
BS(CS)-5A
SZABIST-ISB
Download