Skip to content

Commit e9298f3

Browse files
committed
work on syntax
1 parent 6af2283 commit e9298f3

1 file changed

Lines changed: 87 additions & 67 deletions

File tree

docs/doc-plan.md

Lines changed: 87 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,101 @@
1-
MicroCode programs consist of 5 pages, numbered 1 - 5.
2-
Execution always starts on page 1. Before execution
3-
starts, all variables are initialized to 0 and
4-
the current value of all sensors is cached.
1+
# The MicroCode Language
52

6-
A page consists of a sequence of rules (R):
3+
## Syntax
74

8-
P := page-D R\*
5+
In the following, a word in ALLCAPS refers to a non-terminal in
6+
MicroCode's grammar. Words in lowercase are terminal symbols and
7+
may have dashes and other symbols in them. <float> is a floating
8+
point number; <pos> is an integer greater than zero. Comments follow //.
99

10-
Each rule has an option when section W and an optional do section D.
10+
A program (PROG) consists of 5 pages, number 1-5, each with a possibly empty sequence of
11+
rules RULE:
1112

12-
R := when [W] do [D]
13+
PROG := page-1 RULE\* page-2 RULE\* page-3 RULE\* page-4 RULE\* page-5 RULE\*
1314

14-
The when section specifies an event of interest
15-
and, optionally, a filter on that event.
16-
The do section specifies an action and, optionally,
17-
parameters to that action.
15+
Each rule has an option when section WHEN and an optional do section DO.
16+
17+
RULE := when [WHEN] do [DO]
18+
19+
The WHEN section specifies an event of interest and, optionally, a filter on that event.
20+
The DO section specifies an action and, optionally, parameters to that action.
1821
Some actions can be repeated.
1922

20-
W :=
21-
| page-start [TS]
22-
| timer [TS]
23-
| press [PK]
24-
| release [PK]
25-
| move [MK]
26-
| sound [loud | quiet | C]
27-
| temperature [UD | C]
28-
| light [UD | C]
29-
| magnet [UD | C]
30-
| radio-receive [C]
31-
| variable-X-set [C]
32-
| variable-Y-set [C]
33-
| variable-Z-set [C]
34-
35-
UD := up | down
36-
TS := (1/4-second | 1-second | 1-random-second | 5-seconds)\*
37-
PK := button-A | button-B | logo | pin-0 | pin-1 | pin-2
38-
MK := shake | tilt-left | tilt-right | ...
39-
40-
C := CO V
41-
42-
CO :=
43-
| equals
44-
| not-equals
45-
| less-then
46-
| less-then-or-equal
47-
| greater-than
48-
| greater-than-or-equal
49-
50-
V :=
51-
| A
52-
| A + V
53-
| A / V
54-
| A - V
55-
| A \* V
56-
| random PV
57-
58-
A :=
59-
| <float>
60-
| var-X | var-Y | var-Z
61-
| light-value | sound-value | temp-value | magnet-value
62-
| radio-value
63-
64-
PV :=
65-
| int>0
66-
| int>0 + PV
67-
| int>0 \* PV
68-
69-
D :=
23+
WHEN :=
24+
| page-start [TS] // fires (once) when control transitions to this page, with optional delay
25+
| timer [TS] // set a timer to fire after a delay, execute repeatedly after associated action completes
26+
| press [PK] // fire on press of specified button PK
27+
| release [PK] // fire on release of specified button PK
28+
| move [MK] // fire on specified accelerometer event MK
29+
| sound [loud | quiet | C] // fire on loud/quiet event or comparison C of current sound level (0-255)
30+
| temperature [UD | C] // fire on UD event or comparison C of current temperature (in Celcius)
31+
| light [UD | C] // fire on UD event or comparison C of current light level (0-255)
32+
| magnet [UD | C] // fire on UD event or comparison C of current magnetic level
33+
| radio-receive [C] // fire when number arrives via radio, subject to optional comparison C
34+
| variable-X-set [C] // fire after variable X has been assigned, subject to optional comparison C
35+
| variable-Y-set [C] // fire after variable Y has been assigned, subject to optional comparison C
36+
| variable-Z-set [C] // fire after variable Z has been assigned, subject to optional comparison C
37+
38+
UD := up | down
39+
TS := (1/4-second | 1-second | 1-random-second | 5-seconds)\* // sum the sequence of times
40+
PK := button-A | button-B | logo | pin-0 | pin-1 | pin-2
41+
MK := shake | tilt-left | tilt-right | ...
42+
43+
Sensors and variables may be compared to values using C; sensors may also have events
44+
45+
C := CO E
46+
47+
Comparison operators CO are as follows:
48+
49+
CO :=
50+
| equals
51+
| not-equals
52+
| less-then
53+
| less-then-or-equal
54+
| greater-than
55+
| greater-than-or-equal
56+
57+
An expression E is either atomic A, a binary expression, or a randomly chosen value:
58+
59+
E :=
60+
| A
61+
| A + E
62+
| A / E
63+
| A - E
64+
| A * E
65+
| random PE
66+
67+
An atomic value A is either a floating point number, one of the three variables,
68+
or the current value of one of the four sensors, or the last value received over radio:
69+
70+
A :=
71+
| <float>
72+
| var-X | var-Y | var-Z
73+
| light-value | sound-value | temp-value | magnet-value
74+
| radio-value
75+
76+
A positive (integer) expression PE is
77+
78+
PE :=
79+
| <pos>
80+
| <pos> + PE
81+
| <pos> * PE
82+
83+
DO :=
7084
| show-number [V]
71-
| show-image (image)_ [repeat [PV]]
72-
| play-sound (sound)_ [repeat [PV]]
73-
| play-music (notes)\* [repeat [PV]]
85+
| show-image (image)_ [repeat [PE]]
86+
| play-sound (sound)_ [repeat [PE]]
87+
| play-music (notes)\* [repeat [PE]]
7488
| radio-send [V]
75-
| radio-set-group [PV]
89+
| radio-set-group [PE]
7690
| set-variable-X [V]
7791
| set-variable-Y [V]
7892
| set-variable-Z [V]
7993
| switch-page [PG]
8094

81-
PG := | page-1 | page-2 | page-3 | page-4 | page-5
95+
PG := | page-1 | page-2 | page-3 | page-4 | page-5
96+
97+
## Semantics
98+
99+
Before execution starts, all variables are initialized to 0 and
100+
the current value of all micro:bit/jacdac sensors is cached.
101+
Execution begins by transitioning to page 1.

0 commit comments

Comments
 (0)