L3 - WHILE Language Flashcards

1
Q

Why do we prefer a high level language in order to write effective procedures?

A

Turing machines are tedious in terms of establishing computability and complexity. Thus, a higher level language is preferred.

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

Why is the WHILE language a good choice for establishing computability and complexity?

A

The language is high level and has a good mix of expressive power and simplicity.

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

How many data types does WHILE have? What is this data type?

A

WHILE can be considered untyped. The type system contains only Binary Trees. These trees are used to encode all other types needed.

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

What other Programming Languages did WHILE take inspiration from ? What were some reasons for this?

A

JSON, XML, S-Expressions

These are document notation languages. They are:
- expressive
- human readable
- efficiently read by machines
- Are nested lists, which can be encoded as Binary Trees.

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

In what form is WHILE data represented?

A

Binary Trees.

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

What letter do we use to denote a set of Binary Trees?

A

D

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

What are the only 2 states that the while binary tree can be? How are these denoted?

A

Empty : Nil
Constructed : <l,r>

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

Think of a simple binary tree where all leaf atoms are nil. Represent this tree in linear form…

A

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

In WHILE syntax, how do we encode Booleans?

A

False = nil
True = <nil.nil></nil.nil>

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

In WHILE syntax, how do we encode Natural Numbers?

A

3 = <nil . <nil . <nil.nil> > ></nil.nil>

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

In WHILE syntax, how do we encode Lists?

Encode : [a1,a2,a3]
Encode : [[],[]]
Encode : [nil,nil,[],[]]

A

[] = nil
[a1] = <a1.nil>
[a1,a2] = < a1 . <a2.nil> >
[a1,a2,a3] = < a1 . < a2 < a3.nil > > ></a2.nil></a1.nil>

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

In WHILE syntax, how do we encode Pairs?

A

(p,q) = [p,q] = < p . < q . nil > >

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

What are the 2 data that Expressions can represent in WHILE?

A
  • An empty tree
  • A constructed tree
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Destructor in WHILE? Give the main 2.

A
  • Disassemble a Binary Tree into left and right subtrees.
  • Head : Disassembles to left subtree.
  • Tail : Disassembles to right subtree.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the 4 types of Commands in WHILE?

A

Assignment
Conditional
While Loop
Statement Block

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

Name and define the components of a WHILE program…

A

Name
Input Read
Statement Block
Output Write

17
Q

How many variables can a WHILE program read and write?

A

1