git @ Cat's Eye Technologies Vinegar / b2c2592
Support "a bit more concatenative" syntax. Chris Pressey 1 year, 10 months ago
4 changed file(s) with 28 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
313313 fac1 =& dup int[0] gt!;
314314 fac2 =| fac3 fac4;
315315 fac3 =& dup int[1] eq!;
316 fac4 =& dup int[1] sub fact mul;
317
318 There! Are you happy now?
316 fac4 =& pop dup int[1] sub fact mul;
317 main =& int[5] fact;
318 ==> OK([120])
319
320 There! <s>Are you happy now?</s> Don't that just beat all?
321 In light of this stellar feature it is expected that serious
322 programmers would treat the plain `=` form of definition as
323 a sort of "wimpmode" and shun it.
324
325
0 fact =& fac1 fac2;
1 fac1 =& dup int[0] gt!;
2 fac2 =| fac3 fac4;
3 fac3 =& dup int[1] eq!;
4 fac4 =& pop dup int[1] sub fact mul;
5 main =& int[5] fact;
22
33 #
44 # Program ::= {Definition}.
5 # Definition ::= name<def> "=" Expression ";".
5 # Definition ::= name<def> ("=" Expression | "=&" Term | "=|" Term) ";".
66 # Expression ::= Term {"|" Term}.
77 # Term ::= Atom {Atom}.
88 # Atom ::= "(" Expression ")" | name<use> [bracketedtext].
2525 def definition(self):
2626 name = self.scanner.token
2727 self.scanner.scan()
28 self.scanner.expect('=')
29 expr = self.expression()
28 if self.scanner.consume('='):
29 expr = self.expression()
30 elif self.scanner.consume('=&'):
31 expr = self.term()
32 elif self.scanner.consume('=|'):
33 expr = self.term(constructor=Else)
34 else:
35 raise ParseError('Expected `=`, `=&`, or `=|`')
3036 self.scanner.expect(';')
3137 self.definitions[name] = expr
3238
3743 t1 = Else(t1, t2)
3844 return t1
3945
40 def term(self):
46 def term(self, constructor=Then):
4147 a1 = self.atom()
4248 while self.scanner.on_type('word') or self.scanner.token == '(':
4349 a2 = self.atom()
44 a1 = Then(a1, a2)
50 a1 = constructor(a1, a2)
4551 return a1
4652
4753 def atom(self):
3434 self.token = None
3535 self.type = 'EOF'
3636 return
37 if self.scan_pattern(u'\\|', 'operator'):
37 if self.scan_pattern(r'\||\=\&|\=\||\=', 'operator'):
3838 return
3939 if self.scan_pattern(r'\;', 'punct'):
4040 return