2.1 The While Programming Language Flashcards

1
Q

What is a programming language? What does every language need?

A

A precise language for giving instructions.

Needs: Syntax: form programs are allowed to take
Semantics: what a program means

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define the grammar of while:
S ::==
b ::==
a ::==

A

S ::== a | skip | S1;S2| if b then S1 else S2 | while b do S | (S)

b ::== true | false | a1 = a2 | a1 ≤ a2 | ¬b | b1 ∧ b2 | (b)

a ::== v | n | a1 + a2 | a1 - a2 | a1 x a2 | (a)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how can we extend the while language?

A

if b then s = if b then s else skip
a1 < a2 = ¬ ( a2 ≤ a1 )
a1 > a2 = ¬ ( a1 ≤ a2 )
a1 != a2 = ¬ (a1 = a2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what does this mean:

A

We execute program S in state σ to give a new program S’ and state σ’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give state modification notation

A

σ[x↦2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

are these states:
[x↦y]
[x+ y ↦2]

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly