]> thyrsus.com Git - mad.git/commitdiff
Addedc CONTINUE, OR WHENEVER, and EXECUTE.
authorEric S. Raymond <esr@thyrsus,com>
Tue, 27 Jan 2004 08:11:44 +0000 (08:11 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Tue, 27 Jan 2004 08:11:44 +0000 (08:11 +0000)
mad

diff --git a/mad b/mad
index 7f6873196b5039ea56c5f92c66eaa4adb6126a45..9cdcf5a55b009084396370faebaf797a084b5bd4 100755 (executable)
--- a/mad
+++ b/mad
@@ -1,9 +1,9 @@
 #!/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',
@@ -60,10 +60,13 @@ def t_FLOATNUM(t):
     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'
@@ -116,6 +119,11 @@ def p_labeled_card(t):
 
 # Statement level
 
+## CONTINUE
+def p_statement_continue(t):
+    'statement : CONTINUE'
+    t[0] = ('continue',)
+
 ## DIMENSION
 def p_statement_dimension(t):
     'statement : DIMENSION dimension_list'
@@ -138,6 +146,14 @@ def p_end_of_functions(t):
     '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'
@@ -216,6 +232,9 @@ def p_whenever_simple(t):
 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):
@@ -479,6 +498,12 @@ def print_statement(statement):
                         '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))
@@ -495,6 +520,10 @@ def print_statement(statement):
             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:
@@ -503,6 +532,8 @@ def print_statement(statement):
             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`)