git @ Cat's Eye Technologies ALPACA / b2d8d1f
Fix a bug, identify a token collision, fix an example, all pass. --HG-- rename : eg/nbhd1.alp => eg/neighbourhood2.alp catseye 12 years ago
6 changed file(s) with 22 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
313313
314314 | neighbourhood Moore
315315 | (< > ^ v ^> ^< v> v<);
316 | neighbourhood vonNeumann
316 | neighbourhood VonNeumann
317317 | (^ v < >);
318318 | state Space
319319 | to Thing when 1 in Moore Thing;
445445 by some other description, however, this spec does not define a standard
446446 way in which that could happen.
447447
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
448456 Differences between ALPACA 1.0 and Previous Versions
449457 ----------------------------------------------------
450458
+0
-8
eg/nbhd1.alp less more
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.
66 else:
77 self.children = []
88 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)
1212
1313 def __repr__(self):
1414 if self.value is None:
1616 if not self.children:
1717 return 'AST(%r,value=%r)' % (self.type, self.value)
1818 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()
4747 text = file.read()
4848 file.close()
4949 ast = Parser(text).alpaca()
50 ast.check()
5150 if options.parse_only:
5251 sys.exit(0)
5352 if options.show_ast:
193193 nb = NBHD_MOORE
194194 if self.scanner.consume('in'):
195195 if self.scanner.on_type('identifier'):
196 nb = self.scanner.consume('identifier')
196 nb = AST('NbhdRef',
197 value=self.scanner.consume_type('identifier'))
197198 else:
198199 nb = self.neighbourhood()
199200 if self.scanner.consume('is'):