What is Context Sensitive Grammar

Bhanu Priya
Updated on 15-Jun-2021 11:30:50

10K+ Views

The Context sensitive grammar (CSG) is defined as G=(V, Σ, P, S)Where, V: Non terminals or variables.Σ: Input symbols.P: Production rule.P:{αAβ → αγβ, A ϵ V, α ϵ (V∪Σ)*, β ϵ (V∪Σ)*S: Starting symbol.ExampleaS→SAa|aAaA→abcIn context sensitive grammar, there is either left context or right context (αAβ i.e. α is left context and β is right) with variables.But in context free grammar (CFG) there will be no context.For example in production ruleS →0 B S 2 ,B 0 → 0 BWe cannot replace B until we get B0.Therefore, CSG is harder to understand than the CFG.The CFG, CSG and the unrestricted ... Read More

Operator Grammar and Precedence in Parser

Bhanu Priya
Updated on 15-Jun-2021 11:29:18

3K+ Views

If the grammar satisfies the following two conditions, then we can say that type of grammar is called as operator precedence grammar.If ε is on its RHS then there exists no production rule.If two non-terminals are adjacent to each other on its RHS then there exists no production rule.Operator Grammars have the property that no production right side is empty or has two adjacent non-terminals.ExampleE-> E A E | idA-> + | *The above grammar is not an operator grammar but we can convert that grammar into operator grammar like −E-> E + E | E * E | idThere ... Read More

Convert CFG to Greibach Normal Form

Bhanu Priya
Updated on 15-Jun-2021 11:26:20

18K+ Views

A Context Free Grammar (CFG) is said to be in Greibach Normal Form(GNF), if production rules satisfy one of the following criteria −Only a start symbol can generate ε. For example, if S is the start symbol then S → ε is in GNF.A non-terminal can generate a terminal. For example, if A is Non terminal and a is terminal then, A → a is in GNF.A non-terminal can generate a terminal followed by any number of non-terminals. For Example, S → aAS is in GNF.Case 1G1 = {S → aAB | aB, A → aA| a, B → bB ... Read More

Union and Intersection of Regular Languages with CFL

Bhanu Priya
Updated on 15-Jun-2021 11:24:21

2K+ Views

We know that the languages accepted by finite automata (FA) are called regular languages and the languages accepted by push down automata (PDA) are called context free languages (CFG).Closure of CFLs under UnionCFL is the short form for Context Free Language. Here the CFL is as follows −G = (V, Σ, R, S) such that L(G) = L(G1) ∪ L(G2)Thus, V = V1 ∪ V2 ∪ {S} (the three sets are disjoint)Σ = Σ1 ∪ Σ2R = R1 ∪ R2 ∪ {S → S1|S2}Union of Regular language with CFGIf all regular languages are context-free then union of both results is ... Read More

Differentiate Between Mealy Machine and Moore Machine in TOC

Bhanu Priya
Updated on 15-Jun-2021 11:21:53

20K+ Views

Mealy MachineIn a Mealy machine the output symbol depends upon the present input symbol and present state of the machine.In the Mealy machine, the output is represented with each input symbol and each state is separated by /.The Mealy machine can be described by six tuples (Q, q0, Σ, O, δ, λ')Where, Q: Finite set of states.q0: Initial state of machine.Σ: Finite set of input alphabet.O: Output alphabet.δ: Transition function where Q × Σ → Q.λ': Output function where Q × Σ → O.In the Mealy machine, the output is represented with each input symbol and each state is separated ... Read More

Explain the Cross Product Method Process in DFA

Bhanu Priya
Updated on 15-Jun-2021 07:01:52

2K+ Views

The cross product method process in the deterministic finite automata (DFA) is explained below −Let a's DFA diagram has m number of states and b's DFA diagram has n number of states the cross product m x n will have mxn states.Languages represented by even number of ‘a’ and even number of ‘b’ are given below −L1 = {ε, baa, aa, aba, aab, aaaa, ... }L2 = {ε bb, abb, bab, bba, ...}After cross product we will find the DFA as mentioned below −As, L = {ab, aab, abb, aaab, ...}ExampleLet’s taken two DFAsEven number of a'sEven number of b'sThe ... Read More

Explain Union Process in DFA

Bhanu Priya
Updated on 15-Jun-2021 06:55:09

3K+ Views

The union process in the deterministic finite automata (DFA) is explained below −If L1 and If L2 are two regular languages, their union L1 U L2 will also be regular.For example, L1 = {an | n > O} and L2 = {bn | n > O}L3 = L1 U L2 = {an U bn | n > O} is also regular.ProblemDesign a DFA over an alphabet {a, b} where the start and end are of different symbols.SolutionThere are two different types of languages are formed for a given condition −L1={ab, aab, abab, abb, …….}L1={ab, aab, abab, abb, …….}Here, L1= starts ... Read More

Construct DFA of a String with Second Symbol from RHS as 'a'

Bhanu Priya
Updated on 15-Jun-2021 06:52:53

4K+ Views

A Deterministic Finite automaton (DFA) is a 5-tuplesM=(Q, Σ, δ, q0, F)Where, Q : Finite set called states.Σ : Finite set called alphabets.δ : Q × Σ → Q is the transition function.q0 ϵ Q is the start or initial state.F : Final or accept state.ProblemDesign a finite automaton where the second symbol from the right hand side is ‘a’.SolutionThe language for a given string over an alphabet {a, b} is −L={aa, abaa, abbab, aaabab, ………}ExampleInput − aabaOutput − Not acceptedBecause the second letter from right hand side is not aInput − aabbabOutput − AcceptedIt is complicated to directly construct ... Read More

Design DFA for Language Over 0, 1 Accepting Strings with Odd Number of 1's and Even Number of 0's

Bhanu Priya
Updated on 15-Jun-2021 06:50:08

5K+ Views

A Deterministic Finite automaton (DFA) is a 5-tuplesM=(Q, Σ, δ, q0, F)Where, Q : Finite set called states.Σ : Finite set called alphabets.δ : Q × Σ → Q is the transition function.q0 ϵ Q is the start or initial state.F : Final or accept state.ProblemConstruct a DFA machine accepting odd numbers of 1’s and even number of 0’s.SolutionDesign two separate machines for the two conditions over an alphabet Σ={0, 1}:DFA accepts only an odd number of 1’s.DFA accepts only even number of 0’s.Here, s1 = starts2=odd 1 or start 11s3= starts 11 accepted and stay theres4 = accept even ... Read More

Construct NFA Accepting Strings with Even Number of 0s or Odd Number of 1s

Bhanu Priya
Updated on 15-Jun-2021 06:47:51

15K+ Views

Non-deterministic finite automata (NFA) also have five states which are same as DFA, but with different transition function, as shown follows −δ: Q X Σ → 2QWhere, Q : Finite set called states.Σ : Finite set called alphabets.δ : Q × Σ → Q is the transition function.q0 ϵ Q is the start or initial state.F : Final or accept state.ProblemConstruct NFA over an alphabet Σ={0, 1}.SolutionDesign two separate machines for the two conditions, as given below −NFA accepting only odd number of 1’sNFA accepting only even number of 0’sNFA accepting only odd number of 1’s over an alphabet Σ= ... Read More

Advertisements