Thursday, March 24, 2016
Discuss the capabilities of CFG
12:59 PM
No comments
The capabilities of CFG :
Context free grammars are capable of describing most of the syntax of programming language. suitable grammars for expressions can often be constructed using associatively & precedence information. So, context free grammar are most useful in describing nested structures such as balanced parentheses, matching begin-end's, corresponding if-then-else's & so on. These nested structures cannot be described by regular expression. The following grammars the string, which serves the language.
Stat if cond then stat
| if cond then stat else stat
|other -stat.What is CFG?Advantages of CFG
12:52 PM
No comments
Context Free Grammar : A CFG is a way of describing language by recursive rules. A CFG consists four tuples, denoted G = {V, T, P, S}
Where,
V = Finite set of variables. [Eg. {S, E}etc.]
T = Finite set of terminals. [Eg. {a, b, c,+}etc.]
P = Finite set of productions. [Eg. E E+E]
S = Start symbol.
Example :
Let a CFG which is given :
Here, V = {E}
T = {+, *, id}
S = E
So, the grammar notation is written as; G = (E, {+, *, id}, P, E)
Advantages of context free grammar :
- A grammar give a precise, yet easy to understand, syntactic specification of a programming language.
- An efficient parser can be constructed automatically from a properly designed grammar.
- A grammar imparts a structure to a program that is useful for its translation into object code for the detection of errors.
- Language ecvolved over a period of time.acquiring new constructs & performing additional tasks.
What is drawback of operator precedence parsing?
12:46 PM
No comments
Drawback of operator precedence parsing :
- Difficult to find token from the operator precedence parsing.
- It is itself tenuous. One can't always be sure the parser accepts exactly the desired language.
- Only a small class of grammar can be using operator precedence techniques.
What is Context Free Grammar With Example?
12:36 PM
No comments
Context Free Grammar : A CFG is a way of describing language by recursive rules. A CFG consists four tuples, denoted G = {V, T, P, S}
Where,
V = Finite set of variables. [Eg. {S, E}etc.]
T = Finite set of terminals. [Eg. {a, b, c,+}etc.]
P = Finite set of productions. [Eg. E E+E]
S = Start symbol.
Example :
Let a CFG which is given :
Here, V = {E}
T = {+, *, id}
S = E
So, the grammar notation is written as; G = (E, {+, *, id}, P, E)
What are the differences between single pass & multi-pass compiler?
12:25 PM
No comments
Single Pass Compiler | Multi-Pass Compiler |
---|---|
1. Single pass compiler can be made to use more space than multi-pass compiler | 1. Multi - pass compiler can be made to use less space than a single -pass compiler |
2. Single pass compiler is faster than a multi -pass compiler | 2. Multi - pass compiler is slower than a single pass compiler because each pass reads & writes an intermediate file. |
Translate the expression -
11:55 AM
No comments
Translate the expression -
-(a+b)*(c+d)+(a+b+c) into (ii) Quadruples
At first we construct the three address code the above expression :
Three address code :
0) T1 : = a+b
1) T2 : = -T1
2) T3 : = c+d
3) T4 : = T2*T3
4) T5 : = a+b
5) T6 : = T5+c
6) T7 : = T4+T6
-(a+b)*(c+d)+(a+b+c) into (ii) Quadruples
At first we construct the three address code the above expression :
Three address code :
0) T1 : = a+b
1) T2 : = -T1
2) T3 : = c+d
3) T4 : = T2*T3
4) T5 : = a+b
5) T6 : = T5+c
6) T7 : = T4+T6
SL NO | OP | ARG1 | ARG2 | RESULT |
---|---|---|---|---|
(0) | + | a | b | T1 |
(1) | uminus | T1 | - | T2 |
(2) | + | c | d | T3 |
(3) | * | T2 | T3 | T4 |
(4) | + | a | b | T5 |
(5) | + | T5 | c | T6 |
(6) | + | T4 | T6 | T7 |
Fig. (a) quadruple.
Translate the following assignment statement A : = -B*(C+D) into three address, quadruple & triple forms
11:39 AM
No comments
Here, given the expression - A: = -B*(C+D)
Three-address code :
T1 : = -B
T2 : = C+D
T3 : = T1+T2
A : = T3
These statement are represented by quadruples as shown in fig . (a)
SL NO | OP | ARG1 | ARG2 | RESULT |
---|---|---|---|---|
(0) | Uminus | B | - | T1 |
(1) | + | C | D | T2 |
(2) | * | T1 | T2 | T3 |
(3) | := | T3 | - | A |
Fig. (a) quadruple representation of three -address statements.
These statement are represented by triples as shown in fig . (b)
SL NO | OP | ARG1 | ARG2 |
---|---|---|---|
(0) | Uminus | B | - |
(1) | + | C | D |
(2) | * | (0) | (1) |
(3) | := | A | (2) |
Fig. (b) triple representation of three -address statements.