deck = [] # List of tuples generated by parsing
targets = {} # Dictionary of targets of TRANSFERs
headers = [] # Required .h file basenames
-funcnames = [] # List of function names
+funcnames = ["main."] # List of function names
dimensions = {} # Dictionary of array depths
arraydepths = {} # Dictionary of array dimensions
-returntypes = {} # Dictionary of function returntypes
+returntypes = {"main.":'int'} # Dictionary of function returntypes
static = {} # Dictionary of static char variables
format = {} # Dictionary of format strings
hasmain = False # Does this program have a main line?
-def initfunc(f):
- global currentfunc
- currentfunc = f
- funcnames.append(currentfunc)
-
-initfunc("main.")
-returntypes['main.'] = 'int'
-
# Program level
def p_program(t):
## ENTRY
def p_entry(t):
"statement : ENTRY TO FUNCALL"
- initfunc(t[3])
t[0] = ('entry', t[3])
## ERROR RETURN
def analyze():
"Gather variable types and determine function boundaries."
- global deck, currentfunc, hasmain
+ global deck, hasmain
global sourcefile, sourceline
# We may need to generate a pseudo-function call
for i in range(len(deck)):
elif statement[0] == 'dimension':
for (var, dimlist) in statement[1]:
dimensions[var] = dimlist
- elif statement[0] == 'entry':
- currentfunc = statement[1]
- funcline = sourceline
elif statement[0] == 'integer':
for var in statement[1:]:
typedict[var] = 'int'
# Do type deductions from format fields
for card in deck:
(sourcefile, sourceline, label, statement) = card
- if statement[0] == 'entry':
- currentfunc = statement[1]
- funcline = sourceline
- elif statement[0] == 'read':
+ if statement[0] == 'read':
if statement[1] not in format:
nonfatal("uninitialized format string" +`statement[1]`)
else:
# expression evaluation until we can't deduce any more int or bool
# type bindings for variables. Everything else just defaults to
# double.
+ currentfunc = None
while True:
deductions = 0
for card in deck:
return res
def print_C_statement(statement):
- global currentfunc
if statement[0] in ('boolean',
'dimension',
'external_function',