Explain classes more, begin introducing neighbourhoods.
catseye
12 years ago
6 | 6 | |
7 | 7 | The language described herein is mostly compatible with the version |
8 | 8 | 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. | |
11 | 11 | |
12 | 12 | Encoding |
13 | 13 | -------- |
22 | 22 | An ALPACA description consists of a list of one or more _definitions_, |
23 | 23 | optionally followed by an _initial configuration_. |
24 | 24 | |
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.) | |
29 | 29 | |
30 | 30 | Example: a trivial ALPACA description with two states: |
31 | 31 | |
41 | 41 | |
42 | 42 | #### Representation Declarations #### |
43 | 43 | |
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 | |
47 | 47 | drawn from a set defined by this specification, or it may be |
48 | 48 | implementation-defined. The datum may consist essentially arbitrary data, |
49 | 49 | and may refer to a character, a colour, a graphic image, or anything else. |
93 | 93 | to Thing when true; |
94 | 94 | state Thing |
95 | 95 | to Space when true. |
96 | ||
97 | TODO default transition rule. | |
96 | 98 | |
97 | 99 | ##### State Referents ##### |
98 | 100 | |
180 | 182 | of a state referent, the second term is a class referent. An example will |
181 | 183 | be given under "Classes", below. |
182 | 184 | |
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. | |
187 | 191 | |
188 | 192 | ### Classes ### |
189 | 193 | |
190 | 194 | 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. | |
194 | 256 | |
195 | 257 | ### Initial Configuration ### |
196 | 258 | |
211 | 273 | |
212 | 274 | AlpacaProgram ::= Entries ("." | "begin" initial-configuration). |
213 | 275 | Entries ::= Entry {";" Entry}. |
214 | Entry ::= Class | State. | |
215 | Class ::= "class" ClassID {MembershipDecl} | |
276 | Entry ::= ClassDefinition | |
277 | | StateDefinition | |
278 | | NeighbourhdDef. | |
279 | ClassDefinition ::= "class" ClassID {MembershipDecl} | |
216 | 280 | [Rules]. |
217 | State ::= "state" StateID {ReprDecl} {MembershipDecl} | |
281 | StateDefinition ::= "state" StateID {ReprDecl} {MembershipDecl} | |
218 | 282 | [Rules]. |
283 | NeighbourhdDef ::= "neighbourhood" NeighbourhoodID | |
284 | Neighbourhood. | |
219 | 285 | |
220 | 286 | ClassID ::= identifier. |
221 | 287 | StateID ::= identifier. |
288 | NeighbourhoodID ::= identifier. | |
222 | 289 | ReprDecl ::= quoted-char |
223 | 290 | | identifier ":" quoted-string. |
224 | 291 | |
240 | 307 | | RelationalFunc. |
241 | 308 | RelationalFunc ::= StateReferent (["="] StateReferent | ClassReferent). |
242 | 309 | AdjacencyFunc ::= ("1" | "2" | "3" | "4" | "5" | "6" | "7" | "8") |
310 | [Neigbourhood | NeighbourhoodID] | |
243 | 311 | (StateReferent | ClassReferent). |
244 | 312 | BoolPrimitive ::= "true" | "false" | "guess". |
313 | ||
314 | Neighbourhood ::= "(" {arrow-chain} ")". | |
245 | 315 | |
246 | 316 | The following are token definitions, not productions. |
247 | 317 | |
298 | 368 | This is no longer supported. However, a future version might introduce a |
299 | 369 | more "readable" alternative state referent syntax. |
300 | 370 | |
371 | Previous versions of ALPACA always assumed a Moore neighbourhood when making | |
372 | an adjacency comparison. | |
373 | ||
301 | 374 | Previous versions of ALPACA did not support giving an initial configuration |
302 | 375 | for the cellular automaton. |