## R
def p_remark1(t):
'statement : COMMENT STRING'
- t[0] = ('remark', t[2])
+ t[0] = ('remark', t[2][1:-1])
def p_remark2(t):
'statement : COMMENT'
if __name__ == '__main__':
import os, getopt
mad_debug = 0
- (options, arguments) = getopt.getopt(sys.argv[1:], "d:")
+ binary = True
+ target = None
+ (options, arguments) = getopt.getopt(sys.argv[1:], "cd:o:")
for (opt, val) in options:
- if opt == '-d':
+ if opt == '-c':
+ binary = False
+ elif opt == '-d':
mad_debug = int(val)
+ elif opt == '-o':
+ target = val
if len(arguments) == 0:
arguments = ['-']
# Generate code
if arguments == ['-']:
generate(sys.stdout)
- elif len(arguments) == 1:
- stem = arguments[0][:-4]
- out = open(stem + ".c", "w")
- generate(out)
- out.close()
- compile = "cc %s.c -lm -o %s" % (stem, stem)
- if os.system(compile) == 0:
- os.remove(stem + ".c")
- else:
- print "Compilation failed"
- out.close()
- else:
- sys.stderr.write("mad: multiple file args are not yet supported\n")
+ elif not target and len(arguments) > 1:
+ sys.stderr.write("mad: -o is required with multiple sourcefiles.\n")
sys.exit(1)
+ else:
+ if not target:
+ target = arguments[0][:-4]
+ for file in arguments:
+ stem = file[:-4]
+ out = open(stem + ".c", "w")
+ generate(out)
+ out.close()
+ srclist = " ".join(map(lambda x: x[:-4] + ".c", arguments))
+ if binary:
+ compile = "cc %s -lm -o %s" % (srclist, target)
+ if os.system(compile) == 0:
+ os.system("rm -f " + srclist)
# end