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 |...
Let G be any context-free grammar. Show that the number of strings that have a derivation...
Let G be any context-free grammar. Show that the number of strings that have a derivation in G of length n or less, for any n > 0, is finite. Could you please answer with clear explanation. The question is from Elaine Rich's Automata, Computability and Complexity Chapter 11 Exercise 14.
Write a program that prompts the user to enter a series of strings, but with each...
Write a program that prompts the user to enter a series of strings, but with each string containing a small integer. Use a while loop and stop the loop when the user enters a zero. When the loop has finished, the program should display: the number of user inputs (not counting the final zero input). the total of the integers in the strings entered. the average of the integers accurate to one decimal place. Any help is greatly appreciated, this...
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) { }
3. Write a Java program that generates a set of random strings from a given string...
3. Write a Java program that generates a set of random strings from a given string of same length where no character is ever repeated and characters belong to the original string. Examples Input: “Hello World” Output: “World oHlel”
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...
use java Write a program that, given two binary numbers represented as strings, prints their sum...
use java Write a program that, given two binary numbers represented as strings, prints their sum in binary. The binary strings are comma separated, two per line. The final answer should not have any leading zeroes. In case the answer is zero, just print one zero i.e. 0 Input: Your program should read lines from standard input. Each line contains two binary strings, separated by a comma and no spaces. Output: For each pair of binary numbers print to standard...
write a java prog that include an array of strings of size 50    String[] strings...
write a java prog that include an array of strings of size 50    String[] strings = new String[50]; then find the max length of the inputs inside a method keep reading from the user until user enters keyword to stop input : may ala jony ram asd fgghff daniel jwana output : max length : 10
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT