プログラミング言語 / Programming Languages
田浦健次朗 / Kenjiro Taura

(the page is encoded in UTF-8)

お知らせ / What's New

新しいものが上です.

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.

スライド・資料 / Slides and other materials

2021年度までのスライド

参考書 / References

リンク

成績の付け方

Grading

単位がつく条件は以下の,

条件1 and 条件2 and (条件3a or 条件3b)

Conditions for getting the credit are

Condition #1 and Condition #2 and (Condition #3a or Condition #3b)
below

発表用論文

授業で説明した内容を踏まえて, 以下の論文の内容をスライドなども使いながら紹介,議論する.

発表予定

過去の「お知らせ」

2023

2022

2021

Answer to a question on June 28

I got the following question in today's lecture.
Q: What's the order of evaluation for CFG of ocamlyacc?
Consider the following example of CFG:
   "I see (a man with a mirror)"
or "I see (a man) with a mirror"
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.
  1. np  / verb / np
    I   / see  / a man with a mirror
    
  2. np  / verb / np    / advp 
    I   / see  / a man / with a mirror
    
I define a simple English-like grammar as follows for the sake of a concrete discussion. For clarity, the following is not really the ocaml-conforming description, but you can easily make it a real grammar that ocamlyacc/ocamllex can accept.
----------------------------------
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" np
can be parsed in two ways
  1.               np
    np "see" [np "with" np]   (* using sentence := np "see" np *)
    
  2.     
                  advp
    np "see" np ["with" np]   (* using sentence := np "see" np advp *)
    
You are asking in which way it is parsed.

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

  • if I write the grammar in the above order (sentence; advp; np; adjp), then it is parsed as (2)
  • if I put the grammar in the opposite order (adjp; np; advp; sentence), then it is parsed as (1)

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 stmt
can be parse either
  1. if expr (if expr stmt else stmt) or
  2. if expr (if expr stmt) else stmt

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.

Jupyter Notebook 修正 / Errata of Jupyter Notebooks

  • Jupyter notebook に対して, 後から判明した間違いをここにまとめて訂正します. 指摘してくれた皆さんありがとうございます. これからも疑問があればお知らせください.
  • Errors in Jupyter notebooks found after released are shown here. Thanks to those of you who point them out. When you find anything that you think might be an error, please let me know.
番号 / 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 松岡 暉心

2020

  • 2020/7/19 最終課題のファイルが一つ足りていませんでした(make -f test.mk 実行時の cmp_gcc_occ.py). 先程追加いたしました. すいません.
  • 2020/7/19 A file (cmp_gcc_occ.py necessary when you execute "make -f test.mk") was missing and was just added to your directory. Sorry.
  • 2020/7/13 starts @ 10:25 Rustと所有権〜さよならセグフォ,はじめましてボローエラー!〜 (Google Drive (g.ecc.u-tokyo.ac.jp必要); PDF)
  • 2020/7/13 最終課題の仕様; 提出はITC-LMS (オプション0, 1, 2のどれか1を提出); 締切 8/8 (土) 23:59
  • 2020/7/13 The final report spec; Submit via ITC-LMS (submit one of option #0, #1, or #2); Due Aug 8th (Sat) 23:59
  • 2020/7/11 7/13 10:25〜は近藤佑亮君, 吉田光樹君による以下の発表があります. 田浦の授業には飽きたという人も来て下さい.
    Rustと所有権〜さよならセグフォ,はじめましてボローエラー!〜
  • 2020/7/11 On July 13th 10:25- 近藤佑亮君 and 吉田光樹君 will talk about
    Rustと所有権〜さよならセグフォ,はじめましてボローエラー!〜
    Everyone including those who are bored with my lecture are welcome to join.
  • 2020/7/6 starts @ 10:25;
    1. talk: A crash (crude) course on machine (assembly) language
    2. (optional) exercise: compilation by hand (ex08_asm.c.ipynb)
    3. if time remains ...
    4. talk: A crash (crude) course on implementing a compiler
    5. talk: incremental GC
    6. I will deliver follow-up videos on these subjects if the time expires
    7. (optional) exercise: "implementation of a compiler"; materials come after the lecture
    8. exercise: on Lexing and parsing (ex07_lex_parse.c.ipynb) will be due Aug 1st (to be on ICT-LMS after today's lecture)
  • 2020/6/29 starts @ 10:25;
    1. talk: Lexing and parsing
    2. exercise: Lexing and parsing (ex07_lex_parse.c.ipynb)
    3. talk: incremental GC
  • 2020/6/22 starts @ 10:25;
    1. Join the class via Tanma! and send me a real-time feedback!
    2. ガベージコレクション / Garbage Collection
    3. Garbage collection exercise (ex05_gc.c.ipynb and ex05_gc_visualize.py.ipynb)
    4. Terminal and SSH for the next week (ex00_term_and_ssh.c.ipynb)
    5. ガベージコレクション (II) / Garbage Collection (II)
  • 2020/6/15 starts @ 10:25;
    1. ガベージコレクション / Garbage Collection
    2. Garbage collection exercise (ex05_gc.c.ipynb and ex05_gc_visualize.py.ipynb)
    3. highlight important points of OCaml type system if time permits
  • 2020/6/8 starts @ 10:25;
    1. talk (static type systems for object-oriented languages)
    2. break (work ex04_ocaml_oo.ml.ipynb);
    3. talk (OCaml type system) or finish early
  • 2020/5/25 starts @ 10:25;
    1. talk (static type systems for object-oriented languages)
    2. break (work ex04_ocaml_oo.ml.ipynb);
    3. talk (OCaml type system)
  • 2020/5/18 starts @ 10:25;
    1. talk (wrap up) Python
    2. break (work ex03_python_oo.py.ipynb or ex04_ocaml_oo.ml.ipynb);
    3. briefly talk about safety and types
    4. break (or work ex04_ocaml_oo.ml.ipynb);
    5. talk (static type systems for object-oriented languages)
  • 2020/5/11 starts @ 10:25; talk (wrap up OCaml); work (ex03_python_oo.py.ipynb); talk (object-oriented programming)
  • 2020/4/27 先週までとURLが違います. ITC-LMS を見てください(土曜日にLine/Emailのお知らせを飛ばしたつもりですが飛んでいないかも?). もしITC-LMSが重かったら... いまだけ
  • 2020/4/27 Class URL has changed. Get it at ITC-LMS (I sent a LINE/Email notification but did it reach you?). In case ITC-LMS does not respond, only now
  • 2020/4/20 Wake and be ready to work with your laptop not smartphone!
  • 2020/4/20 ITC-LMSで最初のダミー課題のフィードバックを受取り, 作業用URLを入手してください.
  • 2020/4/20 Go ITC-LMS, read the feedback for your first empty assignment and get your workplace URL.
  • 2020/4/13 Zoomにg.ecc.u-tokyo.ac.jpサインインが必要な 会議への入り方
  • 2020/4/13 How to enter Zoom meetings that require sign in
  • 2020/4/2 日本語授業が受けづらい(多分外国人)学生が一人でもいたら英語で喋ります. 連絡をください.
  • 2020/4/2 If there is one (presumably international) student who doesn't speak Japanese, I will do the lecture in English. Please let me know if that is the case for you.
  • 2020/4/2 オンライン授業に備えて / Get ready for online classes
    • オンライン授業のURLは UTAS のシラバス -> 「詳細情報」 -> 「オンライン授業URL」からたどれます(全授業共通ルール)が,
    • The URL for online classes can be obtained from UTAS syllabus -> "details" 「詳細情報」 -> "online class URL" 「オンライン授業URL」 (ground rule)
    • 初回授業に先立ち ITC-LMSでお知らせ通知機能をONにしておいてください(手順)
    • Prior to the first lecture, please set "Email/Line Notification" of ITC-LMS (how).
    • 初回授業に先立ち ITC-LMS 上で 受講登録 して, 情報が見れる+お知らせが受け取れる ようにしておいてください
    • Prior to the first lecture, register yourself (受講登録) in ITC-LMS, so that you can browse course information and receive notifications.
    • オンライン講義URLは ITC-LMSで, 本講義の「お知らせ」に書く予定ですので, UTASが重くて開かなければ, 直接ITC-LMSに行ってください (か, Email, LINE通知を見てください).
    • URL(s) of this lecture will be written in and sent through its "notifications" 「お知らせ」 in ITC-LMS, so if you experience UTAS becoming unresponsive, just go straight to ITC-LMS (or just check your Email or LINE).
    • 第一週4/6に始める(つながる)予定ですが, 中身をいきなり喋りだすことはない予定です. 初回は主に 「オンライン授業の受け方」 について話しなるべく多く質問を受け付けます.
    • I am going to start at the first week (Apr. 6) but I won't get into the technical content right away. I will mostly talk about How to attend online classes and take as many questions as possible.
    • 講義に出たいのにギガ不足, ソフトのトラブルその他で 出れないという人がいたら田浦まで 連絡ください. tau@eidos.ic.i.u-tokyo.ac.jp
    • If you want to participate but have difficulties due to the data capacity limit of your connection ("Giga-limit"), let me know tau@eidos.ic.i.u-tokyo.ac.jp
  • 2020/4/2 2020年版HP開設
  • 2020/4/2 HP opened.

2019

  • 2019/7/17 予想に反して早く 最終課題の仕様 公開
  • 2019/7/17 コンパイラ演習(課題としてはオプション)は notebooks/compiler_skeletonにあります
  • 2019/7/17 最終課題のオプションに, 「コンパイラ(コード生成器)を作る」 をあげます. 詳細は授業後約24時間以内に書きます
  • 2019/7/17 その他この他, 最終課題の詳細を授業後約24時間以内に書き, ITC-LMS にてレポートを出題します
  • 2019/6/23 字句解析・構文解析 (2019版)の演習
  • 2019/6/23 これまでのアナウンスの日付が全て2018になっていたことに 気づいて修正 orz
  • 2019/5/28 ex04_ocaml_oo.ipynbの締め切り 6/15 (土) 23:59
  • 2019/5/18 口頭でもアナウンスしたとおり, 5/20 (月)は休講です 掲示が遅くなり申し訳ありません(UTASでも連絡しています).
  • 2019/4/22 ex03_python_oo.ipynbの締め切り 5/11 (土) 23:59
  • 2019/4/22 ex02_ocaml_practice.ipynbの締め切り 4/27 (土) 23:59
  • 2019/4/22 ex01_ocaml_intro.ipynb の 解答例. わからなかった問題がある人は参考にしてください
  • 2019/4/15 ex01_ocaml_intro.ipynb の締め切り 4/20 (土) 23:59 4/15夕方までにLMSの課題として提出方法を指示します (コードの提出 + 形式的な提出作業のみ. レポートは不要).
  • 2019/4/15 次の自習課題 ex02_ocaml_practice.ipynb を公開.
  • 2019/4/8 初回の授業前もしくは授業中に, Jupyter演習環境のアカウント作成要求 をしてください. Request your account on the Jupyter hands-on exercise environment before or during the first lecture.
  • 2019/4/8 できたらこのシートで Jupyter環境のアクセス情報を取得して下さい (4/8 13:00更新. シートへのアクセス許可を落としたので, 見たい場合は誰かがわかるように, リクエストして下さい. Googleアカウントでアクセスをrequestするか, 田浦あてにメールでも良いです (いずれにせよ誰かがわかるようにしてください. 自分の情報が確認できたらまた田浦あてに連絡を下さい)). After you are done, check this sheet to get your account info on the Jupyter environment (4/8 13:00 UPDATE. Anyone's access permission is now off. If you want to see it, request access revealing who you are. You can request access through your Google account or simply send me an Email (In any case, tell me who is requesting. Also let me know when you obtain the necessary information).)
  • 2019/4/8 今後のために ITC-LMS で メールのお知らせを受け取る設定をしておいて下さい (任意で, LINEでも受け取れます). 課題提出や授業に関するお知らせなどは ITC-LMS を用いて行います.
  • 2019/4/4 2019年版HP開設

2018

  • 2018/7/2 Updated the spec on the final report, including which exercises are mandatory.
  • 2018/7/2 I will announce the exact requirement to get a credit shortly. For now, I'll just announce that the exercises on conservative GC is not a part of the requirement. Details will come shortly.
  • 2018/7/2 最終回(7/9)は有志による発表です. The last lecture is presentations by volunteers.
    • 王 力捷: Block-free concurrent GC: stack scanning and copying citation, paper, slides
    • 宮里 俊太郎: Rust流のメモリ管理, ライフタイムやリージョン. Region-Based Memory Management in Cyclone. citation, paper, slides
    • 浅井明里: A proposal for making Eiffel type-safe citation, paper pdf, slides
  • 2018/6/11 The class on June 18 will be canceled. m(_ _)m すみませんが, 6/18 (月) の講義を休講とします. m(_ _)m
  • 2018/5/31 The class on June 4 will be canceled. Sorry. すみませんが, 6/4 (月) の講義を休講とします.
  • 2018/4/8 2018年版HP開設