Exams COPY Flashcards

1
Q
A

(a) valid
(b) not valid (h is not a function, cannot apply it to 1)
(c) not valid (g + 1 is not a function)
(d) valid
(e) valid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Statements:

  • Variable declarations
  • Expressions statments
  • While loops
  • Blocks: (possible empty) lists of statements enclosed in braces
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Expression constructs

  • Identifiers/variables
  • Integer literals
  • Post-increments of identifiers (++x)
  • less or equal than comparision (E>=E’)
  • Assignments of identifiers (x=E)
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Expressions

  • Identifiers/variables
  • Integer literals
  • post-increments of identifiers (x++)
  • less-or-equal than comparisons(E<=E’)
  • Assignments of identifiers (x = E)

Write compilation schmes in pseudo code for each of the expression constructions above generating JVM (i. asmin assembler). It is not necessary to remember exactly the names of the instructions - only what arguments they take and how they work.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
A

(a) Not valid (f is unbound)
(b) valid
(c) valid
(d) not valid (f doe snot have a function type)
(e) not valid (self application x x is not typable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write syntax-directed typing rules for the expression below. In any case, the environemnt must be made explicit

  • Integer literals
  • identifiers
  • function calls, i.e., identifiers applied to a tuple of expressions
  • Addition (+) and multiplication (*)
  • less-than comparison of integer expressions (
  • assignments
  • parenthesized expressions

Function calls, multiplication and addition are left-associative, comparison is non-associative, assignment is right associative. Function calls binds strongest, then multiplication, then addition, then comparison, then assignment.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write syntax-directed type checking rules for the expressions below. The typing enviroment must be made explicit

  • Expressions
  • Subtraction -
  • Multiplication *
  • pre-increment of variables ++x
  • Function calls x(e,…,e) with zero or more arguments
  • Parenthesized expressions. (e).

Both arithmetic operations are left associative. Multiplication binds stronger than subtraction

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
A
17
Q

Write compilation schemes in pseudo code or in Haskeel for the statement and expressions below. The compiler should output symbolic JVM insturctions (i. Jasmin assembler). It is not necessary to remember exactly the names of the instructions - only what arguments they take and how they work

  • Statements
    • statements formed from expressions by adding a semicolon;
    • Single variable declarations, e.g., int x
    • While loops
  • Expression
    • Inteleger literals
    • identifiers
    • functions calls i.e., identifiers applied to a tuple of expressions
    • additions (+) and multiplication (*)
    • less-than comparision of integers expression (
    • assignments
    • parenthesized expressions

Function calls, multiplication and addition are left-associateive, comparison is non-associative, assignments is rightassociative. Function calls bind strongest, then multiplication, then addition, then comparison, then assignment

A
18
Q
A
19
Q
A
20
Q
A
21
Q
A
22
Q
A

(a) not valid (f is unbound)
(b) valid
(c) valid
(d) not valid (g does not have a function type)
(e) not valid (self application x x is not typable)

23
Q

Write compilation schemes in pseudo-code for each of the grammer constructions in. The compiler shoul output symbolic JVM instructions (i.e Jasmin assembler). It is not necessary to remember exactly the ames of the instructions - only what arguments they take and how they work.

  • Statements
    • Blocks: lists of statments (possible empty) in curly brackets { }
    • Variable initialization: A type followed by an identifier, the equals sign, an initializing expression, and a semicolon e.g. int x = 4;
    • return statements: an expression betwen keyword return, and a semicolon, e.g. return 1;
  • Types
    • Int
  • Expressions
    • Integer literals
    • Subraction -
    • Multiplication *
    • pre-increment of variables ++x
    • function calls x(e,…,e) with zero or more arguments
    • parenthesized expressions (e)

Both arithemetic operations are left associative. Mutliplication binds stronger than subtraction.

A
24
Q

Write syntax directed interpretation rules for the statements forms and lists below. The environment must be made explicit, as well as all possible side effects. You can assume an interpreter for expressions

  • Blocks: lists of statements (possible empty) in curly brackets {}
  • Variable initialization statement: a type followed by an indentifier, the equals sign, an initializing expression, and a semicolon, e.g. int x = 4
  • return statemetns: an expression between keyword return and a semicolon, e.g return 1;
A
25
Q

Expressions

  • Identifiers/variables
  • Integer literals
  • post-increments of identifiers (x++)
  • less-or-equal than comparisons(E<=E’)
  • Assignments of identifiers (x = E)

Write syntax directed interpretation rules for the expression forms above. The environment must be made explicit, as well as all possible side effects.

A
26
Q
  • Statements
    • statements formed from expressions by adding a semicolon;
    • Single variable declarations, e.g., int x
    • While loops
  • Expression
    • Inteleger literals
    • identifiers
    • functions calls i.e., identifiers applied to a tuple of expressions
    • additions (+) and multiplication (*)
    • less-than comparision of integers expression (
    • assignments
    • parenthesized expressions

Function calls, multiplication and addition are left-associateive, comparison is non-associative, assignments is rightassociative. Function calls bind strongest, then multiplication, then addition, then comparison, then assignment

A
27
Q
A
28
Q
A
29
Q
A
30
Q
A

(a) not valid (f does not have a function type)
(b) valid
(c) not valid (self application xx is not typable)
(d) not valid (f is unbound)
(e) valid

31
Q

Write a call-by-value interpreter for below lambda-calculus either with inference rules, or in pseudo-code or haskell

A
32
Q
A
33
Q
  • Statements
    • Blocks: lists of statments (possible empty) in curly brackets { }
    • Variable initialization: A type followed by an identifier, the equals sign, an initializing expression, and a semicolon e.g. int x = 4;
    • return statements: an expression betwen keyword return, and a semicolon, e.g. return 1;
  • Types
    • Int
  • Expressions
    • Integer literals
    • Subraction -
    • Multiplication *
    • pre-increment of variables ++x
    • function calls x(e,…,e) with zero or more arguments
    • parenthesized expressions (e)

Both arithemetic operations are left associative. Mutliplication binds stronger than subtraction.

A
34
Q

Expression constructs

  • Identifiers/variables
  • Integer literals
  • Pre-increments of identifiers (++x)
  • Greater or equal than comparision (E>=E’)
  • Assignments of identifiers (x=E)
A