t_ignore = ' \n\t'
def t_error(t):
- sys.stderr.write('"%s", line %d: illegal character %s\n' % (sourcefile, t.lineno, `t.value[0]`))
+ global sourceline
+ sourceline = t.lineno
+ nonfatal('illegal character %s' % `t.value[0]`)
t.skip(1)
# Build the lexer
'range : NAME application DOTRANGE NAME application'
t[0] = ('range', t[1], t[2][0], t[5][0])
if t[1] != t[4]:
- sys.stderr.write("\"%s\", %d: variable names in range don't match!" % (sourcefile, t.lineno(1)))
- sys.exit(1)
+ global sourceline
+ sourceline = t.lineno(1)
+ nonfatal("variable names in range don't match.")
## R
def p_remark1(t):
def p_error(t):
"Gets fed an error token."
- sys.stderr.write('"%s", line %d: syntax error at "%s"\n' % (sourcefile, t.lineno, t.value))
+ global sourceline
+ sourceline = t.lineno
+ nonfatal('syntax error on token "%s"' % t.value)
import yacc
yacc.yacc()
else:
nonfatal('no EXTERNAL declaration matches this ENTRY')
except:
- sys.stderr.write("mad: internal error while analyzing code for line %d\n" % line)
+ nonfatal("internal error while analyzing code")
(exc_type, exc_value, exc_traceback) = sys.exc_info()
raise exc_type, exc_value, exc_traceback
if left == 'int' or right == 'int':
#print "<-mode of binary operand"
return 'int'
- sys.stderr.write("mad: internal error while computing mode of %s\n" % `t`)
+ nonfatal("internal error while computing mode of %s\n" % `t`)
sys.exit(1)
def prinC1(t):
while str[i] != ',':
i += 1
if i <= 0:
- sys.stderr.write('"%s", line %d: invalid spacer in %s\n' % (sourcefile, sourceline, str))
- sys.exit(1)
+ nonfatal('invalid spacer in %s\n' % str)
count = int(str[1:i])
res += ' ' * count
str = str[i:]
str = str[i:]
types += ['int'] * count
else:
- sys.stderr.write('"%s", line %d: invalid field code %s at %d in format string %s!\n' % (sourcefile, sourceline, `str[0]`, len(fmt)-len(str), `fmt`))
- sys.exit(1)
+ nonfatal('invalid field code %s at %d in format string %s!\n' % (`str[0]`, len(fmt)-len(str), `fmt`))
#print "<-fmt_convert() = %s" % res
return (res, types)
elif res[0] == '4': # Skip to next quarter page
res = res + r"\v" + res[1:]
else: # Anything else falls through
- sys.stderr.write('unknown print code %s ignored\n' % res[0])
+ nonfatal('unknown print code %s ignored\n' % res[0])
res = res[1:]
res = res + '\\n'
return res
if rep.endswith(", "):
rep = rep[:-2]
rep = rep + ") {"
- #if defaulted:
- # sys.stderr.write("warning: defaulted base type for %s\n" % ", ".join(defaulted))
return rep
elif statement[0] == 'error_return':
- return 'puts("ERROR RETURN"); exit(1);'
+ return 'puts("ERROR RETURN from line %s:%d"); exit(1);' % (sourcefile,sourceline)
elif statement[0] == 'execute':
return print_C_expr(statement[1]) + ";"
elif statement[0] == 'external_call':
elif type(ispec)==type(()) and ispec[0]=='range' and itype=='char':
inlist.append(print_C_expr(ispec))
else:
- sys.stderr.write("unsupported type in READ FORMAT\n")
- sys.exit(1)
+ nonfatal("unsupported type in READ FORMAT")
return 'scanf("' + fmt + '", ' + ', '.join(inlist) + ');'
elif statement[0] == 'remark':
if len(statement) == 1:
out.write("\n")
indent = 0
- global sourceline
+ global sourcefile, sourceline
scopes = [] # THROUGH scopes that are pending
- for (file, sourceline, label, statement) in deck:
+ for (sourcefile, sourceline, label, statement) in deck:
if label in targets:
out.write(" " + label+':\n')
if statement[0] in ('for', 'map'):
try:
rep = print_C_statement(statement)
except:
- sys.stderr.write("mad: internal error while generating code for line %d\n" % sourceline)
+ nonfatal("internal error while generating code")
(exc_type, exc_value, exc_traceback) = sys.exc_info()
raise exc_type, exc_value, exc_traceback
if rep: