Homework 2
Structure of Programming Languages
NAME_________________________ SID________________
1. Consider the following declarations:
struct StudentRec
{
int age;
int ID;
float GPA;
char address[40];
}
typdef struct StudentRec[100] StudentTable1;
typdef struct StudentRec[100] StudentTable2;
struct StudentRect A[100],B[100];
StudentTable1 C,D;
StudentTable2 E;
Which variables are of equivalent type if the language uses each of the
following?
a) Domain equivalence
b) Name equivalence
c) Declaration equivalence
2. Trace the contents of the stack of activation records for the following
sample program written in the pseudolanguage.
CODE:
C() { }
D()
{
< declare > Z
}
B()
{
< declare > Y
C();
D();
}
A()
{
< declare > X,Y,Z
B();
}
F()
{
< declare > X
}
E()
{
< declare > Z
F();
}
Main()
{
< declare > X,Y
A();
E();
}
3. For a language with which you are familiar, what does your language use
for type equivalence, domain, name, or declaration.
4. Does your language perform implicit type conversions? If so, give an
example of two.
5. For a language with which you are familiar, find an example of a primitive
operation
(a) That has an implicit argument.
(b) That has a side effect.
(c) That is undefined for some data objects in its specified domain.
(d) That is self-modifying.
6. Pick a language and a data structure type in that language. List the
attributes of data objects of that type. List the operations
provided for data objects of that type. Determine the storage
representation for data objects of that type in your local implementation
of the language. Is there a run-time descriptor? What attributes are
stored in the descripror?
7. Give the accessing formula for computing the location of component,
A[I,J] of a matrix A declared as:
#define MAX2 10
#define MAX1 10
char A[MAX1][MAX2]
;where A is stored in column-major order.
8. Given the following C++ program segment:
class Test
{
private:
.....
public:
void Add(int g) { ... }
void Add(double s) { ... }
}
:
main()
{
Test t = new Test();
char x = '2';
float y = 4.2;
t.Add(x); //statement 1
t.Add(y); //statement 2
}
What happens during invocation of the two calls to the member function
Add in the main function? Does an type error occur? Explain.
9. Complete Lab 1.
The errors obtained using lex can be solved by removing all function
prototypes within the Lex code, and replacing the function definitions
as follows:
Ex.
int foo(int y, char * b)
Is replaced by:
int foo(y, *b)
int y;
char *b;
Turn in a scripted output of a source listing of your program along
with a sample test run as run on scs.howard.edu. Use following steps.
Steps:
1. $ script
2. $ ls -l
3. $ cat .
4. $ compile program
5. $ ls -l
6. $ run your program
7. $ exit
8. $ lp typescript
~