]> thyrsus.com Git - mad.git/commitdiff
First try at compiling internal functions.
authorEric S. Raymond <esr@thyrsus,com>
Tue, 20 Jan 2004 18:29:27 +0000 (18:29 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Tue, 20 Jan 2004 18:29:27 +0000 (18:29 +0000)
mad

diff --git a/mad b/mad
index 05e66626ececafcf47f4730e1cbf493d16f3b297..2b12f6d24e94d7d6be1cbaffc1d63b5aaef31061 100755 (executable)
--- a/mad
+++ b/mad
@@ -51,7 +51,7 @@ for r in reserved:
 refcount = {}
 
 def t_NAME(t):
-    r'[A-Z][A-Z0-9]*\.?'
+    r'[A-Z][A-Z0-9]*(\.(?!P))?'
     t.type = reserved_map.get(t.value, 'NAME')
     if t.type and t.value[-1] == '.':
         t.type = 'FUNCALL'
@@ -258,15 +258,15 @@ def p_function_application(t):
     t[0] = ('apply', t[1], tuple(t[2]))
 
 def p_expression_application(t):
-    'application : LPAREN inner_expression RPAREN'
+    'application : LPAREN arglist RPAREN'
     t[0] = t[2]
 
 def p_expression_tail_empty(t):
-    'inner_expression : expression'
+    'arglist : expression'
     t[0] = [t[1]]
 
 def p_expression_tail_nonempty(t):
-    'inner_expression : inner_expression COMMA expression'
+    'arglist : arglist COMMA expression'
     t[0] = t[1] + [t[3]]
 
 def p_expression_name(t):
@@ -454,8 +454,15 @@ def print_statement(statement):
         return('// ' + `statement`)
 
 def generate(out):
-    out.write('#include <math.h>\n')
-    out.write('main(int argc, char *argv[])\n')
+    out.write('#include <math.h>\n\n')
+
+    for (label, statement) in deck:
+        if statement == 'function':
+            # FIXME: someday, deduce when return is of integral type
+            out.write('float %s {return %s;}' \
+                      (t[1], print_expr(('apply', t[2], t[3])),t[4]))
+
+    out.write('\nmain(int argc, char *argv[])\n')
     out.write('{\n')
     if integers:
         out.write('\tint ' + ', '.join(integers) + ';\t/* INTEGER */\n')