diff python/testc3.py @ 149:74241ca312cc

Fixes on parser and semantics
author Windel Bouwman
date Fri, 01 Mar 2013 11:43:52 +0100
parents e5263f74b287
children 4ae0e02599de
line wrap: on
line diff
--- a/python/testc3.py	Fri Mar 01 10:24:01 2013 +0100
+++ b/python/testc3.py	Fri Mar 01 11:43:52 2013 +0100
@@ -1,10 +1,14 @@
 import c3.parser, c3.semantics
 from ppci.errors import printError, Diagnostics
+import time
 
 testsrc = """
 package test;
 
-public function void test1() 
+var u32 a ;
+var u32 c, d;
+
+function void test1() 
 {
     var u32 b;
     var int a = 10;
@@ -18,20 +22,31 @@
     }
 }
 
-public function int t2(u32 a, u32 b)
+function int t2(u32 a, u32 b)
 {
    return a + b;
    a = 2
 }
 
+function int t2(u32 a, u32 b)
+{
+   return a + b;
+   a = 2 + 33 - 1;
+   a = a - 2
+}
+
 """
 
-def printAst(ast):
-   print(ast)
+def printAst(ast, indent=''):
+   print(indent + str(ast))
+   if isinstance(ast, c3.astnodes.Package):
+      for s in ast.scope:
+         printAst(s, indent + '  ')
+   if isinstance(ast, c3.astnodes.Procedure):
+      for s in ast.scope:
+         printAst(s, indent + '  ')
    for c in ast.getChildren():
-      printAst(c)
-   if isinstance(ast, c3.astnodes.Package):
-      print('PACK', ast.scope)
+      printAst(c, indent + '  ')
 
 def do():
    print('[0] source:')
@@ -40,8 +55,10 @@
    diag = Diagnostics()
    sema = c3.semantics.Semantics(diag)
    p = c3.parser.Parser(sema, diag)
-   
+   t1 = time.time()
    p.parseSource(testsrc)
+   t2 = time.time() 
+   print('parsetime: {0} [s]'.format(t2 - t1))
 
    for d in diag.diags:
       print('ERROR:', d)