From: Eric S. Raymond Date: Thu, 22 Jan 2004 20:00:12 +0000 (+0000) Subject: Process R properly. X-Git-Tag: 1.0~176 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=be8cb4781c070be8d5475c640de0ddfd5aba6cc9;p=mad.git Process R properly. --- diff --git a/mad b/mad index 42f0192..fcad61c 100755 --- 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