Question

In: Computer Science

For the following grammars, write the leftmost derivation for the strings given with each. Next to...

  1. For the following grammars, write the leftmost derivation for the strings given with each. Next to each derivation step, write the number of the rule used. Do not combine steps.
  2. grammar (6 rules), Σ = {0, 1}:

S -> A1B

A -> 0A | ε

B -> 0B | 1B | ε

strings (3): 1, 0011, 01010

  1. grammar (6 rules), Σ = { +, x, a, (, ) }

E -> E + T | T

T -> T x F | F

F -> (E) | a

strings (3): a, a x a, (a) + a x a,

  1. grammar (4 rules), Σ = {(, ), [, ]}:

S -> (S) | [S] | SS | ε

strings (3): ( ), [ ] ( ), ( [ ] )  

Solutions

Expert Solution

R1:S-> A1B
R2:A-> 0A
R3:A->ε
R4:B-> 0B
R5:B->1B
R6:B->ε


For string- 1
First we must use R1 because S is starting symbol
S -> A1B {leftmost variable is A therefore used R3}
=>1B { there is only one variable B used R6}
=>1 Answer
For String 0011
S -> A1B {R1}
=>0A1B {Leftmost variable is A used used R2}
=>00A1B {Leftmost variable is A used used R2}
=>001B {Leftmost variable is A used used R3}
=>0011B { there is only one variable B used R5}
=>0011 {there is only one variable B used R6}

S==>0011 Answer



Related Solutions

Draw parse trees for nine strings in question one, using their grammars. For the following grammars,...
Draw parse trees for nine strings in question one, using their grammars. For the following grammars, write the leftmost derivation for the strings given with each. Next to each derivation step, write the number of the rule used. Do not combine steps.   grammar (3 rules), Σ = {a, b}: S -> aSbS | bSaS | ε strings (3): ab, baab, bbaa grammar (6 rules), Σ = {0, 1}: S -> A1B A -> 0A | ε B -> 0B |...
Given the nested collection that maps each term to a set of strings   Return a string...
Given the nested collection that maps each term to a set of strings   Return a string of terms that are repeated in all the nested sets Given : {apple=[apple BALL carrot, ball !carrot! ,!Dog*&]} {apple=[apple BALL carrot, ball !carrot! ,!Dog*&], dog=[ball !carrot! ,!Dog*&]} Return: [ball !carrot! ,!Dog*&] Public static String common(Map<String, Set<Sting>> map) { }
Write a progrm that accepts two strings as input, then indicates if the two strings are...
Write a progrm that accepts two strings as input, then indicates if the two strings are equal when the case of individual letters is ignored. Sample runs are shown below. Use C++ Enter two strings. String 1: PROgraM String 2: proGram PROgraM and proGram are equal. Enter two strings. String 1: litter String 2: LittLe litter and LittLe are not equal.
Given two ArrayLists of Strings (ArrayList<String>), write a Java method to return the higher count of...
Given two ArrayLists of Strings (ArrayList<String>), write a Java method to return the higher count of the characters in each ArrayList.  For example, if list1 has strings (“cat, “dog”, “boat”, “elephant”) and list 2 has strings (“bat”, “mat”, “port”, “stigma”), you will return the value 18.  The list 1 has 18 characters in total for all its strings combined and list2 has 16 characters for all of its strings combined.  The higher value is 18. If the character count is the same, you...
With being given two n-bit binary strings, verify if the strings are identical or not. Design...
With being given two n-bit binary strings, verify if the strings are identical or not. Design a procedure showing all steps and write a pseudo-code. What is the complexity of the procedure? If it can tolerate some error, is there a better than linear time solution? If so, write the pseudo-code.
find a patternin the following sequences and write the next two terms. classify each seqences as...
find a patternin the following sequences and write the next two terms. classify each seqences as arithmetic geometic or neither                                                                                  1,4,16,64,        and     3,6,9,12
Write your code inside of SecondProgrammingExam.java including all Part I: Given two strings, a and b,...
Write your code inside of SecondProgrammingExam.java including all Part I: Given two strings, a and b, create a bigger string made of the first char of a, the first char of b, the second char of a, the second char of b, and so on. Any leftover chars go at the end of the result. mixString("abc", "xyz") → "axbycz" mixString("Hi", "There") → "HTihere" mixString("xxxx", "There") → "xTxhxexre" Part II: Given an array of integers create an array of integers in...
Write your code inside of SecondProgrammingExam.java including all Part I: Given two strings, a and b,...
Write your code inside of SecondProgrammingExam.java including all Part I: Given two strings, a and b, create a bigger string made of the first char of a, the first char of b, the second char of a, the second char of b, and so on. Any leftover chars go at the end of the result. mixString("abc", "xyz") → "axbycz" mixString("Hi", "There") → "HTihere" mixString("xxxx", "There") → "xTxhxexre" Part II: Given an array of integers create an array of integers in...
Python 8.17 LAB: Strings of a Frequency Write a program that reads whitespace delimited strings (words)...
Python 8.17 LAB: Strings of a Frequency Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, the program outputs the strings from words that have a frequency equal to freq in a case insensitive manner. Your specific task is to write a function wordsOfFreqency(words, freq), which will return a list of strings (in the order in which they appear in the original list) that have a frequency same as the function parameter freq. The parameter...
write both non-recursive and recursive functions that take the strings from the user and display strings...
write both non-recursive and recursive functions that take the strings from the user and display strings in backwards in python
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT