Skip to content

Commit d2e53de

Browse files
committed
more semantics
1 parent 1783bb9 commit d2e53de

1 file changed

Lines changed: 64 additions & 8 deletions

File tree

docs/doc-plan.md

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
# The MicroCode Language
22

3+
This document presents a detailed accounting of the syntax and
4+
semantics of the MicroCode language. Its intended audience are
5+
those who are familiar with programming languages and would like
6+
to understand the MicroCode language in depth. We also will
7+
use it as the basis for generating friendlier descriptions
8+
that use MicroCode's visual presentation, as well as to
9+
generate tests and aid in the translation of MakeCode programs
10+
to MicroCode programs,
11+
312
## Syntax
413

14+
MicroCode has a concrete syntax, as detailed below, for the
15+
purpose of creating programs without the need for visual
16+
MicroCode editor.
17+
518
In the following, a word in ALLCAPS refers to a non-terminal in
619
MicroCode's grammar. All other words are terminal symbols, with
720
the following exceptions: <float> is a floating point number;
8-
<pos> is an integer greater than zero; // designates a comment;
21+
<pos> is an integer greater than zero; // designates a comment
22+
(just for use in this markdown - MicroCode does not support comments);
923
the symbols \s, \*, (, ), [, ], and | are part of the grammar
1024
specification. Words are always separated by whitespace.
1125

12-
A program (PROG) consists of 5 pages, numbered 1-5, each with a possibly
13-
empty sequence of rules RULE:
26+
Note that non-terminals correspond to the tooltips used in MicroCode's
27+
visual editor (where the underscores are replaced by spaces), which
28+
accounts for their long form.
29+
30+
A program (PROG) consists of 5 pages, numbered 1-5, each with a (possibly
31+
empty) sequence of rules RULE:
1432

1533
PROG := page_1 RULE\* page_2 RULE\* page_3 RULE\* page_4 RULE\* page_5 RULE\*
1634

35+
So, the following program is the empty program
36+
37+
```
38+
page_1 page_2 page_3 page_4 page_5
39+
```
40+
1741
Each rule has an optional section WHEN and an optional section DO.
1842

1943
RULE := when [WHEN] do [DO]
@@ -161,13 +185,14 @@ used for timers, as detailed later.
161185

162186
Actions have effects through writing to resources, which are as follows:
163187

164-
- Screen
165-
- Speaker
166-
- Radio group
167-
- Radio
188+
- screen
189+
- speaker
190+
- radio group
191+
- radio channel
168192
- variable X
169193
- variable Y
170194
- variable Z
195+
- current page
171196

172197
If two rules have actions that target the same resource, they are said
173198
to be in _conflict_ if it is possible for them to execute at the same time.
@@ -176,4 +201,35 @@ to be in _conflict_ if it is possible for them to execute at the same time.
176201

177202
Upon reception of a signal, it is first necessary to find the
178203
rules that are enabled for execution by the signal. The first
179-
step is to find the rules that mention the named signal.
204+
step is to find the rules that mention the named signal. Then
205+
the optional conditions associated with those rules are evaluated
206+
in the current state (of variable and sensor values) to prune this
207+
set to get the enabled set E. Finally, if two rules in E are in conflict
208+
then the rule that comes later in sequence is removed from E.
209+
210+
Once we have the final set E of enabled rules, we halt
211+
execution of any currently active rules that conflict with
212+
a rule in E.
213+
214+
The set E is then partition into three sets, I, S, and T, corresponding
215+
to rules that execute instantly, those that switch page, and t
216+
hose that take time. Instant actions are
217+
218+
- assignments to variables
219+
- radio send
220+
- radio set group
221+
- switch page
222+
223+
The remaining actions are the ones that (may) take time.
224+
225+
The actions in I are executed first and run to completion.
226+
Then, if S is not empty then
227+
it must be a singleton, so a page switch will take place, in which
228+
case actions in T are ignored. Else, if S is empty then actions in
229+
T are started.
230+
231+
### Updating state
232+
233+
### Switching pages
234+
235+
### Timers

0 commit comments

Comments
 (0)