course:programminglanguage
筆記
Chapter 1
Domains: scientific (floating point), business (report, decimal), AI (symbolic), system programming (efficiency), scripting, special-purpose
evaluation criteria: readability (most importnat), writability, reliability, cost, portability, generality, well-definess
architecture: Von Neumann
category
impertive (variables, assigment, statements, iteration)
functional (function, function, and functions)
logic (rule-based)
object-oriented (encapsulation, inheritance, dynamic type binding)
Compilation
Pure Interpretation
interpreter
Chapter 3
syntax: structure of a language
semantic: meanings
lexeme: smallest syntactic unit
recognizer 是給一篇文章,要辨識是不是這個語言 / generator 是給文法,要你生一篇文章
grammar: _finite_ nonempty set of rules
sentential form: derivation 裡的每一句的都算是 (including non-terminals and terminals)
precedence 高的會在樹下面
EBNF 中 {} 是 0 or more times
Attribute Grammar
每個 node X 都有一些 attributes A(X)
X → X_1 … X_n
synthesized attribute of X 是用 X_1 .. X_n 的 A() 組成的,也就是只跟 children 有關(因為他們的是你傳下去的)
inherited attribute of X_j 則是用 X, X_1 … X_{j-1} 組成的,也就是只跟 parent 還有 left sibling 有關
predicated function used to ensure syntax and static sementics rules are obeyed
intrinsic attribute 是 left nodes 的 synthesized attribute(照定義,會跑出樹)
operational semantics
axiomatic semantics: proving correctness
denotational semantics: based on recursion function
Q
Chapter 5
names
variable
(name, addr, value, type, lifetime, scope)
binding, an association
static (before runtime and cannot change) / dynamic (at runtime or changeable)
lifetime 只要還在 memory 中就算,即使你摸不到也可以(在 scope 外)
stack-dynamic 是說那種在 stack 上長的變數,有這種才有辦法做 recursion
implicit heap-dynamic 是說像是 Perl/JavaScript string (or array) 那種
explicit heap-dynamic 執行中產生出來的變數 例如 new
strong typing 是說所有 type errors 都可以抓出來
type compatibility
scope
static, often encourages global
dynamic, convenient but poor readability
referencing enviroment 是說你現在可以摸到的所有 variables
named constant 是說它的 value *只*有在它 bind 到 storage 的時候才會 bind,換句話說,之後就不能改
initialization 則是說 value 在 variable bind 到 storage 的時候,一起 bind 上去
Chapter 7
operators 的 precedence 跟 associativity
coercion 是指 implicit type conversion,會減少 compiler detect type error 的機會
short-circuit 會被 expression 的 side effect 影響,比如說 (a>b) || (b++/3),因為有 short-circuit,你不能確定 b 到底有沒有 +1
(C, C++, Jave) (a>b) ? a : b = 0,反正左邊是拿 l-value,所以沒差
Chapter 8
所有的 control statements 都可以只用 two-way selection 跟 pretest 的 loop 幹掉
dangling else
Dijkstra, 1975, Guarded Commands
course/programminglanguage.txt · Last modified: 2014/04/20 09:44 by 211.76.33.33