L3 - WHILE Language Flashcards
Why do we prefer a high level language in order to write effective procedures?
Turing machines are tedious in terms of establishing computability and complexity. Thus, a higher level language is preferred.
Why is the WHILE language a good choice for establishing computability and complexity?
The language is high level and has a good mix of expressive power and simplicity.
How many data types does WHILE have? What is this data type?
WHILE can be considered untyped. The type system contains only Binary Trees. These trees are used to encode all other types needed.
What other Programming Languages did WHILE take inspiration from ? What were some reasons for this?
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.
In what form is WHILE data represented?
Binary Trees.
What letter do we use to denote a set of Binary Trees?
D
What are the only 2 states that the while binary tree can be? How are these denoted?
Empty : Nil
Constructed : <l,r>
Think of a simple binary tree where all leaf atoms are nil. Represent this tree in linear form…
…
In WHILE syntax, how do we encode Booleans?
False = nil
True = <nil.nil></nil.nil>
In WHILE syntax, how do we encode Natural Numbers?
3 = <nil . <nil . <nil.nil> > ></nil.nil>
In WHILE syntax, how do we encode Lists?
Encode : [a1,a2,a3]
Encode : [[],[]]
Encode : [nil,nil,[],[]]
[] = nil
[a1] = <a1.nil>
[a1,a2] = < a1 . <a2.nil> >
[a1,a2,a3] = < a1 . < a2 < a3.nil > > ></a2.nil></a1.nil>
In WHILE syntax, how do we encode Pairs?
(p,q) = [p,q] = < p . < q . nil > >
What are the 2 data that Expressions can represent in WHILE?
- An empty tree
- A constructed tree
What is a Destructor in WHILE? Give the main 2.
- Disassemble a Binary Tree into left and right subtrees.
- Head : Disassembles to left subtree.
- Tail : Disassembles to right subtree.
What are the 4 types of Commands in WHILE?
Assignment
Conditional
While Loop
Statement Block