#!/usr/bin/env python
-reserved = ('CONDITIONAL', 'DIMENSION', 'END', 'FOR', 'FORMAT', 'FUNCTION',
- 'INTEGER', 'INTERNAL', 'OF', 'PAUSE', 'PRINT', 'PROGRAM', 'READ',
- 'COMMENT', 'THROUGH', 'TO', 'TRANSFER', 'VALUES', 'VECTOR',
- 'WHENEVER')
+reserved = ('CONDITIONAL', 'CONTINUE', 'DIMENSION', 'END', 'EXECUTE',
+ 'FOR', 'FORMAT', 'FUNCTION', 'INTEGER', 'INTERNAL', 'OF',
+ 'PAUSE', 'PRINT', 'PROGRAM', 'READ', 'COMMENT', 'THROUGH',
+ 'TO', 'TRANSFER', 'VALUES', 'VECTOR', 'WHENEVER')
tokens = reserved + (
'SEMI', 'COMMA',
return t
def t_INTNUM(t):
- r'\d+'
+ r'\d+B?'
# Leading zeros flip us into ocal in C, therefore strip them.
while len(t.value) > 1 and t.value[0] == '0':
t.value = t.value[1:]
+ # Handle binary constants here
+ if t.value[-1] == "B":
+ t.value = t.value[:-1]
return t
t_ignore = ' \n\t'
# Statement level
+## CONTINUE
+def p_statement_continue(t):
+ 'statement : CONTINUE'
+ t[0] = ('continue',)
+
## DIMENSION
def p_statement_dimension(t):
'statement : DIMENSION dimension_list'
'statement : END OF FUNCTION'
t[0] = ('end_function',)
+## EXECUTE
+def p_execute(t):
+ 'statement : EXECUTE FUNCALL application'
+ t[0] = ('execute', ('apply', t[2], t[3]))
+def p_execute_noargs(t):
+ 'statement : EXECUTE FUNCALL'
+ t[0] = ('execute', ('apply', t[2], []))
+
## INTEGER
def p_integer(t):
'statement : INTEGER varlist'
def p_whenever_complex(t):
'statement : WHENEVER expression'
t[0] = ('whenever', t[2], t[4])
+def p_whenever_or(t):
+ 'statement : OR WHENEVER expression'
+ t[0] = ('or', t[3])
# VECTOR VALUES
def p_vector_values(t):
'integer',
'values'):
pass
+ elif statement[0] == 'continue':
+ return "/* continue */;"
+ elif statement[0] == 'end_conditional':
+ return "}"
+ elif statement[0] == 'execute':
+ return print_expr(statement[1]) + ";"
elif statement[0] == 'for':
(keyword, label, dummy, start, increment, predicate) = statement
return 'for (%s = %s; %s; %s += %s) {' % (dummy, print_expr(start), print_expr(predicate), dummy, print_expr(increment))
return "\n"
else:
return "/* %s */\n" % statement[1].strip()
+ elif statement[0] == 'or':
+ return 'else if (' + print_expr(statement[2]) + ') {'
+ elif statement[0] == 'otherwise':
+ return 'else {'
elif statement[0] == 'print':
fmt = fmt_convert(format[statement[1]])
if len(statement) < 3:
return 'printf("' + fmt + '", ' + ', '.join(map(print_expr, statement[2:])) + ');'
elif statement[0] == 'substitution':
return statement[1] + ' = ' + print_expr(statement[2]) + ';'
+ elif statement[0] == 'whenever':
+ return 'if (' + print_expr(statement[1]) + ') {'
else:
return('// ' + `statement`)