Found 146 Articles for Compiler Design

How to Fill the Entries in Parsing Table?

Ginni
Updated on 02-Nov-2021 10:51:02

280 Views

A parser is the second phase of compilation. The parser takes as its input tokens generated from the previous phase, i.e., the Lexical Analyzer phase, and groups them in such a way that their syntax can be recognized.For example, Consider I0I0 − E′ → ∙ E      E → ∙ E + T     E → ∙ T     T → ∙ T ∗ F     T → ∙ F     F → ∙ (E)     F → ∙ idFilling of Shifting EntriesApplying Rule (2a) of the algorithm of construction of SLR Parsing Table on a set of a ... Read More

Construct SLR (1) parsing table for the grammar1. E → E + T2. E → T3. T → T * F4. T → F5.F → (E)6.F → id

Ginni
Updated on 02-Nov-2021 10:49:31

651 Views

SolutionSteps to produce SLR Parsing TableGenerate Canonical set of LR (0) itemsCompute FOLLOW as required by Rule (2b) of Parsing Table Algorithm.Computation of FOLLOWBy Rule (1) of FOLLOWFOLLOW(E) = {$}                                                   (1)E → E + TApplying Rule (2) FOLLOWi.e., comparing E → E + T with A → α B βE →ΕE+ TA →ΑBΒ∴ A = E, α = ε, B = E, β = +T∵ Since FIRST(β) = FIRST(+T) = {+}which does not contain ε.∴ ... Read More

What is SLR (1) Parser?

Ginni
Updated on 02-Nov-2021 10:35:47

5K+ Views

SLR represents "Simple LR Parser". It is very simple and economical to execute. But it fails to make a parsing table for some class of grammars, i.e., why CLR and LALR are used which implements mainly all class or type of grammars. It constructs parsing tables which helps to perform parsing of input strings.SLR(1) − A grammar having an SLR parsing table is said to be SLR (1).Working of SLR ParserSLR Parsing can be done if context-free Grammar will be given. In LR (0), 0 means there is no Look Ahead symbol.The Canonical collection of LR (0) itemsThe LR (0) ... Read More

Find the canonical collection of sets of LR (0) items for Grammar -E → E + TE → TT → T * FT → FF → (E)F → id

Ginni
Updated on 02-Nov-2021 10:23:03

2K+ Views

SolutionStep1− Construct the Augmented Grammar and number the productions(0) E′ → E(1) E → E + T(2) E → T(3) T → T * F(4) T → F(5) F → (E)(6) F → idStep2− Apply closure to the set of items & find gotoSquare Boxes represent the new states or items, and Circle represents the repeating items.So, all rules of I0have been completed by applying goto on I0. Now, in the same manner apply goto on I1, I2 and then goes on.Drawing DFAEach set of the item can be taken as a state of DFA, i.e., I0, I1 … … ... Read More

What is Algorithm of Predictive Parsing and compute FIRST and FOLLOW for the following GrammarS → L = RS → RL →* RL → idR → L

Ginni
Updated on 02-Nov-2021 09:55:41

821 Views

SolutionComputation of FIRSTS → L = R∵ L does not derive ε. By rule (4b)of FIRST∴ FIRST(S) = {FIRST(L)}                                                  (1)S → R∵ R does not derive ε. By rule (4b)of FIRST∴ FIRST(S) = {FIRST(R)}                                                 (2)L →* RApplying Rule (3) of FIRSTFIRST(L) = {*}                   ... Read More

What is Canonical Collection of LR (0) items in compiler design?

Ginni
Updated on 01-Nov-2021 13:40:25

4K+ Views

The LR (0) item for Grammar G consists of a production in which symbol dot (.) is inserted at some position in R.H.S of production.For Example − For the production S → ABC, the generated LR (0) items will be −S →∙ ABCS → A ∙ BCS → AB ∙ CS → ABC ∙Production S → ε generates only one item, i.e., S →∙Canonical LR (0) collection helps to construct LR parser called Simple LR (SLR) parser.To create Canonical LR (0) collection for Grammar, 3 things are required −Augmented GrammarClosure Functiongoto FunctionAugmented Grammar − If grammar G has start symbol ... Read More

What are LR Parsers?

Ginni
Updated on 01-Nov-2021 12:39:44

2K+ Views

LR Parser is a class of Bottom-Up Parser that is used to parse Context-Free Grammars. LR Parsing is known as LR (K) parsing whereL represents Left to Right Scanning of InputR represents Rightmost DerivationK is the number of input symbols of Look ahead that are used in developing parsing decisions.LR parser is a shift-reduce parser that creates the use of deterministic finite automata, identifying the collection of all applicable prefixes by reading the stack from bottom to top.It decides what handle, if any, is feasible. An achievable prefix of a right sentential form is that prefix that includes a handle, ... Read More

What is the difference between Backtracking and Non- Backtracking?

Ginni
Updated on 01-Nov-2021 12:36:09

2K+ Views

Top-Down Parsing with BacktrackingIn Top-Down Parsing with Backtracking, Parser will attempt multiple rules or production to discover the match for input string by backtracking at every step of derivation. So, if the used production does not give the input string as needed, or it does not match with the needed string, then it can undo that shift.Top-Down Parsing without BacktrackingAs backtracking looks more powerful by which we can select different alternatives. But backtracking cannot be applied or implemented so easily in parsing. There are two types of Top-Down Parsing without Backtracking, which are as follows −Recursive Descent ParserPredictive ParserRecursive Descent ... Read More

Find FIRST & FOLLOW for the following GrammarE → TE′E → +TE′|εT → FT′T′ →* FT′|εF → (E)|id

Ginni
Updated on 01-Nov-2021 12:27:42

3K+ Views

SolutionComputation of FIRSTE →TE′Applying Rule (4b) of FIRSTSince FIRST (T) does not contain ε, or T does not derive ε.∴ FIRST (E) = FIRST(TE′) = FIRST(T)∴ FIRST (E) = {FIRST(T)} (1)E → +TE′|εApplying Rule (3) of FIRSTComparing E′ → +TE′with X → aα∴ FIRST(E′) = {+}Apply Rule (2) on E′ → εFIRST (E′) = {ε}∴ FIRST(E′) = {+, ε} (2)T→FT′Apply rule (4b) of FIRSTSince, FIRST(F) does not derive ε∴ FIRST(T) = FIRST(FT′) = FIRST(F)∴ FIRST(T) = {FIRST(F)} (3)T′→*FT′|εComparing with rule (2) & (3) of FIRST, we get∴ FIRST(T′) = {ε, ∗} (4)F→(E)|idComparing with rule (3) of FIRST∴ FIRST(F) = {(, ... Read More

Construct a Predictive Parsing table for the following grammar & also check whether string id + id * id is accepted or not.

Ginni
Updated on 08-Nov-2023 00:08:09

25K+ Views

Problem − Consider the following grammar − E → TE′ E′ → +TE′|ε T′ → FT′ T′ → FT′|ε F → (E)|id Solution − Step1− Elimination of Left Recursion & perform Left Factoring As there is no left recursion in Grammar so, we will proceed as it is. Also, there is no need for Left Factoring. Step2− Computation of FIRST FIRST(E) = FIRST(T) = FIRST(F) = {(, id} FIRST (E′) = {+, ε} FIRST (T′) = {*, ε} Step3− Computation of FOLLOW FOLLOW (E) = FOLLOW(E′) = {), $} FOLLOW (T) = FOLLOW(T′) = {+, ), $} FOLLOW (F) = ... Read More

Previous 1 ... 5 6 7 8 9 ... 15 Next
Advertisements