Question

In: Computer Science

Give context free grammars for the languages below. To avoid mistakes, I recommend using scratch paper...

Give context free grammars for the languages below. To avoid mistakes, I recommend using scratch paper to check that your grammars produce the right set of string. This question is structured so that nonterminals (and associated rules) from an earlier subquestion might be useful in a grammar for a later sub-question. That’s why, rather than “S” as the start symbol, we will used different start symbols for each part. If you do use a nonterminal from an earlier sub-question, say something like “see part a”.

Let sigma ( Σ ) be the set {a, b}


a. All possible strings over sigma including the empty string. Use P as the start symbol.

b. Stings over sigma that contain no b's (and any number of a's). Use T as your start symbol.

c. Strings over sigma that contain exactly one b (and any number of a's) Use U as your start symbol.

d. Strings over sigma that contain exactly two b's (and any number of a's)  Use V as your start symbol

e. Strings over sigma that contain exactly three b’s (and any number of a's) Use W as your start symbol.

f) Strings over sigma that contain at most three b's (and any number of a's). Use X as your start symbol

f. Strings over sigma that contain a multiple of three b's (and any number of a's). (including strings with b's at all). Use Y as your start symbol.

Solutions

Expert Solution

a)

P -> PaP | PbP | a | b | epsilon

It will take empty string epsilong and all other strings of combination of a and b can be formed.

b)

T -> aT | epsilon

Here any number of a will come and ends by epsilon but no b will come.

c)

U -> TbT | b

T -> aT | epsilon (from b)

Any number of a will come before and after b.

d)

V -> UU

U -> TbT | b (from c)

T -> aT | epsilon (from b)

There were exactly one b in c and we use it 2 times for exactly 2 b.

e)

W -> UUU

U -> TbT | b (from c)

T -> aT | epsilon (from b)

There were exactly one b in c and we use it 3 times for exactly 3 b.

f)

X -> T | U | V | W

V -> UU (from d)

W -> UUU (from e)

U -> TbT | b (from c)

T -> aT | epsilon (from b)

Atmost 3 b means b can be 0, use T, can be 1, use U, can be 2, use V, and can be 3, use W.

g)

Y -> YW | epsilon

W -> UUU (from e)

U -> TbT | b (from c)

T -> aT | epsilon (from b)

Here W gives exactly 3 b. And Y can be any number of times of W means any number of times of 3, i.e., b will be in multiple of 3.


Related Solutions

Give context free grammars for the languages below. To avoid mistakes, I recommend using scratch paper...
Give context free grammars for the languages below. To avoid mistakes, I recommend using scratch paper to check that your grammars produce the right set of string. This question is structured so that nonterminals (and associated rules) from an earlier subquestion might be useful in a grammar for a later sub-question. That’s why, rather than “S” as the start symbol, we will used different start symbols for each part. If you do use a nonterminal from an earlier sub-question, say...
Closure under Context-Free Languages Show that the following operations are closed under context-free languages: union concatentation...
Closure under Context-Free Languages Show that the following operations are closed under context-free languages: union concatentation Kleene star
Prove the following Closure Properties with respect to Context Free Languages. 1. Show that Context Free...
Prove the following Closure Properties with respect to Context Free Languages. 1. Show that Context Free Languages are Closed under union(∪), concatenation(·), kleene star(*). (Hint: If L1 and L2 are Context Free languages then write Context Free grammar equivalent to L1 ∪ L2, L1 · L2, L∗ 1 ) 2. Show that if L1 and L2 are Context Free Languages, then L1 ∩ L2 is not necessarily Context Free. (Hint: Use Proof by Counter Example)
(a) How Context Free languages are different from Regular languages. (b) What are the automata accepting...
(a) How Context Free languages are different from Regular languages. (b) What are the automata accepting those languages and how they are different from DFA and NFA. (c) How the grammar of Context Free Languages looks different from those in Regular languages.
1. regular expressions as a mechanism to specify tokens, 2. defining context-free grammars for language constructs,...
1. regular expressions as a mechanism to specify tokens, 2. defining context-free grammars for language constructs, and 3. derivation of language terms and expressions based on a context-free grammar. 1 Regex 1. Define the regex for the following description of tokens: (a) Any string that starts with character t (b) Any string of at least length 3 that starts with t and ends with u (c) Any string that specifies the range of numbers between 11 and 23. (d) Any...
Prove that all regular languages are context free. Note: Proof must proceed by structural induction on...
Prove that all regular languages are context free. Note: Proof must proceed by structural induction on regular expressions Please prove by Structural Induction. Will Upvote for correct answer. Thanks
On your scratch paper, write the formulas for the slope and the y-intercept. Using the values...
On your scratch paper, write the formulas for the slope and the y-intercept. Using the values given in the summary table, record how to calculate by hand the slope and y-intercept of the lime. Show all steps. State the final results as the equation of the line. Summary Statistics r = 0.772724. mean length = 3517.94 standard deviation for length = 1623.46 mean duration = 126.4 standard deviation for duration = 43.6616 Within reasonable round off error, your equation should...
Give examples of languages L1 and L2 over {a, b} that satisfy the descriptions below: (a)...
Give examples of languages L1 and L2 over {a, b} that satisfy the descriptions below: (a) L1 is regular, L2 is nonregular, and L1 U L2 is regular; (b) L1 is regular, L2 is nonregular, and L1 U L2 is nonregular; (c) L1 is regular, L2 is nonregular, and L1 n L2 is regular; (d) L1 is nonregular, L2 is nonregular, and L1 U L2 is regular. (e) L1 is nonregular, L2 is nonregular, and L1 n L2 is regular.
Regular => Context-Free Give a proof by induction on regular expressions that: For any language A,...
Regular => Context-Free Give a proof by induction on regular expressions that: For any language A, if A is regular, then A is also context-free. You may assume that the statements from the previous Closure under Context-Free Languages problem are proved. R is a regular expression if RR is: a for some a∈alphabet Σ, the empty string ε, the empty set ∅, R​1​​∪R​2​​, sometimes written R​1​​∣R​2​​, where R​1​​ and R​2​​ are regular expressions, R​1​​∘R​2​​, sometimes written R​1​​R​2​​, where R​1​​ and...
Avoid plagiarism.. I want from your word please Q1 Give example of company using ABC costing...
Avoid plagiarism.. I want from your word please Q1 Give example of company using ABC costing and explain the process used in this company to assign costs in an ABC system? (Week 7: , ABC costing) Answer:       Q 2 Give examples of questions managers could ask to help them identify relevant qualitative factors that will be used before making decision? (Week 9: ,   Relevant information for decision making) Answer:       Q 3 Kadhim Co. manufactures product B which is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT