新しいものが上です.
Newer entries come above.
最初の青字部分がアナウンス日 です.
Blue letters in the beginning of a line indicates the day the announcement was made on.
授業をしながら更新していくので, しょっちゅうreloadしてください.
Please reload the page frequently as it will be updated during the course.
(WRONG) as the function computes sum_array_rec(n - 1) + n - 1, the value of n (or n - 1) must be saved somewhere during sum_array_rec(n - 1); where is it saved?replace it with:
(CORRECTED) as the function computes sum_array_rec(a, p, r) + sum_array_rec(a, r, q), arguments passed to the second call (whichever is done second) must be somehow preserved during the first call, and the return value of the first call must be somehow preserved during the second call. for example, if the compiler decides to perform sum_array_rec(a, p, r) first, a, r, and q must be preserved during the first call and the return value of sum_array_rec(a, p, r) must be preserved during the second call. where are they saved?
(誤) as the function computes sum_array_rec(n - 1) + n - 1, the value of n (or n - 1) must be saved somewhere during sum_array_rec(n - 1); where is it saved?以下に差し替え
(正) as the function computes sum_array_rec(a, p, r) + sum_array_rec(a, r, q), arguments passed to the second call (whichever is done second) must be somehow preserved during the first call, and the return value of the first call must be somehow preserved during the second call. for example, if the compiler decides to perform sum_array_rec(a, p, r) first, a, r, and q must be preserved during the first call and the return value of sum_array_rec(a, p, r) must be preserved during the second call. where are they saved?
<plus> <num>1</num> <mul> <num>2</num> <num>3</num> </mul> <div> <num>4</num> <num>5</num> </div> <minus> <num>6</num> <num>7</num> </minus> </plus>
$ ./eval_expr e.xml 6.8のような出力をするプログラムを作ることが目標
u21xxx@taulec:4-cogen$ make -f test.mk ./cmp_gcc_occ.py exe/f00 10 -5 5 > check/f00.check /bin/sh: 1: ./cmp_gcc_occ.py: Permission denied make: *** [test.mk:25: check/f00.check] Error 126 make: *** Deleting file 'check/f00.check'こちらのミスですいませんが以下のようにして回避して下さい.
chmod +x ./cmp_gcc_occ.py
u21xxx@taulec:4-cogen$ make -f test.mk ./cmp_gcc_occ.py exe/f00 10 -5 5 > check/f00.check /bin/sh: 1: ./cmp_gcc_occ.py: Permission denied make: *** [test.mk:25: check/f00.check] Error 126 make: *** Deleting file 'check/f00.check'Please fix this error by executing the following. My bad!
chmod +x ./cmp_gcc_occ.py
u21xxx@taulec:2-cc-parse$ make ocamlbuild cc.byte + ocamlyacc cc_parse.mly File "cc_parse.mly", line 36: syntax error | definition* EOF { $1 } ^ Command exited with code 1. Compilation unsuccessful after building 4 targets (1 cached) in 00:00:00. make: *** [Makefile:six: cc.byte] Error 10すみませんがこのエラーが出ている人は, 以下の手順で, pl12 を fetch し直して下さい. エラーがでていない人は何もしなくて構いません.
ssh u21xxx@taulec.zapto.org # u21xxx は自分のユーザ名に置き換える cd notebooks mv pl12 pl12.orgとして, 自分の~/notebooks/pl12を一旦別の名前に(pl12が存在しない状態に)すると, 再び pl12 がブラウザから fetch 可能な状態になりますので, fetch し直して下さい. すでに作業をしたファイルが有る場合はすいませんが, 作業済みのものを, 新しいpl12フォルダにコピーして反映させて下さい. 再fetch後は以下のような動作になるはずです.
u21xxx@taulec:2-cc-parse$ make ocamlbuild -use-menhir cc.byte ...一部の人にpl12のfetchが必要な理由:ですが, 一旦田浦が pl12 をfetch可能にしたあとで, (上記を含めた)複数の間違いを修正しています. (*)で言う, このエラーに遭遇する一部の人とは, 最初にpl12 をfetch可能にした後に (間違い修正前に)fetchをした人ということになります. 修正・追加内容は,
u21xxx@taulec:2-cc-parse$ make ocamlbuild cc.byte + ocamlyacc cc_parse.mly File "cc_parse.mly", line 36: syntax error | definition* EOF { $1 } ^ Command exited with code 1. Compilation unsuccessful after building 4 targets (1 cached) in 00:00:00. make: *** [Makefile:six: cc.byte] Error 10If you are one of them, please fetch pl12 again following the procedure below. Otherwise you don't have to do anything.
ssh u21xxx@taulec.zapto.org # u21xxx should be your user name cd notebooks mv pl12 pl12.orgThat is, rename your ~/notebooks/pl12 to something else (so pl12 does not exist) and it becomes fetchable again. Please go ahead and fetch it again. If you have done some work already, please merge your work by copying your files into the newly fetched pl12 folder. After refetching it, it should behave like this.
u21xxx@taulec:2-cc-parse$ make ocamlbuild -use-menhir cc.byte ...The reason why some of you need to fetch pl12 is that I have corrected several errors (including the above) after I once released it (made it fetchable). Some of you (*) who encouter this error are those who fetched it before I corrected it. Changes made are
GCが走るタイミングはどういった基準で決められることが多いのでしょうか?(ヒープメモリの確保がある程度のサイズまで行われた時に走るとか…?)大変良い質問で, だいたい「ヒープメモリの確保がある程度のサイズまで行われた時に走る」なのですが, 「ある程度のサイズ」をどう決めるかが問題です. 実際にプログラムが最低限必要とするメモリ(生きているオブジェクト)量の定数倍, とすることが多いです. ガベージコレクション / Garbage Collection のスライド60あたりで説明の予定です.
Q: What's the order of evaluation for CFG of ocamlyacc?This is indeed a good question about an issue that commonly arises when defininig a grammar using CFG. Let me start by rephrasing your question for the sake of clarity. I assume you are asking how the sentence "I see a man with a mirror" will be parsed (recognized), with a hypothetical English-like grammar, like the following.
Consider the following example of CFG:"I see (a man with a mirror)" or "I see (a man) with a mirror"
np / verb / np I / see / a man with a mirror
np / verb / np / advp I / see / a man / with a mirror
---------------------------------- definition of an English-like grammar ---------------------------------- sentence : np "see" np | np "see" np advp advp : | "with" np np : noun | np adjp adjp : | "with" np ---------------------------------- definition of tokens ---------------------------------- noun := "I" | "a man" | "a mirror"In this grammar, just as you pointed out, a token sequence
np "see" np "with" npcan be parsed in two ways
np np "see" [np "with" np] (* using sentence := np "see" np *)
advp np "see" np ["with" np] (* using sentence := np "see" np advp *)
The accurate answer is "it depends". It depends on how you wrote a grammar (your original question cannot be answered, without specifying how you write the grammar). It also depends on the tool you are using. The following may be specific to ocamlyacc.
With that said, if you write an ocamlyacc grammar in the order above, it seems that it is parsed as (2). It seems that the ocamlyacc uses the first rule that appears in the grammar, if you believe this article. "Well, this simplest answer is to just ignore it and let the default reduce/reduce resolution handle it -- reduce the rule that appears first in the grammar." In this case, "the first rule" involved in the ambiguity will be 'sentence := np "see" np advp' (the second rule being 'np := np adjp').
I wrote an ocamlyacc grammar faithfully implementing the above and confirmed that
However, I could not confirm the above statement "... the default reduce/reduce resolution handle it -- reduce the rule that appears first in the grammar" in an authoritative document. Even if you find a statement like this in an authoritative document, "the rule that appears first in the grammar" is itself a very vague expression. I don't know how to resolve grammar ambiguity with such an ambiguous rule :-)
The bottom line: you should not rely on the ambiguity resolution rule of the particular tool you are using; as a matter of fact, you ought not to define an ambiguous grammar (a grammar that can parse the same sequence of tokens in two or more different ways), at least when you define a syntax of a programming (artificial) language.
With that said, an ambiguity actually arises in programming languages. A famous example is an if statement that may omit the "else" clause. In such a language, a nested if statement like
if expr if expr stmt else stmtcan be parse either
Most programming languages determine such statements should be parsed as the first one (i.e., 'else' must be associated with the closest 'if'). If you want to make your grammar behave this way you must be a bit creative in doing so. See for example this page
NLP is totally different. It is inherently ambiguous and we live with ambiguity. Human is resolving ambiguity with a wealth of information including contexts, meaning of words, and common sense. To put it differently, an ordinary CFG is not a powerful enough tool for defining natural language grammars. NLP parsing is typically done with a statistical ambiguity resolution.
番号 / no | ファイル / File | 場所 / Location | 誤 / Error | 正 / Correct | 備考 / Remarks |
---|---|---|---|---|---|
1 | pl02_ocaml_intro.ml | 4-20. Problem 12 : 2分探索木の探索 / Searching a binary search tree | 2分探索木の探索を行う関数bs_tree_search を書け | 2分探索木の探索を行う関数bs_tree_find を書け | Thanks to 水橋 大瑶 |
1 | pl02_ocaml_intro.ml | 4-20. Problem 12 : 2分探索木の探索 / Searching a binary search tree | write a function bs_tree_search that searches a binary search tree for a value. | write a function bs_tree_find that searches a binary search tree for a value. | Thanks to 水橋 大瑶 |
2 | pl03_ocaml_practice.ml | 1-1. 配列 / Arrays | a.(2) = 200 (* 要素代入(更新) / assign to (update) an element *) | a.(2) <- 200 (* 要素代入(更新) / assign to (update) an element *) | Thanks to ダン チャン ジャ バオ |
3 | pl03_ocaml_practice.ml | 1-3. レコードと更新可能なフィールド / Records and mutable fields | type 型名 = record { フィールド名 : 型 ; フィールド名 : 型 ; ... ; フィールド名 : 型 } | type 型名 = { フィールド名 : 型 ; フィールド名 : 型 ; ... ; フィールド名 : 型 } | Thanks to 押川 令 |
3 | pl03_ocaml_practice.ml | 1-3. レコードと更新可能なフィールド / Records and mutable fields | type name = record { field-name : type ; field-name : type ; ... ; field-name : type } | type name = { field-name : type ; field-name : type ; ... ; field-name : type } | Thanks to 押川 令 |
3 | pl03_ocaml_practice.ml | 1-3. レコードと更新可能なフィールド / Records and mutable fields | type 型名 = record { フィールド名 : 型 ; フィールド名 : 型 ; ... ; フィールド名 : 型 } | type 型名 = { フィールド名 : 型 ; フィールド名 : 型 ; ... ; フィールド名 : 型 } | Thanks to 押川 令 |
3 | pl11_asm.ml | 4-6. 割り算 / division | (%rdx,%rax) = (%rdx:%rax / %rdi, %rdx:%rax % %rdi) ... (%rdx:%rax を %rdi で割った商が %rdx, あまりが %rax に入る) | (%rdx,%rax) = (%rdx:%rax % %rdi, %rdx:%rax / %rdi) ... (%rdx:%rax を %rdi で割った商が %rax, あまりが %rdx に入る) | Thanks to 松岡 暉心 |
3 | pl11_asm.ml | 4-6. 割り算 / division | (%rdx,%rax) = (%rdx:%rax / %rdi, %rdx:%rax % %rdi) ... (that is, it divides %rdx:%rax by %rdi and puts the quotient on %rdx and the remainder on %rax) | (%rdx,%rax) = (%rdx:%rax % %rdi, %rdx:%rax / %rdi) ... (that is, it divides %rdx:%rax by %rdi and puts the quotient on %rax and the remainder on %rdx) | Thanks to 松岡 暉心 |
Rustと所有権〜さよならセグフォ,はじめましてボローエラー!〜
Rustと所有権〜さよならセグフォ,はじめましてボローエラー!〜Everyone including those who are bored with my lecture are welcome to join.