reserved = ('CONDITIONAL', 'DIMENSION', 'END', 'FOR', 'FORMAT',
'FUNCTION', 'INTEGER', 'INTERNAL', 'OF', 'PRINT', 'PROGRAM',
- 'READ', 'REMARK', 'THROUGH', 'TO', 'TRANSFER', 'VALUES', 'VECTOR',
+ 'READ', 'COMMENT', 'THROUGH', 'TO', 'TRANSFER', 'VALUES', 'VECTOR',
'WHENEVER')
tokens = reserved + (
## READ FORMAT
def p_read_format(t):
- 'statement : READ FORMAT varlist'
- t[0] = ('read',) + tuple(t[3])
+ 'statement : READ FORMAT NAME COMMA varlist'
+ t[0] = ('read', t[3]) + tuple(t[5])
## PRINT FORMAT
def p_print_format(t):
- 'statement : PRINT FORMAT exprlist'
- t[0] = ('print',) + tuple(t[3])
+ 'statement : PRINT FORMAT NAME COMMA exprlist'
+ t[0] = ('print', t[3]) + tuple(t[5])
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]]
+def p_print_format0(t):
+ 'statement : PRINT FORMAT NAME'
+ t[0] = ('print', t[3])
-## REMARK
+## R
def p_remark1(t):
- 'statement : REMARK STRING'
+ 'statement : COMMENT STRING'
t[0] = ('remark', t[2])
def p_remark2(t):
- 'statement : REMARK'
+ 'statement : COMMENT'
t[0] = ('remark',)
## THROUGH
str = str[i:]
elif str[0] == 'H':
if write:
- res += str[1:count]
+ res += str[1:count+1]
str = str[count+1:]
elif str[0] == 'I':
i = 1
if len(statement) < 3:
return 'printf("' + fmt + '");'
else:
- return 'printf("' + fmt + '", ' + ', '.join(statement[2:]) + ');'
+ return 'printf("' + fmt + '", ' + ', '.join(map(print_expr, statement[2:])) + ');'
elif statement[0] == 'substitution':
return statement[1] + ' = ' + print_expr(statement[2]) + ';'
else:
# Grotty hack to remove continuation digits
source = re.sub("\n [0-9] ", "\n ", source)
# A grotty hack to transform remarks
- source = re.sub(r'\tR\n', '\tREMARK\n', source)
- source = re.sub(r'\tR (.*)', '\tREMARK $\\1$', source)
+ source = re.sub(r'\tR\n', '\tCOMMENT\n', source)
+ source = re.sub(r'\tR (.*)', '\tCOMMENT $\\1$', source)
# Equally grotty hack to add end-of-statement delimiters
source = re.sub('\n([A-Z]|\t)', ' ;\n\\1', source).rstrip() + ' ;\n'
# Parse