t[0] = ('or', t[3])
# VECTOR VALUES
-def p_vector_values(t):
+def p_vector_values_string(t):
'statement : VECTOR VALUES NAME EQUALS STRING'
t[0] = ('values',) + (t[3], t[5])
+def p_vector_values_array(t):
+ 'statement : VECTOR VALUES NAME EQUALS arglist'
+ t[0] = ('values',) + (t[3], t[5])
## Assignment
def p_statement_substitution1(t):
sys.exit(1)
def prinC1(t):
+ "Recursive print of expression value"
if t[0] == 'variable':
res = t[1]
if len(t) > 2:
- for dim in t[2]:
- res += '[' + print_C_expr(dim) + ']'
+ if len(t[2]) == 1:
+ # One subscript, the ordinary linear-addressing case.
+ subscript = print_C_expr(t[2][0])
+ else:
+ # More than one subscript; this is where we implement MAD's
+ # weird reliance on dope vectors.
+ raise IndexError
+ res += '[' + subscript + ']'
return res
elif t[0] == 'funptr':
return t[1]
return 'printf("' + fmt + '", ' + ', '.join(map(print_C_expr, statement[2:])) + ');'
elif statement[0] == 'read':
(fmt, types) = fmt_convert(format[statement[1]])
+ print "Foo!", (fmt, types)
inlist = []
for (ispec, itype) in zip(statement[2:], types):
if type(ispec) == type(""):
elif type(ispec)==type(()) and ispec[0]=='range' and itype=='char':
inlist.append(print_C_expr(ispec))
else:
- nonfatal("unsupported type in READ FORMAT")
+ nonfatal("unsupported type in READ FORMAT:" + `ispec`)
return 'scanf("' + fmt + '", ' + ', '.join(inlist) + ');'
elif statement[0] == 'remark':
if len(statement) == 1:
out.write("typedef int bool;\n")
for (id, value) in static.items():
- out.write('static const char *%s\t= "%s";\n' % (id,fmt_convert(value)))
+ if typedict[id] == 'char':
+ out.write('static char *%s\t= "%s";\n' % (id,fmt_convert(value)))
+ elif typedict[id] == 'int':
+ out.write('static int %s\t= {%s};\n' % (id, ", ".join(map(lambda x: x[1], value))))
+ else:
+ sys.stderr.write("mad: static %s has unknown type\n")
+ sys.exit(1)
declarations = ""
for vtype in ('double', 'int', 'bool', 'char'):
vars = filter(lambda x: typedict[x] == vtype, typedict.keys())
+ vars = filter(lambda x: x not in static, vars)
if vars:
declarations += vtype
for var in vars: