Author: leo
Date: Tue Sep 27 05:10:58 2005
New Revision: 9253

Modified:
   branches/leo-ctx5/languages/bc/TODO
   branches/leo-ctx5/languages/bc/bc.py
   branches/leo-ctx5/languages/bc/docs/parrot_bc.pod
   branches/leo-ctx5/languages/bc/grammar/bc_python.g
   branches/leo-ctx5/languages/bc/lib/Parrot/Test/Bc.pm
   branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py
   branches/leo-ctx5/src/call_list.txt
Log:
merge -r9248:9252 from trunk

Modified: branches/leo-ctx5/languages/bc/TODO
==============================================================================
--- branches/leo-ctx5/languages/bc/TODO (original)
+++ branches/leo-ctx5/languages/bc/TODO Tue Sep 27 05:10:58 2005
@@ -4,6 +4,8 @@
 # Some tidbits on what is to do for Parrot bc.
 # See docs/parrot_bc.pod for visions.
 
+- Emit Perl6 code
+
 - Custom PMCs for Parrot bc
   - Decimal BigNum libraries
  

Modified: branches/leo-ctx5/languages/bc/bc.py
==============================================================================
--- branches/leo-ctx5/languages/bc/bc.py        (original)
+++ branches/leo-ctx5/languages/bc/bc.py        Tue Sep 27 05:10:58 2005
@@ -3,6 +3,7 @@
 
 import os
 import sys
+import re
 import getopt
 
 lib_path = os.path.join( os.path.dirname(sys.argv[0]), 'python', 'lib' )
@@ -63,7 +64,11 @@ def main():
    (options, bc_filenames) = getopt.getopt(sys.argv[1:], 'l')
    # TODO: option checkint, consider option -l
    # TODO: allow multiple input files and STDIN
-   bc_fh = open(bc_filenames[0], 'r')
+   bc_fn  = bc_filenames[0]
+   bc_fh = open(bc_fn, 'r')
+   regexp = re.compile( r"bc$" )
+   pir_fh = open( regexp.sub("pir", bc_fn), 'w' )
+   p6_fh  = open( regexp.sub("p6", bc_fn), 'w' )
 
    L = bc.BcLexer.Lexer(bc_fh) 
    P = bc.BcParser.Parser(L)
@@ -88,6 +93,7 @@ def main():
    visitor = Visitor()
 
    ###show tree
+   sys.stdout = pir_fh
    print ""
    print "=begin comment"
    print ""
@@ -97,7 +103,7 @@ def main():
    print ""
    print "visit>>"
    print ""
-   visitor.visit(ast);
+   # visitor.visit(ast);
    print "visit<<"
    print ""
    print "=end comment"
@@ -105,7 +111,6 @@ def main():
 
    W = bc.BcTreeWalker.Walker();
    W.gen_pir(ast);
-
    pir_ast = W.getAST()
    print ""
    print "=begin comment"
@@ -116,7 +121,7 @@ def main():
    print pir_ast.toStringList()
    print ""
    print "visit>>\n"
-   visitor.visit(pir_ast);
+   #visitor.visit(pir_ast);
    print "visit<<"
    print ""
    print "=end comment"
@@ -162,5 +167,19 @@ def main():
 .end
    """
 
+   # Now dump the AST as Perl6
+   # TODO: This is a dummy implementation right now
+   sys.stdout = p6_fh
+   W.gen_p6(ast);
+   p6_ast = W.getAST()
+   print ""
+   print "=begin comment"
+   print ""
+   print "AST after being processed by TreeParser"
+   print ""
+   print "p6_ast.toStringList:" 
+   print p6_ast.toStringList()
+   print ""
+
 if __name__ == "__main__":
    main()

Modified: branches/leo-ctx5/languages/bc/docs/parrot_bc.pod
==============================================================================
--- branches/leo-ctx5/languages/bc/docs/parrot_bc.pod   (original)
+++ branches/leo-ctx5/languages/bc/docs/parrot_bc.pod   Tue Sep 27 05:10:58 2005
@@ -3,15 +3,17 @@
 
 =head1 Overview
 
-This is an implementation of 'POSIX bc'. It is based on ANTLR.
+This is an implementation of 'POSIX bc'. It is based on Python classes 
generated by ANTLR.
 
 =head1 Why Parrot bc
 
 Self education. A fairly simple language but has symbols and subroutines.
 Test for decimal bignum libraries.
+A starting point for more interesting languages like R, GDL.
 
 =head2 Vision
 
+Do the code generation like bc -> PIL -> PIR
 Be compatible with Pirate and Pugs.
 Switch to Perl6 after Gary Evans has made a Perl6 backend for ANTLR.
 

Modified: branches/leo-ctx5/languages/bc/grammar/bc_python.g
==============================================================================
--- branches/leo-ctx5/languages/bc/grammar/bc_python.g  (original)
+++ branches/leo-ctx5/languages/bc/grammar/bc_python.g  Tue Sep 27 05:10:58 2005
@@ -505,3 +505,10 @@ gen_pir!
       #gen_pir = #([PIR_HEADER, "pir header\n#"], #B, [PIR_FOOTER, "pir 
footer\n#"]); 
     }
   ;
+
+gen_p6!
+  : B:expr_list
+    {
+      #gen_p6 = #([PIR_HEADER, "pir header\n#"], #B, [PIR_FOOTER, "pir 
footer\n#"]); 
+    }
+  ;

Modified: branches/leo-ctx5/languages/bc/lib/Parrot/Test/Bc.pm
==============================================================================
--- branches/leo-ctx5/languages/bc/lib/Parrot/Test/Bc.pm        (original)
+++ branches/leo-ctx5/languages/bc/lib/Parrot/Test/Bc.pm        Tue Sep 27 
05:10:58 2005
@@ -51,8 +51,8 @@ foreach my $func ( keys %language_test_m
         my $test_prog_args = $ENV{TEST_PROG_ARGS} || '';
         my $test_prog      = $ENV{PARROT_BC_TEST_PROG} ?
                                "$ENV{PARROT_BC_TEST_PROG}  ${test_prog_args} 
languages/${lang_f}" :
-                               "python languages/bc/bc.py languages/${lang_f} 
> languages/${pir_f} && $self->{parrot} languages/${pir_f}";
-         # die Dumper( $test_prog, \%ENV ) if $ENV:{PARROT_BC_TEST_PROG} ;
+                               "python languages/bc/bc.py languages/${lang_f} 
&& $self->{parrot} languages/${pir_f}";
+        # die Dumper( $test_prog );
 
         # This does nor create byte code, but bc code
         my $parrotdir       = dirname( $self->{parrot} );

Modified: branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py
==============================================================================
--- branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py        
(original)
+++ branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py        Tue Sep 
27 05:10:58 2005
@@ -963,6 +963,39 @@ class Walker(antlr.TreeParser):
         self.returnAST = gen_pir_AST
         self._retTree = _t
     
+    def gen_p6(self, _t):    
+        
+        gen_p6_AST_in = None
+        if _t != antlr.ASTNULL:
+            gen_p6_AST_in = _t
+        self.returnAST = None
+        currentAST = antlr.ASTPair()
+        gen_p6_AST = None
+        B_AST = None
+        B = None
+        try:      ## for error handling
+            pass
+            B = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
+            self.expr_list(_t)
+            _t = self._retTree
+            B_AST = self.returnAST
+            gen_p6_AST = currentAST.root
+            gen_p6_AST = antlr.make(self.astFactory.create(PIR_HEADER,"pir 
header\n#"), B_AST, self.astFactory.create(PIR_FOOTER,"pir footer\n#"));
+            currentAST.root = gen_p6_AST
+            if (gen_p6_AST != None) and (gen_p6_AST.getFirstChild() != None):
+                currentAST.child = gen_p6_AST.getFirstChild()
+            else:
+                currentAST.child = gen_p6_AST
+            currentAST.advanceChildToEnd()
+        
+        except antlr.RecognitionException, ex:
+            self.reportError(ex)
+            if _t:
+                _t = _t.getNextSibling()
+        
+        self.returnAST = gen_p6_AST
+        self._retTree = _t
+    
 
 _tokenNames = [
     "<0>", 

Modified: branches/leo-ctx5/src/call_list.txt
==============================================================================
--- branches/leo-ctx5/src/call_list.txt (original)
+++ branches/leo-ctx5/src/call_list.txt Tue Sep 27 05:10:58 2005
@@ -316,3 +316,6 @@ p       Jipp
 p       Jbip
 v       Jp
 v       JS
+
+# crypt
+t       tt

Reply via email to