4 # dcc - Compile brainfuck code to a csv file specifying Dogeparty sends
5 # Copyright (C) 2014 Rob Myers rob@robmyers.org
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from optparse import OptionParser
23 import dogecode.translation
26 usage = "usage: %prog [options] source_file"
27 parser = OptionParser(usage=usage)
28 parser.add_option("-n", "--nocomment",
29 action="store_false", dest="strip", default=True,
30 help="don't skip the first [] as a comment")
31 parser.add_option("-d", "--dontrun",
32 action="store_false", dest="run", default=True,
33 help="don't run the code locally to check it executes")
34 parser.add_option("-o", "--outfile", dest="outfilename", default="-",
35 help="write compiled csv to OUTFILENAME", metavar="FILE")
36 opts, args = parser.parse_args()
38 parser.error("must supply source_file")
42 (opts, args) = getopts()
44 if opts.outfilename != "-":
46 outfile = open(opts.outfilename, 'w')
48 print("Couldn't open file {} .".format(opts.outfilename))
50 strip_comment = opts.strip
51 run_code_locally = opts.run
52 source_filename = args[0]
54 source_code = open(source_filename).read()
56 print("Couldn't read file {} .".format(source_filename))
58 #TODO: check account strings are valid
60 #TODO: run the code locally
62 dogecode.translation.source_to_tokens_csv(source_code,
66 if __name__ == "__main__":