]> thyrsus.com Git - mad.git/commitdiff
More compilation framework.
authorEric S. Raymond <esr@thyrsus,com>
Tue, 20 Jan 2004 18:58:55 +0000 (18:58 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Tue, 20 Jan 2004 18:58:55 +0000 (18:58 +0000)
mad

diff --git a/mad b/mad
index 50d1f11311964ea69b3be4e15c7b1148840a6fb5..3374d78820954bbb1a8ee55b28de2b58bbb824e1 100755 (executable)
--- 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
+