From: Eric S. Raymond Date: Tue, 20 Jan 2004 18:58:55 +0000 (+0000) Subject: More compilation framework. X-Git-Tag: 1.0~184 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=bf392538f9a8f99668a8abdc37ad954c8c21451d;p=mad.git More compilation framework. --- diff --git a/mad b/mad index 50d1f11..3374d78 100755 --- a/mad +++ b/mad @@ -61,7 +61,7 @@ def t_NAME(t): 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 @@ -280,7 +280,7 @@ def p_expression_name(t): # 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() @@ -503,6 +503,9 @@ if __name__ == '__main__': 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) @@ -514,7 +517,18 @@ if __name__ == '__main__': 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 +