Fix a bug, identify a token collision, fix an example, all pass.
--HG--
rename : eg/nbhd1.alp => eg/neighbourhood2.alp
catseye
12 years ago
313 | 313 |
|
314 | 314 |
| neighbourhood Moore
|
315 | 315 |
| (< > ^ v ^> ^< v> v<);
|
316 | |
| neighbourhood vonNeumann
|
|
316 |
| neighbourhood VonNeumann
|
317 | 317 |
| (^ v < >);
|
318 | 318 |
| state Space
|
319 | 319 |
| to Thing when 1 in Moore Thing;
|
|
445 | 445 |
by some other description, however, this spec does not define a standard
|
446 | 446 |
way in which that could happen.
|
447 | 447 |
|
|
448 |
`arrow-chain` and `identifier` tokens overlap; tokens beginning with a
|
|
449 |
series of `v`s (lower-case letter "vee"s) will be interpreted as an `arrow-chain`.
|
|
450 |
Thus, the text `vonNeumann` will be scanned as the arrow-chain `v` followed
|
|
451 |
by the identifier `onNeumann`. Until such time as this is addressed, avoid
|
|
452 |
giving states, classes, and neighbourhoods names which begin with a lowercase
|
|
453 |
`v`. (Convention says to start these identifiers with uppercase letters
|
|
454 |
anyhow.)
|
|
455 |
|
448 | 456 |
Differences between ALPACA 1.0 and Previous Versions
|
449 | 457 |
----------------------------------------------------
|
450 | 458 |
|
0 | |
neighbourhood Moore
|
1 | |
(< > ^ v ^> ^< v> v<);
|
2 | |
neighbourhood vonNeumann
|
3 | |
(^ v < >);
|
4 | |
state Space
|
5 | |
to Thing when 1 in Moore Thing;
|
6 | |
state Thing
|
7 | |
to Space when 3 in (^ v < >) Space.
|
|
0 |
neighbourhood Moore
|
|
1 |
(< > ^ v ^> ^< v> v<);
|
|
2 |
neighbourhood Foo
|
|
3 |
(^ v < >);
|
|
4 |
state Space
|
|
5 |
to Thing when 1 in Moore Thing;
|
|
6 |
state Thing
|
|
7 |
to Space when 3 Space.
|
6 | 6 |
else:
|
7 | 7 |
self.children = []
|
8 | 8 |
assert isinstance(self.children, list)
|
9 | |
|
10 | |
def add_child(self, item):
|
11 | |
self.children.append(item)
|
|
9 |
for child in self.children:
|
|
10 |
assert isinstance(child, AST), \
|
|
11 |
"child %r of %r is not an AST node" % (child, self)
|
12 | 12 |
|
13 | 13 |
def __repr__(self):
|
14 | 14 |
if self.value is None:
|
|
16 | 16 |
if not self.children:
|
17 | 17 |
return 'AST(%r,value=%r)' % (self.type, self.value)
|
18 | 18 |
return 'AST(%r,%r,value=%r)' % (self.type, self.children, self.value)
|
19 | |
|
20 | |
def check(self):
|
21 | |
for child in self.children:
|
22 | |
assert isinstance(child, AST), \
|
23 | |
"child %r of %r is not an AST node" % (child, self)
|
24 | |
child.check()
|
47 | 47 |
text = file.read()
|
48 | 48 |
file.close()
|
49 | 49 |
ast = Parser(text).alpaca()
|
50 | |
ast.check()
|
51 | 50 |
if options.parse_only:
|
52 | 51 |
sys.exit(0)
|
53 | 52 |
if options.show_ast:
|
193 | 193 |
nb = NBHD_MOORE
|
194 | 194 |
if self.scanner.consume('in'):
|
195 | 195 |
if self.scanner.on_type('identifier'):
|
196 | |
nb = self.scanner.consume('identifier')
|
|
196 |
nb = AST('NbhdRef',
|
|
197 |
value=self.scanner.consume_type('identifier'))
|
197 | 198 |
else:
|
198 | 199 |
nb = self.neighbourhood()
|
199 | 200 |
if self.scanner.consume('is'):
|