Académique Documents
Professionnel Documents
Culture Documents
c c
c
c
c
c
c
c
Ê Ê
c
cc
c
cc
c Ê cccc
cc c
cc
c
c c
c c
Êc
Q1.Explain Static storage allocation.
ANS:
Ê
1. The size of the data object and constraints on its position in memory must be
known at compile time.
Fortran was designed to permit static storage allocation. A Fortran program
consists of a main program, subroutines, and functions, as in Fortran 77 program in
figure(a). Using memory organization of figure(b), the layout of the code and the
activation records for this program in figure(c). Within the activation record for
CNSUME, there is space for the locals BUF, NEXT, and C. The storage bound to
BUF holds a string of 50 characters. It is followed by space for holding an integer
value for NEXT and a character value for C. The fact that NEXT is also declared
in PRDUCE presents no problem, because the locals of the two procedures get
space in their respective activation records.
Since the sizes of the executable code and the activation records are known at
compile time, memory organizations other than the one in figure(c) are possible. A
Fortran compiler might place the activation record for a procedure together with
the code for that procedure. On some computer systems, it is feasible to leave the
relative position of the activation records unspecified and allow the link editor to
link activation records and executable code.
Void alloc_static()
int n;
Array[n]=n+1;
ANS:
If memory is repeatedly allocated, eventually the system will run out of memory.
d Allocate
d Free.
d Heap allocation: more general, but less efficient, more difficult to implement.
c
ANS:
Unlike other aspects of the compiler, the syntax analysis parts are not very
separable, since they are mixed up with calls to all other parts, such as semantic
analysis.
However the method used is that commonly known as ÿ ÿ This will
not be treated in great detail here - consult any book on compiler theory for details.
The method depends on writing a separate parsing procedure for each kind of
syntactic structure, such as u statement, assignment statement, expression and so
on, and each of these is only responsible for analysing its own kind of structure. If
any structure contains another structure then the parsing procedure can call the
procedure for this contained structure.
ANS: ANS: code generation is the process by which a compiler's code generator
converts some internal representation of source code into a form (e.g., machine
code) that can be readily executed by a machine .
Sophisticated compilers typically perform multiple passes over various
intermediate forms. This multi-stage process is used because many algorithms for
code optimization are easier to apply one at a time, or because the input to one
optimization relies on the processing performed by another optimization. This
organization also facilitates the creation of a single compiler that can target
multiple architectures, as only the last of the code generation stages (the ·^ )
needs to change from target to target.
The input to the code generator typically consists of a parse tree or an abstract
syntax tree. The tree is converted into a linear sequence of instructions, usually in
an intermediate language such as three address code.
ANS:
In POSIX, a file descriptor is an integer, specifically of the C type int. There are 3
standard POSIX file descriptors which presumably every process (save perhaps a
daemon) should expect to have:
The FILE * file handle in the C standard I/O library routines is technically a
pointer to a data structure managed by those library routines; one of those
structures usually includes an actual low level file descriptor for the object in
question on Unix-like systems. Since
^
refers to this additional layer, it is
not interchangeable with
ÿÿ.
^
to refer to the more low-level construct, akin to POSIX's file descriptors.
Microsoft's C libraries also provide compatibility functions which "wrap" these
native handles to support the POSIX-like convention of integer file descriptors as
detailed above.
Q6.Differentiate top down and bottom up parsing.
Ê
u
according to a grammar G attempts to derive a string
matching a source string through a sequence of derivations starting with the
distinguished symbol G. Top-down parsing is determining how to interpret a
particular piece of data by splitting around non terminals first and sorting these into
a hierarchy that ends with terminals.
££
constructs a parse tree for a source string through a
sequence of reductions. The source string is valid if it can be reduced to S ,the
distinguished symbol of G. Bottom up parsing proceeds in a left to right manner ,
ie. Attempts at reduction start with the first symbol in the string and proceed to the
right. Bottom-up parsing is determining how to interpret a particular piece of data
by resolving sets of terminals into terminals themselves, and branching up until the
whole set has been resolved