Programming Language Semantics - Quick Summary - Fall 2010 Semantics = meaning (vs syntax = form) Two possible questions: 1. What does a program [or statement] mean (ie what computation does it do)? 2. Does a program perform a specific computation correctly? How to specify: Outdated methods: 1. It means what the compiler says it means (depends on compiler). 2. Describe meaning in natural language (hard to be precise. too big) Current methods: 1. OPERATIONAL Translate to some theoretical machine eg i := 3 + 4; Definition (theoretical machine is a register machine: load $1, 3 load $2, 4 add $3, $1, $2 store i, $3 Alternate definition (theoretical machine is a stack machine): push 3 push 4 add store i (Long and tedious, but good for compiler writer) 2. AXIOMATIC - Define rules that logically describe the effect of each statement and each way of combining statements 3. DENOTATIONAL - Define mathematical functions that specify effect of statements ----------------------------------------------------------------------------------- ----------------------------------------------------------------------------------- THE ADDITIONAL MATERIAL BELOW IS NOT ON THE FALL 2010 FINAL EXAM ----------------------------------------------------------------------------------- ----------------------------------------------------------------------------------- 2. AXIOMATIC - Define rules that logically describe the effect of each statement and each way of combining statements eg i := 3 + 4; rule: memory after statement = memory before statement with i now = value of (3 + 4) eg Statement 1 Statement 2 rule: Effect of both statements is the effect of first statement followed by effect of second statement (Good for proving program properties) 3. DENOTATIONAL Define mathematical functions that specify effect of statements eg i := 3 + 4; Meaning(i:=3+4, Memory1) -> Memory1[with i replaced by valueOf(3+4)] eg S1 S2 Meaning(S1; S2, Memory1) -> Meaning(S2, Meaning(S1, Memory1) ) (Good for analyzing language designs)