]> thyrsus.com Git - mad.git/commitdiff
Process R properly.
authorEric S. Raymond <esr@thyrsus,com>
Thu, 22 Jan 2004 20:00:12 +0000 (20:00 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Thu, 22 Jan 2004 20:00:12 +0000 (20:00 +0000)
mad

diff --git a/mad b/mad
index 42f01924a28f478bb274e5591bb8dd6e4adc1063..fcad61cceb04d0a36ac726e42ee8fa224caaa859 100755 (executable)
--- a/mad
+++ b/mad
@@ -2,7 +2,7 @@
 
 reserved = ('CONDITIONAL', 'DIMENSION', 'END', 'FOR', 'FORMAT',
             'FUNCTION', 'INTEGER', 'INTERNAL', 'OF', 'PRINT', 'PROGRAM',
-            'READ', 'THROUGH', 'TO', 'TRANSFER', 'VALUES', 'VECTOR',
+            'READ', 'REMARK', 'THROUGH', 'TO', 'TRANSFER', 'VALUES', 'VECTOR',
             'WHENEVER')
 
 tokens = reserved + (
@@ -166,6 +166,15 @@ def p_print_format(t):
     'statement : PRINT FORMAT varlist'
     t[0] = ('print',) + tuple(t[3])
 
+## REMARK
+def p_remark1(t):
+    'statement : REMARK STRING'
+    t[0] = ('remark', t[2])
+
+def p_remark2(t):
+    'statement : REMARK'
+    t[0] = ('remark',)
+
 ## THROUGH
 def p_through_for(t):
     'statement : THROUGH NAME COMMA FOR NAME EQUALS expression COMMA expression COMMA expression'
@@ -466,6 +475,11 @@ def print_statement(statement):
         return 'if (' + print_expr(statement[1]) + ') ' + print_statement(statement[2])
     elif statement[0] == 'read':
         return 'scanf("' + fmt_convert(format[statement[1]], write=False) + '", ' + ', '.join(map(lambda x: '&'+x, statement[2:])) + ');'
+    elif statement[0] == 'remark':
+        if len(statement) == 1:
+            return "\n"
+        else:
+            return "/* %s */\n" % statement[1].strip()
     elif statement[0] == 'print':
         fmt = fmt_convert(format[statement[1]])
         if len(statement) < 3:
@@ -538,6 +552,9 @@ if __name__ == '__main__':
             fp.close()
         # 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)
         # Equally grotty hack to add end-of-statement delimiters
         source = re.sub('\n([A-Z]|\t)', ' ;\n\\1', source).rstrip() + ' ;\n'
         # Parse