Course Overview
Overall Compiler Structure

(授業の概要; コンパイラ全体の仕組み)

Language Theory and Compilers

(言語理論とコンパイラ)

1st lecture, April 7, 2017

http://www.sw.it.aoyama.ac.jp/2017/Compiler/lecture1.html

Martin J. Dürst

duerst@it.aoyama.ac.jp, Building O, Room 529

AGU

© 2006-17 Martin J. Dürst 青山学院大学

 

Today's Schedule

 

Self-Introduction

TA: Sōichirō Yashiki (矢舗 宗一郎、M1)

 

授業の位置付け

 

成績評価方法

(目安)

 

授業の目標

 

The Importance of Compilers

Blog by Steve Yegge

Executive Summary:

 

授業の進め方

 

Course Schedule

Schedule

参考書

(授業は言語理論とコンパイラ両方をカバーするが、参考書はそれぞれ片方に集中)

 

Course Contents


Theory Compilers Other applications
Front end language theory, automata lexical analysis, parsing regular expressions, text/data formats
Back end
optimization, code generation

 

Example of Difference between Input and Output

(Computer Practice I, problems 04A1 and 04C1)

Character itself
(internal representation)
Escaping in HTML/XML
(external representation)
' '
" "
< &lt;
> &gt;
& &amp;

→: output
←: input
Which direction is more difficult?

 

Difficulties for Input

 

The Function of a Compiler

Bridge between software and hardware

 

Example Compiler Input/Output

Input fragment:

sum += price * 25;

Output (assembly language):

LOAD   R1, price  ; load from price into R1 (register 1)
CONST R2, 25 ; set constant 25 into R2 (register 2)
MUL R1, R1, R2 ; set the multiple of R1 and R2 into R1
LOAD R2, sum ; load from sum into R2
ADD R2, R1, R2 ; set the sum of R1 and R2 into R2
STORE sum, R2 ; store the contents of R2 into sum

 

Logical Structure of a Compiler

  1. [preprocessor]
  2. Lexical analysis
  3. Parsing (syntax analysis)
  4. Semantic analysis
  5. Optimization (or 5)
  6. Code generation (or 4)
  7. [assembler]
  8. [linker, loader]

 

Compiler Types and Related Software

 

Example of Lexical Analysis

Fragment of input program (sequence of characters):

s u m   + =   p r i c e   *   2 5 ; \n

Output (sequence of tokens):

id("sum"), plusequal, id("price"), asterisk, int(25), semicolon

 

Overview of Lexical Analysis

 

Example of Parsing

Input (sequence of tokens):

id("sum"), plusequal, id("price"), asterisk, int(25), semicolon

Output (syntax tree):

 

 

 

 

Details of Syntax Trees

More Examples

price = pretax / 100 * (108 - discount);

if (a > 5)
    b = 15;

 

Example of an Automaton

Very simple automatic vending machine:

State transition diagram:

 
 
 

 

Language and Grammar

 

Grammar of Imperative Sentences

ImperativeSentence → Verb Noun
Verb → eat
Verb → read
Verb → play
Noun → bread
Noun → music
Noun → books

 

Homework / 宿題

Deadline: April 13, 2017 (Thursday), 19:00

Where to submit: Box in front of room O-529 (building O, 5th floor)

Format: A4 single page (using both sides is okay; NO cover page), easily readable handwriting (NO printouts), name (kanji and kana) and student number at the top right

Problem: For the one-line C program fragment below, and based on the examples given in this lecture, write down:

  1. the result of lexical analysis
  2. the result of parsing
  3. the output of the compiler (in assumbly language; comments are not needed; use SUB for substraction, and DIV for division)
grade = english + math/2 - absent*5;

 

Glossary

lexical analysis
字句解析
parsing, syntax analysis
構文解析
automaton
オートマトン
formal language
形式言語
grammar
文法
executive summary
役員 (時間がない人) のための要約
front end
フロントエンド
back end
バックエンド
optimization
最適化
code generation
コード生成
regular expression
正規表現
text format
文書形式
data format
データ形式
internal representation
内部表現
external representation
外部表現
(e.g. face) recognition
(顔) 認識
high-level program language
高級プログラム言語
source (file/program)
ソース (ファイル・プログラム)、原始プログラム
object code
目的プログラム
machine code
実行プログラム
assembly language
アセンブリ言語
register
レジスタ
preprocessor
プリプロセッサ
semantic analysis
意味解析
assembler
アセンブラ (アセンブリ言語を処理するソフト)
linker
リンカ
loader
ローダ
one pass compiler
ワンパス・コンパイラ
x-pass compiler
x-パス・コンパイラ
cross-compiler
クロスコンパイラ
dynamic/just-in-time (JIT) compiler
動的コンパイラ
preprocessor
プリプロセッサ
interpreter
インタプリタ、通訳系
token
トークン、記号、符
natural language
自然言語
attribute
属性
identifier (発音: アイデンティファイア)
識別子
syntax tree
構文木
operator
演算子
operand
被演算子
expression
subexpression
部分式
statement (of a program)
separators
区切り記号
automatic vending machine
自動販売機
state transition diagram
状態遷移図
structure
構造
syntax
構文
semantics
意味 (論)
imperative sentence
命令文
verb
動詞
noun
名詞