Exams COPY Flashcards
(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
Statements:
- Variable declarations
- Expressions statments
- While loops
- Blocks: (possible empty) lists of statements enclosed in braces
Expression constructs
- Identifiers/variables
- Integer literals
- Post-increments of identifiers (++x)
- less or equal than comparision (E>=E’)
- Assignments of identifiers (x=E)
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) 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)
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.
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