git @ Cat's Eye Technologies Beatnik / beaf9f7
beatnik.py's --tokenize now compiles Beatnik to Wottasquare. Chris Pressey 7 years ago
2 changed file(s) with 9 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
3939 to standard error as the program is run.
4040
4141 `beatnik.py` also takes a `--tokenize` flag, which prevents the program
42 from being run, and instead dumps a readable representation of the program
43 to standard output.
42 from being run, and instead dumps a representation of the program in
43 Wottasquare to standard output. (It is essentially a Beatnik-to-Wottasquare
44 compiler.)
4445
45 Thus, the following idiom can be used to find out what Scrabble score, and
46 thus what Beatnik instruction, a particular word has.
46 The following idiom can be used to find out what Scrabble score, and thus what
47 Beatnik instruction, a particular word has.
4748
4849 $ beatnik.py --tokenize --eval 'Twenty'
49 'Twenty' = 12 (DUP)
50
51 TODO: the dump should really be in Wottasquare format, making this a
52 Beatnik-to-Wottasquare compiler.
50 [12:DUP/Twenty]
5351
5452 wottasquare.py
5553 --------------
8989 words.append(word)
9090
9191 if tokenize:
92 # A better version of this would not try to assign an ACTION
93 # to constants (words that follow PUSH or SKIP instructions)
9294 for word in words:
9395 value = scrabble(word)
94 print "'%s' = %s (%s)" % (word, value, ACTION.get(value, '(none)'))
96 print "[%s:%s/%s]" % (value, ACTION.get(value, 'NOP'), word)
9597 sys.exit(0)
9698
9799 words.append('FOXY') # stop if you get to the end