Recent questions tagged grammar

1 1 vote
1 1 answer
2.9k
2.9k views
The following SDT computes the value of a string of $0's$ and $1's$ interpreted as a positive, binary integer.$B\rightarrow B_{1}0\:\{B.val=2\times B_{1}.val\}\mid B_{1}1...
1 1 vote
1 1 answer
1.3k
1.3k views
Rewrite the following SDT:$A\rightarrow A\{a\}B\mid AB\{b\}\mid 0$$B\rightarrow B\{c\}A\mid BA\{d\}\mid 1$ so that the underlying grammar becomes non-left-recursive. Here...
0 0 votes
0 0 answers
723
723 views
We mentioned in Section $5.4.2$ that it is possible to deduce, from the LR state on the parsing stack, what grammar symbol is represented by the state. How would we disco...
0 0 votes
0 0 answers
1.8k
1.8k views
Below is a grammar for expressions involving operator $+$ and integer or floating-point operands. Floating-point numbers are distinguished by having a decimal point.$E\ri...
0 0 votes
1 1 answer
7.4k
7.4k views
This grammar generates binary numbers with a "decimal" point:$S\rightarrow L.L\mid L$$L\rightarrow LB\mid B$$B\rightarrow 0\mid 1$ Design an S-attributed SDD to compute $...
0 0 votes
0 0 answers
2.1k
2.1k views
This grammar generates binary numbers with a "decimal" point:$S\rightarrow L.L\mid L$$L\rightarrow LB\mid B$$B\rightarrow 0\mid 1$ Design an L-attributed SDD to compute $...
3 3 votes
0 0 answers
771
771 views
Write a $Yacc$ program that takes regular expressions (as defined by the grammar of Question $4.2.2(d)$, but with any single character as an argument, not just a) and p...
1 1 vote
0 0 answers
672
672 views
Write a $Yacc$ program that takes lists (as defined by the grammar of Question $4.2.2(e)$, but with any single character as an element, not just $a$) and produces as outp...
0 0 votes
0 0 answers
432
432 views
Write a $Yacc$ program that tells whether its input is a palindrome (sequence of characters that read the same forward and backward).
0 0 votes
0 0 answers
620
620 views
Write a $Yacc$ program that takes boolean expressions as input [as given by the grammar of Question $4.2.2(g)$] and produces the truth value of the expressions.
2 2 votes
0 0 answers
842
842 views
In Fig. $4.56$ is a grammar for certain statements, similar to that discussed in Question $4.4.12$. Again, $e$ and $s$ are terminals standing for conditional expressions ...
0 0 votes
0 0 answers
1.1k
1.1k views
The following is an ambiguous grammar for expressions with $n$ binary, infix operators, at $n$ different levels of precedence: $E\rightarrow E\theta_{1}E\mid E\theta_{2}E...
0 0 votes
1 1 answer
1.1k
1.1k views
Show that the following grammar$S\rightarrow Aa\mid bAc\mid Bc\mid bBa$$A\rightarrow d$$B\rightarrow d$is LR(1) but not LALR(1).
0 0 votes
1 1 answer
2.0k
2.0k views
Show that the following grammar$S\rightarrow Aa\mid bAc\mid dc\mid bda$$A\rightarrow d$is LALR(1) but not SLR(1).
0 0 votes
0 0 answers
463
463 views
For the grammar of Exercise $4.7.1$, use Algorithm $4.63$ to compute the collection of LALR sets of items from the kernels of the $LR(0)$ sets of items.
0 0 votes
0 0 answers
480
480 views
Repeat Exercise $4.7.1$ for each of the (augmented) grammars of Exercise $4.2.2(a)-(g)$.
0 0 votes
0 0 answers
592
592 views
Construct thecanonical LR, andLALR sets of items for the grammar $S\rightarrow S S + \mid S S \ast \mid a$ of Question $4.2.1$.
0 0 votes
0 0 answers
470
470 views
We suggested that individual items could be regarded as states of a nondeterministic finite automaton, while sets of valid items are the states of a deterministic finite ...
0 0 votes
0 0 answers
1.3k
1.3k views
Consider the family of grammars $G_{n}$, defined by:$S\rightarrow A_{i}b_{i}$ for $1\leq i\leq n$$A_{i} \rightarrow a_{j} A_{i}\mid a_{j}$ for $1\leq i,j\leq n$ and $i\ne...
0 0 votes
0 0 answers
720
720 views
Show that the following grammar:$S\rightarrow SA\mid A$$A\rightarrow a$is SLR(1) but not LL(1).
2 2 votes
0 0 answers
638
638 views
Show that the following grammar:$S\rightarrow AaAb\mid BbBa$$A\rightarrow \epsilon$$A\rightarrow\epsilon$is LL(1) but not SLR(1).
5 5 votes
0 0 answers
1.2k
1.2k views
Describe all the viable prefixes for the following grammars:The grammar $S\rightarrow 0S1\mid 01$ of Question $4.2.2(a)$.The grammar $S\rightarrow SS+\mid SS\ast\mid a$ o...
0 0 votes
0 0 answers
479
479 views
Give bottom-up parses for the following input strings and grammars: The input 000111 according to the grammar of $S\rightarrow 0\: S\: 1 \mid 0\: 1$.The input $aaa \ast a...
0 0 votes
0 0 answers
421
421 views
Repeat Question $4.5.1$ for the grammar $S\rightarrow S\: S + \mid S\: S \ast \mid a$ of Exercise $4.2.1$ and the following right-sentential forms:$SSS+a\ast+.$$SS+a\ast ...
0 0 votes
0 0 answers
372
372 views
For the grammar $S \rightarrow 0\: S\: 1 \mid 0\: 1$ of Question $4.2.2(a)$,indicate the handle in each of the following right-sentential forms:$000111$$00S11$
1 1 vote
0 0 answers
669
669 views
In Fig. 4.24 is a grammar for certain statements. You may take $e$ and $s$ to be terminals standing for conditional expressions and "other statements," respectively. If w...
0 0 votes
0 0 answers
363
363 views
Modify your algorithm of Question $4.4.9$ so that it will find, for any string, the smallest number of insert, delete, and mutate errors (each error a single character) n...
0 0 votes
0 0 answers
498
498 views
A grammar is said to be in Chomsky Normal Form (CNF) if every production is either of the form $A\rightarrow BC$ or of the form $A\rightarrow a$, where $A, B$, and $C$ ar...
0 0 votes
0 0 answers
376
376 views
A single production is a production whose body is a single nonterminal, i.e., a production of the form $A\rightarrow A$.Give an algorithm to convert any grammar into an $...
2 2 votes
0 0 answers
393
393 views
A grammar is $\epsilon$-free if no production body is $\epsilon$ (called an $\epsilon$-production).Give an algorithm to convert any grammar into an $\epsilon$-free gramma...