Pla
- Booleans
S d Pi
- Steps towards a Pico en
– Step 1: define syntax – Step 2: define a typechec – Step 3: define an evaluat
Step 3: define an evaluat
– Step 4: define a compile
T l f ti
- Traversal functions
- Methodology
Introduction
an
i nvironment
cker tor tor er
to ASF+SDF 1
The Toy Lan
- Pico has two types: natu
Variables have to be dec
- Variables have to be dec
- Statements: assign, if-th
- Expressions: natural, str
+ and ha e nat ral ope
- + and - have natural ope
- || has string operands a
|| g p
- Tests (if, while) should
Introduction
nguage Pico
ural number and string clared clared hen-else, while-do ring, +, - and || erands; the res lt is nat ral erands; the result is natural and the result is string be of type natural
to ASF+SDF 2
A Pico P
begin declare input : natural begin declare input : natural,
- utput : natural,
repnr: natural, rep: natural; rep: natural; input := 14;
- utput := 1;
while input 1 do while input - 1 do rep := output; repnr := input; hil 1 d while repnr - 1 do
- utput := output + rep;
repnr := repnr - 1 d
- d;
input := input - 1
- d
d
Introduction
end
Program
input value input value
- utput value
What does this program compute?
to ASF+SDF 3
A Pico P
begin declare input : natural begin declare input : natural,
- utput : natural,
repnr: natural, rep: natural; rep: natural; input := 14;
- utput := 1;
while input 1 do while input - 1 do rep := output; repnr := input; hil 1 d while repnr - 1 do
- utput := output + rep;
repnr := repnr - 1 d
- d;
input := input - 1
- d
d
Introduction
end
Program
input value input value
- utput value
14! 14 * 13 * * 1 What does this program compute? 14! = 14 * 13 * ... * 1 Why is it written in this l l (a) Pico has no input/output clumsy style? ( ) p p statements (b) Pico has no multiplication
- perator
to ASF+SDF 4
- perator