Scripting Languages CSCI-GA.3033.003, Summer 2012 Final

Thursday 8/9/2012. 60 points.

final_1 Precedence and associativity (10 points)

Here is an excerpt of the Perl operator table:
** binary right Exponentiation
*, / binary leftMultiplication, division
+, - binary leftAddition, subtraction
1a.
(2 points) What is the associativity of the ** operator?
1b.
(6 points) Add parentheses to the following expression so that it still produces the same value, but does not rely on precedence or associativity for disambiguation.
10 - 2 ** 3 / 4
1c.
(2 points) What does the expression from question (1b) evaluate to?

final_2 Type systems (10 points)

Please keep your answers to the following questions brief.
2a.
(3 points) Briefly define what “dynamic typing” is.
2b.
(3 points) Briefly define what “weak typing” is.
2c.
(4 points) Briefly define what “duck typing” is.

final_3 Regular expressions (10 points)

Consider the following Perl regular expression:
([34]1?[5-7])+
3a.
(2 points) Give two examples of strings that match the regular expression.
3b.
(2 points) Give two examples of strings that do not match the regular expression.
3c.
(6 points) Rewrite this regular expression using only the “essential” features of formal regular expressions. In other words, replace each shortcut feature by the regular expression it is a shortcut for.

final_4 Prototypes in JavaScript (10 points)

Consider the following JavaScript code.
function Ant() {
  this.legs = 6;
}
Ant.prototype.color = "black";
Ant.prototype.toString = function(n) {
  return "{legs=" + this.legs + ", color=" + this.color + "}";
}
//--- program point (4a) ---
critter = new Ant();
critter.color = "brown";
//--- program point (4b) ---
document.write(critter.toString());
4a.
(4 points) Draw the object diagram at program point (4a).
4b.
(4 points) Draw the object diagram at program point (4b).
4c.
(2 points) What does the script print?

final_5 Web programming and security (10 points)

5a.
(4 points) Give a typical example for the damage that an SQL injection attack can do.
5b.
(4 points) What do you need to do in your script to protect against SQL injection attacks?
5c.
(2 points) Do you need to apply the changes for question (5b) in a client-side script or in a server-side script?

final_6 Call-backs via Ruby blocks (10 points)

Consider the following Ruby script:
#!/usr/bin/env ruby
def myIterator(x)
  x += 2
  yield x
  x += 4
  yield x
end
myIterator(3){|y|
  puts y
}
6a.
(4 points) What does the script print?
6b.
(6 points) Draw the corresponding interaction diagram.

http://cs.nyu.edu/courses/summer12/CSCI-GA.3033-003/final-a.html