search
Log In

Recent questions tagged grammar

1 vote
3 answers
1
A given grammar is called ambiguous if two or more productions have the same non-terminal on the left hand side a derivation tree has more than one associated sentence there is a sentence with more than one derivation tree corresponding to it brackets are not present in the grammar
asked Jan 13 in Compiler Design Satbir 809 views
2 votes
2 answers
2
Given the grammar $s \rightarrow T ^{\ast} S\ \mid T$ $T \rightarrow U+T\ \mid U$ $U \rightarrow a \mid b$ Which of the following statements is wrong? Grammar is not ambiguous Priority of $+$ over $^{\ast}$ is ensured Right to left evaluation of $^{\ast}$ and $+$ happens None of these
asked Jan 13 in Compiler Design Satbir 314 views
1 vote
2 answers
3
A grammar is defined as $A \rightarrow BC$ $B \rightarrow x \mid Bx$ $C \rightarrow B \mid D$ $D \rightarrow y \mid Ey$ $E \rightarrow z$ The non terminal alphabet of the grammar is $\{A,B,C,D,E\}$ $\{B,C,D,E\}$ $\{A,B,C,D,E,x,y,z\}$ $\{x,y,z\}$
asked Jan 13 in Compiler Design Satbir 282 views
0 votes
0 answers
4
Modify the SDD of Fig. $5.25$ to include superscripts denoted by operator sup between boxes. If box $B_{2}$ is a superscript of box $B_{1}$, then position the baseline of $B_{2}\:0.6$ times the point size of $B_{1}$ above the baseline of $B_{1}.\text{Add}$ the new production and rules to the SDT of Fig. $5.26$.
asked Sep 7, 2019 in Compiler Design Lakshman Patel RJIT 94 views
0 votes
0 answers
5
Modify the SDD of Fig. $5.25$ to include a synthesized attribute $B.le$, the length of a box. The length of the concatenation of two boxes is the sum of the lengths of each. Then add your new rules to the proper positions in the SDT of Fig. $5.26$.
asked Sep 7, 2019 in Compiler Design Lakshman Patel RJIT 79 views
0 votes
0 answers
6
Write L-attributed SDT's analogous to that of Example $5.19$ for the following productions, each of which represents a familiar flow-of-control construct, as in the programming language C. You may need to generate a three address statement to jump to a particular ... have a jump from its middle to the next statement, so it is not sufficient simply to generate code for each statement in order.
asked Sep 7, 2019 in Compiler Design Lakshman Patel RJIT 42 views
0 votes
0 answers
7
Write L-attributed SDD's analogous to that of Example $5.19$ for the following productions, each of which represents a familiar flow-of-control construct, as in the programming language C. You may need to generate a three address statement to jump to a particular ... have a jump from its middle to the next statement, so it is not sufficient simply to generate code for each statement in order.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 27 views
1 vote
1 answer
8
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\:\{B.val=2\times B_{1}.val+1\}\mid 1 \:\{B.val=1\}$ Rewrite this SDT so the underlying grammar is not left recursive, and yet the same value of $B.val$ is computed for the entire input string.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 88 views
1 vote
1 answer
9
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, $a, b, c$, and $d$ are actions, and $0$ and $1$ are terminals.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 113 views
0 votes
0 answers
10
0 votes
0 answers
11
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\rightarrow E+T\mid T$ $T\rightarrow num.num\mid num$ Give an SDD to determine the type ... SDD of $(a)$ to translate expressions into postfix notation.Use the unary operator intToFloat to turn an integer into an equivalent float.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 105 views
0 votes
1 answer
12
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 $S.val$, the decimal-number value of an input string. For example, the translation of string $101.101$ should be the decimal number $5.625$.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 210 views
0 votes
0 answers
13
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 $S.val$ ... be the decimal number $5.625$. Hint: use an inherited attribute $L.side$ that tells which side of the decimal point a bit is on.
asked Sep 6, 2019 in Compiler Design Lakshman Patel RJIT 188 views
0 votes
0 answers
14
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 produces as output a transition table for a nondeterministic finite automaton recognizing the same language.
asked Aug 20, 2019 in Compiler Design Lakshman Patel RJIT 58 views
0 votes
0 answers
15
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 output a linear representation of the same list; i.e., a single list of the elements, in the same order that they appear in the input.
asked Aug 20, 2019 in Compiler Design Lakshman Patel RJIT 22 views
0 votes
0 answers
16
0 votes
0 answers
17
1 vote
0 answers
18
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 and "other statements," respectively. Build an LR parsing table for this grammar, resolving conflicts in the usual way ... your parser on the following inputs: if e then s ; if e then s end while e do begin s ; if e then s ; end
asked Aug 20, 2019 in Compiler Design Lakshman Patel RJIT 72 views
0 votes
0 answers
19
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\mid \cdot\cdot\cdot E\theta_{n}E\mid(E)\mid id$ ... of the tables for the two (ambiguous and unambiguous) grammars compare? What does that comparison tell you about the use of ambiguous expression grammars?
asked Aug 20, 2019 in Compiler Design Lakshman Patel RJIT 89 views
0 votes
1 answer
20
0 votes
0 answers
22
0 votes
0 answers
24
0 votes
0 answers
25
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 automaton (see the box on "Items as States of an NFA" in Section $4.6.5$ ... cases, the subset construction applied to the NFA that comes from the valid items for a grammar produces the $LR(0)$ sets of items.
asked Aug 20, 2019 in Compiler Design Lakshman Patel RJIT 13 views
0 votes
0 answers
26
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\neq j$ Show that: $G_{n}$, has $2n^{2}-n$ productions. $G_{n}$, has $2^{n} + n^{2} + n$ sets of $LR(0)$ items. $G_{n}$ is $SLR(1)$. What does this analysis say about how large $LR$ parsers can get?
asked Aug 20, 2019 in Compiler Design Lakshman Patel RJIT 70 views
1 vote
0 answers
29
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$ of Question $4.2.1$. The grammar $S\rightarrow S(S)\mid \epsilon$ of Question $4.2.2(c)$.
asked Aug 20, 2019 in Compiler Design Lakshman Patel RJIT 113 views
0 votes
0 answers
30
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 + + $according to the grammar of $S\rightarrow S S + \mid SS \ast \mid a$.
asked Aug 20, 2019 in Compiler Design Lakshman Patel RJIT 22 views
...