Sei sulla pagina 1di 13

SP2010

Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

1. Which statement is true regarding the Language Evaluation Criteria of


Simplicity and Orthogonality?
a)

Simplicity is same as Orthogonality.

b)

Simplicity includes Orthogonality.

c)

Orthogonality includes Simplicity.

d)

None of above is true.

2. Which statement is true regarding the Language Evaluation Criteria of


Simplicity and Multiplicity?
a)

Simplicity means having only one way to accomplish a particular operation.

b)

Multiplicity means having more than one way to accomplish a particular operation.

c)

Multiplicity includes Simplicity.

d)

None of above is true.

3. What is the lowest syntactic unit in programming language?


a) Token.
b)

Lexeme.

c)

Variables.

d)

Parse Tree.

4. Which construct does not meet the concept of Orthogonality?


a)

User-defined data types

b)

Dynamic arrays

University of Northern Virginia


1/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

c)

Floating-point

d)

None of above

5. Which statement is true regarding Smalltalk?


a)

It is a compling system

b)

The program units are objects

c)

It is an Object-Oriented programming language

d)

All of above

Use this Grammar to complete the following questions


An Unambiguous Grammar for Simple Assignment Statements

<assign> <id> := <expr>


<id> A | B | C
<expr> <expr> + <term>

<term> <term> * <factor> |


<factor> ( <expr> )

<term>

<expr> - <term>

<factor>

<id>

Return the answer in a different paper, scan or picture them, and send back
with the answers.

6.

B := (A + B ) * (B C)

University of Northern Virginia


2/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

7.

C := A B * C + A * (B + C)

8.

A := A * (C A + B) * (A B)

9.

B := B C * A + B

10.

C := (B C * A) * (B C)

11. According to the following grammar, please select a true statement.


A Grammar for Simple Assignment Statements

<assign> <id> := <expr>


<id> A | B | C
<expr> <expr> + <term>

<term>

<expr> - <term>

<term> <term> * <expr> | ( <factor> ) | <id>


a)

This grammar does not give the precedence over the multiplication operator and
parenthese operator.

b)

This grammar will only generate one parse tree

c)

This grammar does not give the precedence over the multiplication operator and
addition/subtraction operator.

d)

None of above.

University of Northern Virginia


3/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

12. Which statement is true regarding to an ambiguity grammar?


a)

It will always generate more than one parse tree in an ambiguity grammar.

b)

If a grammar can not tell the operator precedence, it is then an ambiguity grammar.

c)

If a grammar can not tell the operator associativity, it is then an ambiguity grammar.

d)

All of above.

13. According to the following grammar, please select a true statement.

<stmt> <matched> | <unmatched>


<matched> if <logic_expr> then <matched> else <matched>
| any non-if statement
<unmatched> if <logic_expr> then stmt>
| if <logic_expr> then <matched> else <unmatched>

a)

This is an ambiguous grammar.

b)

This grammar defines that between a then and its matching else, an if
statement without an else is not allowed.

c)

This grammar defines an unmatched statement is always placed after else clause.

d)

None of above.

14. Which statement is true regarding keywords and reserved words in


programming languages?
a)

A keyword is also a reserved word.

b)

A reserved word must be a key word.

University of Northern Virginia


4/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

c)

A keyword can be re-defined and a reserved word can not be re-defined.

d)

A keyword is much more important than a reserved word.

15. Which statement is true regarding a variable?


a)

A variable must associate with a memory address when declared

b)

A variable must be defined with a data type when declared

c)

A variable must be assigned a value when memory storage is allocated.

d)

None of above

16. What does data type mean to a variable?


a)

Data type defines the valid range of values to a variable.

b)

Data type defines the size of memory storage to be allocated to a variable.

c)

Data type defines the set of operations that are defined for values of the type.

d)

All of above

17. Which statement is true regarding Static Binding?


a)

A binding must happen before run time.

b)

A binding remain unchanged throughout program execution.

c)

A binding must happen during run time and remain unchanged throughout program
execution.

d)

None of above.

18. If a data type is dynamically bound to a variable during the program


execution, then which statement is true?
a)

The memory allocation to the variable must also be dynamically allocated.

University of Northern Virginia


5/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

b)

No data type is allowed dynamically bound to a variable during the program

execution.
c)

The memory allocation must happen before data type binding.

d The variable is bound to a type when it is assigned a memory location.

19. When does a variable start to have a life?


a)

When a variable is declared, it starts to have a life.

b) When a variable is bound to a data type, it starts to have a life.


c)

When a variable is bound to memory storage, it starts to have a life.

d)

When a program runs, all variables start to have a life.

20. Which statement is true regarding variable?


a)

Static variables must be global variables

b)

Stack Dynamic variables must be local variables

c)

Heap Dynamic variables must be local variables

d)

None of above

21. If a variable is allocated in DATA segment, then it must be:


a)

a static variable

b)

a global variable

c)

existing in data segment throughout the program execution

d)

All of above

22. Base on the characteristics of variables, which variables are the most
memory efficiency?
University of Northern Virginia
6/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

a) Static variables.
b)

Stack dynamic variables.

c)

Heap dynamic variables.

d) None of above.

23. Base on the characteristics of variables, which variables are the most
addressing efficiency?
a) Static variables.
b)

Stack dynamic variables.

c)

Heap dynamic variables.

d) None of above.

24. Base on the characteristics of variables, which variables are both the most
memory and addressing efficiency?
a) Static variables.
b)

Stack dynamic variables.

c)

Heap dynamic variables.

d) None of above.

25. Which statement is true regarding Explicit heap-dynamic variables?


a)

It is often used for dynamic structures, such as linked lists and trees, that need to
grow and/or shrink during execution.

University of Northern Virginia


7/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

b)

It can only be built using pointers.

c)

Once allocated, it can not be de-allocated throughout the program execution.

d)

It always associated with a name which is the same as the pointer.

26. What is the purpose of Type Checking?


a)

To ensure that the operands of an operator are of compatible types.

b)

To ensure that the variable is large enough to hold the value assigned.

c)

To ensure that the operation performed is legal.

d)

To ensure that the memory allocation is compatible with the data type.

27. What is the purpose of using a Strong Typed language?


a)

To make sure every variable is legally defined.

b)

To make sure the program is highly reliable.

c)

To make sure the type checking is enforced during the program execution.

d)

To make sure the type error is always detected.

28. Which of the following is non-local variable?


a)

a variable declared in main program module.

b)

a variable declared in sub-program module.

c)

a variable is visible, but not declared in this module.

d)

a variable is not visible, and not declared in the module.

29. Which statement is true regarding to Static Scope variables?


a)

The scope of a variable can be determined prior to execution and during execution.

b)

All variables are non-local variables in Static Scope programming languages.

University of Northern Virginia


8/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

c)

All variables data type binding must be static in Static Scope programming
languages.

d)

None of above

The following questions are based on the referencing environment


diagram below in a static scoped language
Program example ;
Var a, b, c, d : integer ;
Procedure sub1 ;
Var d, e, f, g : integer ;
Procedure sub2 ;
Var a, c, d, g, x, y : integer ;
Begin
1
End ;
Begin
2
End ;
Procedure sub3 ;
Var x, y, z : integer ;
Procedure sub4 ;
Var x, g, y, c : integer ;
Begin
3
End ;
Begin
4
End ;
Begin

End ;

University of Northern Virginia


9/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

30. Which variable does not exist in the referencing environment for #1
a)

e of sub1

b) d of sub1
c)

x, y of sub2

d) a, b, c, d of example

31. What is the correct referencing environment for #2


a) d, e, f, g of sub1,

a, b, c, d of example

b)

a, c, d, g, x, y of sub2, d, e, f, g of sub1,

c)

d, e, f, g of sub1,

d) d, e, f, g of sub1,

a, b, c of example

a, b, c of example
b of example,

(a, c, d of example are hidden)

32. What is the correct referencing environment for #3


a) x, g, y, c of sub4, x, y, z of sub3,
b) x, g, y, c of sub4, z of sub3,
c)

x, g, y, c of sub4,

d) x, g, y, c of sub4,

a, b, c, d of example

a, b, d of example

d, e, f, g of sub1,

z of sub3,

a, d of sub2, z of sub3,

b, d of example

b, d of example

33. What is the correct referencing environment for #4


a) x, y, z of sub3,

a, b, c, d of example

University of Northern Virginia


10/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

b)

x, g, y, c of sub4, z of sub3,

b, d of example

c)

x, y, z of sub3, d, e, f, g of sub1,

d) x, y, z of sub3, d, e, f, g of sub1,

a, b, c of example
a, b, c, d of example

34. In referencing environment #4, the variable g is coming from?


a)

sub1

b) sub2
c)

sub3

d) None of above

35. In referencing environment #3, the variable d is coming from?


a)

sub1

b) sub2
c)

example

d) None of above

University of Northern Virginia


11/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

The following questions are based on the referencing environment diagram


below in a dynamic scoped language
Void sub1 ( ) {
int a, b, c, d ;
1

sub3
}
Void sub2 ( ) {
int b, c, d ;

sub1
}
Void sub3 ( ) {
int c, d ;

.
}
Void sub4 ( ) {
int x, y, z, d ;

sub2
}
Void main ( ) {
int x, a

sub4
}

36. What is the correct referencing environment for #3


a)

c, d of sub3,

a, b of sub1,

b of sub2, x, y, z of sub4

b)

c, d of sub3,

a, b of sub1,

x, y, z of sub4

c)

c, d of sub3,

a, b of sub1, b of sub2, x, y, z of sub4, x, a of main

d) None of above
University of Northern Virginia
12/13

SP2010
Midterm Exam
CSCI524 Principles of Programming Languages
Prof. E. Chen

37. What is the correct referencing environment for #4


a) x, y, z, d of sub4, b, c of sub2, a of main
b) x, y, z, d of sub4, b, c of sub1, a of main
c)

x, y, z, d of sub4, a of main

d) None of above

38. To reference x in sub2, the x is coming from?


a)

sub1

b)

sub2

c)

sub3

d) sub4

39. What is true to a variable initialization?


a)

If the variable is statically bound to storage, binding and initialization occur before
run time.

b)

If the storage binding is dynamic, initialization can be static.

c)

If the storage binding is statically bound, initialization must be static.

d)

If the variable initialization is dynamic, the storage binding must be dynamic.

University of Northern Virginia


13/13