Skip to content

Commit

Permalink
Merge pull request #14 from slowli/new-lecture
Browse files Browse the repository at this point in the history
лекция 12
  • Loading branch information
slowli committed Dec 12, 2014
2 parents f3233a8 + f59612f commit f86fc50
Show file tree
Hide file tree
Showing 13 changed files with 710 additions and 1 deletion.
5 changes: 5 additions & 0 deletions 12/code-bnf.yacc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
expression ::= element | list
element ::= number | variable
number ::= [+-]?['0'-'9']+
variable ::= ['A'-'Z''a'-z']'\w'*
list ::= '[' (expression',')*expression ']' | '[]'
18 changes: 18 additions & 0 deletions 12/code-reflection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function Button() { /*...*/ };

Button.prototype = {
onClick: function() { /*...*/ },
onDoubleClick: function() { /*...*/ },
/* ... */

/** #Заменяет все методы объекта, начинающиеся на 'on', на заглушки.# */
disable4ever: function() {
var noop = function() { alert('I am disabled!'); };
for (var member in this) {
if ((typeof(this[member]) == 'function')
&& (member.substring(0, 2) == 'on')) {
this[member] = noop;
}
}
}
};
12 changes: 12 additions & 0 deletions 12/code-semantics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* #Некорректный синтаксис# */
int x == 5;

/* #Некорректная семантика — неизвестный тип переменной# */
MissingType y;

/* #Некорректная семантика — переменная не определена# */
z = 3;

/* #Некорректная семантика — переменная не инициализирована# */
String str;
while (str.length() < 20) str += " ";
3 changes: 3 additions & 0 deletions 12/code-str-int.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printf("%s\n", "4" + 2);
char* nextStr = "next string";
// выведет (скорее всего) "next string"
1 change: 1 addition & 0 deletions 12/code-str-int.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String str = "4" + 2; // str == "42"
4 changes: 4 additions & 0 deletions 12/code-str-int.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
$number = 2;
$x = '4' + $number; // \$x == 6
$x = '4'.$number; // \$x == "42"
2 changes: 2 additions & 0 deletions 12/code-str-int.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x = "4" + 2;
# TypeError: cannot concatenate 'str' and 'int' objects
10 changes: 10 additions & 0 deletions 12/code-view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<table>
<thead><tr><th>Author</th><th>Title</th></tr></thead>
<tbody>
{% for book in books %}
<tr>
<td>{{ book.author }}</td><td>{{ book.title }}</td>
</tr>
{% endfor %}
</tbody>
</table>
15 changes: 15 additions & 0 deletions 12/code-view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Список книг, взятый из базы данных.
books = [
{ 'author': 'Ray Bradbury', 'title': '451F' },
{ 'author': 'Herman Melville', 'title': 'Moby-Dick' }
];

# HTML-код таблицы с данными о книгах.
print '<table>';
print '<thead><tr><th>Author</th><th>Title</th></tr></thead>';
print '<tbody>';
for book in books:
print '<tr><td>%s</td><td>%s</td></tr>'
% (book['author'], book['title']);
print '</tbody>';
print '</table>';
Loading

0 comments on commit f86fc50

Please sign in to comment.