Thursday 8/7/2008. 60 points.
http://www.cs.nyu.edu/courses/summer08/G22.3033-002/
(3+3+4 = 10 points) Consider the following BNF grammar rules:
| identifier | ::= | id_start | id_start id_rest
| |
| id_rest | ::= | id_inner | id_inner id_rest
| |
| id_start | ::= | _ | letter
| |
| id_inner | ::= | _ | letter | digit
| |
| letter | ::= | A | B | ... | Z | a | b | ... | z
| |
| digit | ::= | 0 | 1 | ... | 9
|
(2+2+2+2+2 = 10 points) Please keep your answers to the following questions short.
echo statement in PHP go?
document.write() call in JavaScript go?
(5+5 = 10 points)
"pe" . ("a", "rl").
("a", "rl")?
("a", "rl")?
("a", "rl") after type conversion, but before the converted value gets used?
"pe" . ("a", "rl")?
sqrt @a, assuming array @a has the value (1,9,4,9).
@a?
@a?
@a after type conversion, but before the converted value gets used?
sqrt @a?
(4+6 = 10 points) Consider the following Python code.
numbers = [1, 2]
extensions = ["html", "pdf"]
quizzes = [("quiz%d.%s" % (n, e)) for n in numbers for e in extensions]
quizzes at the end of the code snippet?
@numbers = (1, 2);
@extensions = ("html", "pdf");
Translate the third line of the Python code to Perl.
(3+3+4 = 10 points)
Consider the following PHP script editor_poll.php.
<html><body>
<?php if (empty($_GET['editor'])) { ?>
<form action="editor_poll.php">
<input type="radio" name="editor" value="emacs" /> Emacs
<input type="radio" name="editor" value="notepad" /> Notepad
<input type="radio" name="editor" value="vi" /> Vi
<input type="radio" name="editor" value="other" /> Other
<br />
<input type="submit" value="submit" />
</form>
<?php } else { ?>
You selected: <?php echo $_GET['editor'] ?>
<?php } ?>
</body></html>
(2+2+2+4 = 10 points) Consider the following JavaScript code.
function Vector(x, y) { this.x = x; this.y = y; }
Vector.prototype.length = function() {
q = this.x * this.x + this.y * this.y;
return Math.sqrt(q);
}
v = new Vector(3, 4);
document.write(v.length());
v?
v?
new in JavaScript does.