Q. What Is Input Buffering. What Is Sentinels?
Q. What Is Input Buffering. What Is Sentinels?
Q. What Is Input Buffering. What Is Sentinels?
What is
Sentinels?
S -> aABe
A -> Abc | b
B -> d
Step:
Example:
E --> E1 + T { E.val = E1.val + T.val}
Features –
High level specification
Hides implementation details
Explicit order of evaluation is not
specified
Q. Explain principle source of code
Types of attributes – There are two types of
optimization.
attributes:
Code optimization is used to improve the
1. Inherited Attributes. intermediate code so that the output of the
2. Synthesized Attributes – These are those program could run faster and takes less space.
attributes which derive their values from their It removes the unnecessary lines of the code
children nodes i.e. value of synthesized and arranges the sequence of statements in
attribute at node is computed from the values order to speed up the program execution
of attributes at children nodes in parse tree. without wasting resources. It tries to improve
Example: the code by making it consume less resources
E --> E1 + T { E.val = E1.val + T.val} (i.e. CPU, Memory) and deliver high speed.
In this, E.val derive its values from E 1.val and
T.val
A transformation of a program is called local if
it can be performed by looking only at the
Computation of Synthesized Attributes –
statements in a basic block; otherwise, it is
Write the SDD using appropriate
called global. Many transformations can be
semantic rules for each production in
performed at both the local and global levels.
given grammar.
Local transformations are usually performed
The annotated parse tree is generated and
first.
attribute values are computed in bottom
up manner.
The value obtained at root node is the
There are a number of ways in which a
final output. compiler can improve a program without
changing the function its computes.
Example: Consider the following grammar
S --> E Principal sources of code optimization are:
Optimized code:
x = 6;