reserved = ('BOOLEAN', 'CONDITIONAL', 'CONTINUE', 'DIMENSION', 'END',
'ENTRY', 'EXECUTE', 'EXTERNAL', 'FOR', 'FORMAT',
- 'FUNCTION', 'INTEGER', 'INTERNAL', 'OF', 'PAUSE', 'PRINT',
- 'PROGRAM', 'READ', 'RETURN', 'THROUGH', 'TO', 'TRANSFER',
- 'VALUES', 'VECTOR', 'WHENEVER',
+ 'FUNCTION', 'INTEGER', 'INTERNAL', 'IS', 'MODE',
+ 'NORMAL', 'OF', 'PAUSE', 'PRINT', 'PROGRAM', 'READ',
+ 'RETURN', 'THROUGH', 'TO', 'TRANSFER', 'VALUES', 'VECTOR',
+ 'WHENEVER',
# This is a pseudo-keyword generated early in compilation.
'COMMENT')
typedict = {}
arraydepths = {}
returntypes = {}
+normalmode = 'double'
def initfunc(f):
global currentfunc
t[0] = ('internal', t[3], tuple(t[4]), t[6])
funcnames.append(t[3])
+## NORMAL MODE IS
+def p_normal(t):
+ "statement : NORMAL MODE IS typeval"
+ t[0] = ('normal', t[1])
+def p_typeval_int(t):
+ "typeval : INTEGER"
+ t[0] = 'int'
+def p_typeval_bool(t):
+ "typeval : BOOLEAN"
+ t[0] = 'bool'
+
## PAUSE
def p_pause(t):
"statement : PAUSE expression"
elif statement[0] == 'integer':
for var in statement[1:]:
typedict[currentfunc][var] = 'int'
+ elif statement[0] == 'normal':
+ global normalmode
+ normalmode = statement[1]
elif statement[0] == 'values':
var = statement[1]
if var in refcount:
typedict[currentfunc][var] = type
# Type inference loop. We initialized for this by deducing types
# from READ FORMAT statements. INTEGER, and BOOLEAN declarations
- # above. Now propagate int and bool type markers through
+ # above. Now propagate markers of non-normalmode type through
# expression evaluation until we can't deduce any more int or bool
# type bindings for variables. Everything else just defaults to
# double.
# different modes.
m = mode(statement[1])
returntypes[currentfunc] = m
- if m in ('int','bool') and returntypes[currentfunc] != m:
+ if m != normalmode and returntypes[currentfunc] != m:
deductions += 1
elif statement[0] == 'substitution':
# Propagate type markers through assignment
m = mode(statement[2])
typedict[currentfunc][statement[1]] = m
- if m in ('int','bool') and typedict[currentfunc][statement[1]]!=m:
+ if m != normalmode and typedict[currentfunc][statement[1]]!=m:
deductions += 1
if deductions == 0:
break
#print "->mode", t
if t[0] == 'variable':
#print "<-mode of ", t[1]
- return typedict[currentfunc].get(t[1], 'double')
+ return typedict[currentfunc].get(t[1], normalmode)
elif t[0] in ('UMINUS', 'UPLUS', 'POW', 'ABS'):
#print "<-mode of ", t[1]
return mode(t[1])
#print "<-mode of string ", t[1]
return 'int'
elif t[0] == 'apply':
- return returntypes.get(t[1], "double")
+ return returntypes.get(t[1], normalmode)
elif t[0] in logops:
#print "<-bool (logical operator)", t[1]
return 'bool'
'dimension',
'external_function',
'integer',
+ 'normal',
'values'):
pass
elif statement[0] == 'continue':
func = statement[1]
types = typedict[func]
depths = arraydepths[currentfunc]
- rep = "\n" + returntypes.get(func, "double") + " " + func[:-1] + "("
+ rep = "\n" + returntypes.get(func, normalmode) + " " + func[:-1] + "("
defaulted = []
if statement[2]:
for (dummy, var) in statement[2]:
rep += types[var] + " " + declarator + ", "
del types[var]
else:
- rep += "double " + declarator + ", "
+ rep += normalmode + " " + declarator + ", "
defaulted.append(var)
rep = rep[:-2]
rep = rep + ") {\n"
return 'if (' + print_expr(statement[1]) + ') ' + print_statement(statement[2])
elif statement[0] == 'internal':
return ' %s %s {return %s;}' % \
- (returntypes.get(statement[1], "double"), print_expr(('apply', statement[1], statement[2])), print_expr(statement[3]))
+ (returntypes.get(statement[1], normalmode), print_expr(('apply', statement[1], statement[2])), print_expr(statement[3]))
elif statement[0] == 'pause':
return('printf("%o", ' + print_expr(statement[1]) + '); getchar();')
elif statement[0] == 'read':