git @ Cat's Eye Technologies ALPACA / f250d33
Explain classes more, begin introducing neighbourhoods. catseye 12 years ago
1 changed file(s) with 92 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
66
77 The language described herein is mostly compatible with the version
88 of language which has existed until now (version 0.9x). However, it
9 extends it in some significant ways, and it may be backwards-incompatible
10 in certain way. An implementation of 1.0-PRE does not yet exist.
9 extends it in some significant ways, and is be backwards-incompatible
10 in certain minor ways. An implementation of 1.0-PRE does not yet exist.
1111
1212 Encoding
1313 --------
2222 An ALPACA description consists of a list of one or more _definitions_,
2323 optionally followed by an _initial configuration_.
2424
25 Each definition may specify either a _state_ or a _class_. The definitions
26 in the list are seperated with semicolons and the list ends with either a
27 period (if no initial configuration is given) or the token `begin` (which
28 introduces the initial configuration.)
25 Each definition may specify either a _state_, a _class_, or a _neighbourhood_.
26 The definitions in the list are seperated with semicolons and the list ends
27 with either a period (if no initial configuration is given) or the token
28 `begin` (which introduces the initial configuration.)
2929
3030 Example: a trivial ALPACA description with two states:
3131
4141
4242 #### Representation Declarations ####
4343
44 Each representation declaration may be a single ASCII character enclosed in
45 quotes, or it may be a datum tagged with a name. The tag declares the
46 purpose and/or the intended interpretation of the datum. The tag may be
44 Each representation declaration may be a single printable ASCII character
45 enclosed in quotes, or it may be a datum tagged with a name. The tag declares
46 the purpose and/or the intended interpretation of the datum. The tag may be
4747 drawn from a set defined by this specification, or it may be
4848 implementation-defined. The datum may consist essentially arbitrary data,
4949 and may refer to a character, a colour, a graphic image, or anything else.
9393 to Thing when true;
9494 state Thing
9595 to Space when true.
96
97 TODO default transition rule.
9698
9799 ##### State Referents #####
98100
180182 of a state referent, the second term is a class referent. An example will
181183 be given under "Classes", below.
182184
183 An adjacency comparison is an expression consisting of an integer from
184 1 to 8 followed by a state or class referent. It evaluates to true
185 only if the cell has at least that many (Moore?) neighbours of that
186 state or class. (TODO: extend to other neighbourhoods.)
185 An adjacency comparison is an expression consisting of an integer greater
186 than or equal to 1, followed by an optional neighbourhood specifier,
187 followed by a state or class referent. It evaluates to true only if the
188 cell has at least that many neighbours of that state or class, in that
189 neighbourhood. If no neighbourhood is given, a Moore neighbourhood is
190 assumed.
187191
188192 ### Classes ###
189193
190194 A class declaration defines the general behaviour of a number of states.
191 Each state can belong to many classes, and are listed in overload order.
192 Classes can have their own rules, and the `is` operator can be used to
193 check for any of the states of a class instead of a single state.
195 Classes can have their own rules, and these are shared by all states which
196 are members of the class.
197
198 Example: a cellular automaton with three states, two of which are members
199 of the same class.
200
201 state " " Space
202 to Space when true;
203 class Animal
204 to Space when > Space;
205 state "*" Dog is Animal
206 to Cat when ^ Cat;
207 state "#" Cat is Animal
208 to Dog when ^ Dog.
209
210 Each state can belong to zero or more classes. When it belongs to more
211 than one, class the transition rules for each class are applied in order
212 the classes are listed in the state definition.
213
214 (TODO: Do the rules in a state take precedence over rules inherited from the
215 class? May need to fix next example.)
216
217 Example: a cellular automaton with two states and two classes, where both
218 states are members of both classes, but they inherit in different orders.
219 In it, Ones always remain Ones, and Twos always remain Twos.
220
221 class AlphaType
222 to One when true;
223 class BetaType
224 to Two when true;
225 state "1" One is AlphaType is BetaType
226 to Two when true;
227 state "2" Two is BetaType is AlphaType
228 to One when true.
229
230 In a transition rule, a class-inclusion comparison may be used by
231 giving a state referent, the token `is`, and the name of a class.
232 Intuitively, this evaluates to true if the state so referred to is a
233 member of that class.
234
235 Example: (TODO describe)
236
237 state " " Space
238 to Space when true;
239 class Animal
240 to Space when > is Animal;
241 state "*" Dog is Animal
242 to Cat when not ^ is Animal;
243 state "#" Cat is Animal
244 to Dog when not ^ is Animal.
245
246 ### Neighbourhoods ###
247
248 Example:
249
250 neighbourhood Moore
251 (< > ^ v ^> ^< v> v<);
252 state " " Space
253 to Active when 1 Moore Active;
254 state "*" Active
255 to Space when 4 (^ v < >) Space.
194256
195257 ### Initial Configuration ###
196258
211273
212274 AlpacaProgram ::= Entries ("." | "begin" initial-configuration).
213275 Entries ::= Entry {";" Entry}.
214 Entry ::= Class | State.
215 Class ::= "class" ClassID {MembershipDecl}
276 Entry ::= ClassDefinition
277 | StateDefinition
278 | NeighbourhdDef.
279 ClassDefinition ::= "class" ClassID {MembershipDecl}
216280 [Rules].
217 State ::= "state" StateID {ReprDecl} {MembershipDecl}
281 StateDefinition ::= "state" StateID {ReprDecl} {MembershipDecl}
218282 [Rules].
283 NeighbourhdDef ::= "neighbourhood" NeighbourhoodID
284 Neighbourhood.
219285
220286 ClassID ::= identifier.
221287 StateID ::= identifier.
288 NeighbourhoodID ::= identifier.
222289 ReprDecl ::= quoted-char
223290 | identifier ":" quoted-string.
224291
240307 | RelationalFunc.
241308 RelationalFunc ::= StateReferent (["="] StateReferent | ClassReferent).
242309 AdjacencyFunc ::= ("1" | "2" | "3" | "4" | "5" | "6" | "7" | "8")
310 [Neigbourhood | NeighbourhoodID]
243311 (StateReferent | ClassReferent).
244312 BoolPrimitive ::= "true" | "false" | "guess".
313
314 Neighbourhood ::= "(" {arrow-chain} ")".
245315
246316 The following are token definitions, not productions.
247317
298368 This is no longer supported. However, a future version might introduce a
299369 more "readable" alternative state referent syntax.
300370
371 Previous versions of ALPACA always assumed a Moore neighbourhood when making
372 an adjacency comparison.
373
301374 Previous versions of ALPACA did not support giving an initial configuration
302375 for the cellular automaton.