scopes = []
targets = {}
untyped = []
+headers = []
# Program level
| expression NE expression
| expression POW expression
'''
- t[0] = (t[2][1:-1].lower(), t[1], t[3])
+ global headers
+ op = t[2][1:-1].lower()
+ t[0] = (op, t[1], t[3])
+ if op == 'pow':
+ headers.append("math")
def p_expression_not(t):
'expression : NOT expression %prec NOT'
def p_function_application(t):
'expression : FUNCALL application'
t[0] = ('apply', t[1], tuple(t[2]))
+ global headers
+ if t[1] in ('elog.', 'sqrt.'):
+ headers.append("math")
def p_expression_application(t):
'application : LPAREN arglist RPAREN'
untyped.remove(var)
lst.append(var)
+def croak(t, msg):
+ (file, line, label, statement) = t
+ sys.stderr.write('"%s", line %d: %s\n' % (file, line, msg))
+
def analyze():
"Gather variable types and determine function boundaries."
global integers, floats, bools, deck
if statement[0] == 'entry' and type(statement[1]) == type(""):
name = statement[1]
for j in range(i):
- if deck[i-j-1][3][0] == 'external_function':
- deck[i] = (file, line, label,
- ('entry', ('apply', name, deck[i-j-1][3][1])))
+ prev = deck[i-j-1][3]
+ if prev[0] == 'external_function':
+ deck[i] = (file, line, label, ('entry',
+ ('apply', name, prev[1])))
break
+ elif prev[0] == 'entry':
+ croak(prev, "multiple ENTRY points are not supported")
else:
- sys.stderr.write('"%s", line %d: no EXTERNAL declaration matches this ENTRY\n' % (file, line))
+ croak(deck[i], 'no EXTERNAL declaration matches this ENTRY')
+
def prin1(t):
if t[0] == 'variable':
return('// ' + `statement`)
def generate(out):
- out.write('#include <math.h>\n\n')
+ out.write("/* generated by the MAD compiler */\n\n")
+ if headers:
+ out.write('#include <math.h>\n\n')
if integers:
out.write('int ' + ', '.join(integers) + ';\t/* INTEGER */\n')
# Perform global analysis
analyze()
+ print "Baz!", headers
if (dump_tuples):
for t in deck: