]> thyrsus.com Git - mad.git/commitdiff
Next step towards good compilation.
authorEric S. Raymond <esr@thyrsus,com>
Fri, 23 Jan 2004 01:02:23 +0000 (01:02 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Fri, 23 Jan 2004 01:02:23 +0000 (01:02 +0000)
mad

diff --git a/mad b/mad
index fcad61cceb04d0a36ac726e42ee8fa224caaa859..a96169f5363e1fe79bb8e49da44259ec43730b23 100755 (executable)
--- a/mad
+++ b/mad
@@ -163,8 +163,14 @@ def p_read_format(t):
 
 ## PRINT FORMAT
 def p_print_format(t):
-    'statement : PRINT FORMAT varlist'
+    'statement : PRINT FORMAT exprlist'
     t[0] = ('print',) + tuple(t[3])
+def p_exprlist(t):
+    'exprlist : expression'
+    t[0] = [t[1]]
+def p_exprlist_continue(t):
+    'exprlist : exprlist COMMA expression'
+    t[0] = t[1] + [t[3]]
 
 ## REMARK
 def p_remark1(t):
@@ -401,10 +407,10 @@ def print_expr(t):
     else:
         return '***'+`t`
 
-def fmt_convert(str, write=True):
+def fmt_convert(fmt, write=True):
     "Convert MAD format string to C printf/scanf"
     res = ''
-    str = str[1:-1]
+    str = fmt[1:-1]
     while True:
         if str[0] == '*':
             break
@@ -442,7 +448,7 @@ def fmt_convert(str, write=True):
             str = str[i:]
         elif str[0] == 'H':
             if write:
-                res += str[1:count+1]
+                res += str[1:count]
             str = str[count+1:]
         elif str[0] == 'I':
             i = 1
@@ -451,12 +457,12 @@ def fmt_convert(str, write=True):
             res += ('%' + str[1:i] + 'd') * count
             str = str[i:]
         else:
-            sys.stderr.write('"%s", line %d: invalid field code in format string %s!\n' % (sourcefile, sourceline, str))
+            sys.stderr.write('"%s", line %d: invalid field code %s at %d in format string %s!\n' % (sourcefile, sourceline, `str[0]`, len(fmt)-len(str), `fmt`))
             sys.exit(1)
     # Clip off format character
     if write:
         res = res[1:]
-    res = res + '\\n'
+        res = res + '\\n'
     return res
 
 def print_statement(statement):
@@ -553,8 +559,8 @@ if __name__ == '__main__':
         # Grotty hack to remove continuation digits
         source = re.sub("\n       [0-9] ", "\n        ", source)
         # A grotty hack to transform remarks
-        source = re.sub('\tR', '\tREMARK', source)
-        source = re.sub('\tREMARK (.*)', '\tREMARK $\\1$', source)
+        source = re.sub(r'\tR\n', '\tREMARK\n', source)
+        source = re.sub(r'\tR (.*)', '\tREMARK $\\1$', source)
         # Equally grotty hack to add end-of-statement delimiters
         source = re.sub('\n([A-Z]|\t)', ' ;\n\\1', source).rstrip() + ' ;\n'
         # Parse