t_ignore = ' \n'
def t_error(t):
- sys.stderr.write('Line %d: illegal character %s\n' % (t.lineno, `t.value[0]`))
+ sys.stderr.write('"%s", line %d: illegal character %s\n' % (sourcefile, t.lineno, `t.value[0]`))
t.skip(1)
# Build the lexer
# Error handling
def p_error(t):
- sys.stderr.write('Line %d: syntax error at "%s"\n' % (t.lineno, t.value))
+ sys.stderr.write('"%s", line %d: syntax error at "%s"\n' % (sourcefile, t.lineno, t.value))
import yacc
yacc.yacc()
if file == '-':
sourcefile = 'stdin'
source = sys.stdin.read()
+ elif not file.endswith('.mad'):
+ sys.stderr.write("mad: bad file extension on %s\n" % file)
+ sys.exit(1)
else:
sourcefile = file
fp = open(file)
yacc.parse(source, debug=mad_debug)
# Perform global analysis
- analyze(deck)
+ analyze(deck)
# Generate code
- generate(sys. stdout)
+ if arguments == ('-',):
+ generate(sys.stdout)
+ elif len(arguments) == 1:
+ out = open(arguments[0][:-4] + ".c", "w")
+ generate(out)
+ out.close()
+ else:
+ sys.stderr.write("mad: multiple file args are not yet supported\n")
+ sys.exit(1)
+
+# end
+