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 + (
'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'
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:
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