Write a grammar in which a nonterminal occurs that is both dead and unreachable.
A useless nonterminal is a nonterminal that can never be used in
a "successful" derivation; that is, a derivation that starts with
the start symbol and ends with a terminal strings. Therefore, we
can delete all productions that contain any useless nonterminals
without changing the language generated by the grammer. There are
two types of useless nonterminals: unreachable and dead.
An unreachable nonterminal is one that can never appear in a
derivation that starts with the start symbol.
The second kind of useless nonterminal, a dead nonterminal, is one
from which a termina string cannot be derived.
S --> b
B --> bB
B is both unreachable and dead.
Write a grammar in which a nonterminal occurs that is both dead and unreachable.
1.) Consider the following grammar in which S, A, and B are nonterminal symbols and S is the start symbol. S → 1A | 0B A → A0 | 1B B → 10A| 1 Show that the grammar is ambiguous by showing two parse trees for the sentence 1110110 using leftmost derivation.
Consider the following grammar (S, A, B, and C are nonterminal symbols; S is the start symbol; 0 and 1 are terminal symbols): S → AA A → BCB B → B0 | B1 | 0 | 1 C → 00 | 11 Which of the following sentences are in the language generated by the grammar? Show derivations for the sentences that can be generated. If a sentence cannot be generated by the grammar, explain why. a) 10010001 b) 01101101...
Consider the following grammar: A -> aB | b | cBB B -> aB | bA | aBb C -> aaA | b | caB Perform the pairwise disjoint test for the grammar. Rewrite the above grammar so that all grammar rules pass the pairwise disjoint test. Suppose lex() is the lexical analyzer which gets the next lexeme and puts its token code in the global variable nextToken. And suppose the token codes for terminals a, b, and c are...
A grammar is a 4-tuple G, G = (Ν, Σ, Π, Σ, S) where, Ν is a finite set of nonterminal symbols, Σ is a finite set of terminal symbols, Π is a finite set of rules,S is the starting symbol. Let, Ν = {S, T} Σ = {a, b, c} Π = { S -> aTb S -> ab aT -> aaTb aT -> ac } S is the starting symbol. A) Prove that the given grammar G is...
1 - Semantics - Attributes Grammar (25 points) Using the following grammar write an attributes grammar that can calculate the decimal value of an octal number. Grammar: number = list list = list octal octal octal = '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7' Notes: An octal number consists of octal digits, i.e. O to 7. The following example shows how to convert the octal 67 to its equivalent decimal. The symbol star represents multiplication. 67 = 6*87 + 7* 8° = 6 * 8 +...
Write a context-free grammar that generates the same language as regular expression which is ab*|c+ (Describe the four components of context-free grammar which are start symbol(S), non-terminals(NT), terminals(T), and set of production rules(P))
Using the following grammar write an attributes grammar that can calculate the decimal value of an octal number. Grammar: number = list list = list octal | octal octal = ‘0’ | ‘1’ | ‘2’ | ‘3’ | ‘4’ | ‘5’ | ‘6’ | ‘7’ Notes: An octal number consists of octal digits, i.e. 0 to 7. The following example shows how to convert the octal 67 to its equivalent decimal. The symbol star represents multiplication. 67 = 6 *...
Consider the following grammar G, whose productions rules are the following (an upper case letters represents a nonterminal symbol, a lower case letter represents a terminal symbol). Untitled Note Eile Edit Format View Help S -asCB A b A -aA C B d A Which of the following sentences are in the language generated by the grammar G? |Untitled - Notepad X Eile Edit Format View Help А. асcbd B. abcd c. acccbcc D. acd Е. ассс F. CCC G....
Write an equivalent grammar without left-recursive
rules.
5. Write an equivalent grammar without left-recursive rules. S+SAB A → AaA| a | AB B + Bb | 6
1) a. Write down an unambiguous grammar that generates the set of strings { s;, s;s, s;s;s;, . . . } b. Give a leftmost and rightmost derivation for the string s;s; using your grammar.