Charj : added support for the dot access operator (as opposed to the
authorMinas Charalambides <charala1@illinois.edu>
Thu, 27 May 2010 19:33:13 +0000 (14:33 -0500)
committerMinas Charalambides <charala1@illinois.edu>
Thu, 27 May 2010 19:33:13 +0000 (14:33 -0500)
            arrow). Now dots are turned into arrows in CharjASTModifier.g
            and the pup generation modules are free to choose either the
            dot or the arrow depending on the occasion.

src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/CharjASTModifier.g
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/PupRoutineCreator.java

index 95191f91eba71e4ec73a6629175d82146d967227..8dba031da3390b7cef48228e6cc1ff1fad5e1df2 100644 (file)
@@ -182,6 +182,7 @@ tokens {
     OBJECT_VAR_DECLARATION;
     VAR_DECLARATOR;
     VAR_DECLARATOR_LIST;
+    ARROW;
 }
 
 @header {
@@ -211,7 +212,7 @@ compilationUnit
     ;
 
 packageDeclaration
-    :   PACKAGE IDENT ('.' IDENT)+ ';'  
+    :   PACKAGE IDENT (DOT IDENT)+ ';'  
         ->  ^(PACKAGE IDENT+)
     ;
 
@@ -417,7 +418,7 @@ objectType
     ;
 
 qualifiedTypeIdent
-    :   typeIdent ('.' typeIdent)*
+    :   typeIdent (DOT typeIdent)*
         ->  ^(QUALIFIED_TYPE_IDENT typeIdent+) 
     ;
 
@@ -478,8 +479,8 @@ qualifiedIdentifier
     :   (   IDENT
             ->  IDENT
         )
-        (   '.' ident=IDENT
-            ->  ^('.' $qualifiedIdentifier $ident)
+        (   DOT ident=IDENT
+            ->  ^(DOT $qualifiedIdentifier $ident)
         )*
     ;
 
@@ -772,12 +773,12 @@ qualifiedIdentExpression
         // And now comes the stuff that may follow the qualified identifier.
         (   arguments
             ->  ^(METHOD_CALL qualifiedIdentifier arguments)
-        |   outerDot='.'
+        |   outerDot=DOT
             (   genericTypeArgumentList 
                 (   s=SUPER arguments
                     ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"]
                             qualifiedIdentifier genericTypeArgumentList arguments)
-                |   SUPER innerDot='.' IDENT arguments
+                |   SUPER innerDot=DOT IDENT arguments
                     ->  ^(METHOD_CALL ^($innerDot ^($outerDot qualifiedIdentifier SUPER) IDENT)
                             genericTypeArgumentList arguments)
                 |   IDENT arguments
@@ -844,11 +845,11 @@ INTEGER_TYPE_SUFFIX : ('l'|'L') ;
 FLOATING_POINT_LITERAL
     :   ('0'..'9')+ 
         (
-            '.' ('0'..'9')* EXPONENT? FLOAT_TYPE_SUFFIX?
+            DOT ('0'..'9')* EXPONENT? FLOAT_TYPE_SUFFIX?
         |   EXPONENT FLOAT_TYPE_SUFFIX?
         |   FLOAT_TYPE_SUFFIX
         )
-    |   '.' ('0'..'9')+ EXPONENT? FLOAT_TYPE_SUFFIX?
+    |   DOT ('0'..'9')+ EXPONENT? FLOAT_TYPE_SUFFIX?
     ;
 
 fragment
index 484cb4816a621603c026861a410cce837b4a5b7e..9df04002c6b29dc5e52cc89758db04a9f2fc029c 100644 (file)
@@ -221,10 +221,10 @@ formalParameterVarargDecl
     ;
     
 // FIXME: is this rule right? Verify that this is ok, I expected something like:
-// IDENT (^('.' qualifiedIdentifier IDENT))*
+// IDENT (^(DOT qualifiedIdentifier IDENT))*
 qualifiedIdentifier
     :   IDENT
-    |   ^('.' qualifiedIdentifier IDENT)
+    |   ^(DOT qualifiedIdentifier IDENT)
     ;
     
 block
@@ -346,6 +346,11 @@ primaryExpression
                 |   SUPER
                 )
         )
+        ->   ^(ARROW primaryExpression
+                   IDENT?
+                   THIS?
+                   SUPER?
+             )
     |   parenthesizedExpression
     |   IDENT
     |   ^(METHOD_CALL primaryExpression genericTypeArgumentList? arguments)
index 06643f6e3eeea0a148463d5ca75dcbe7f2875181..edb5a52ca173dc3d861b77c49b2fcf4c4a88305e 100644 (file)
@@ -446,7 +446,7 @@ formalParameterVarargDecl
 qualifiedIdentifier
     :   IDENT
         -> template(t={$text}) "<t>"
-    |   ^('.' qualifiedIdentifier IDENT)
+    |   ^(DOT qualifiedIdentifier IDENT)
         -> template(t={$text}) "<t>"
     ;
     
@@ -640,6 +640,12 @@ expr
 
 primaryExpression
     :   ^(DOT prim=primaryExpression
+            ( IDENT   -> template(id={$IDENT}, prim={$prim.st}) "<prim>.<id>"
+            | THIS    -> template(prim={$prim.st}) "<prim>.this"
+            | SUPER   -> template(prim={$prim.st}) "<prim>.super"
+            )
+        )
+    |   ^(ARROW prim=primaryExpression
             ( IDENT   -> template(id={$IDENT}, prim={$prim.st}) "<prim>-><id>"
             | THIS    -> template(prim={$prim.st}) "<prim>->this"
             | SUPER   -> template(prim={$prim.st}) "<prim>->super"
index 6cb869742ce965698eacbb5793beddaad4ef9c1f..bbdba00abcc8666703b99c35c666030efb26a566 100644 (file)
@@ -98,7 +98,7 @@ packageDeclaration
     :   ^(PACKAGE (ids+=IDENT)+)  
         {
             String packageName = "";
-            for(Object o : $ids) packageName += '.' + ((CharjAST)o).getText();
+            for(Object o : $ids) packageName += DOT + ((CharjAST)o).getText();
             packageName = packageName.substring(1);
             PackageScope ps = symtab.resolvePackage(packageName);
             if (ps == null) {
@@ -306,10 +306,10 @@ formalParameterVarargDecl
     ;
     
 // FIXME: is this rule right? Verify that this is ok, I expected something like:
-// IDENT (^('.' qualifiedIdentifier IDENT))*
+// IDENT (^(DOT qualifiedIdentifier IDENT))*
 qualifiedIdentifier
     :   IDENT
-    |   ^('.' qualifiedIdentifier IDENT)
+    |   ^(DOT qualifiedIdentifier IDENT)
     ;
     
 block
@@ -425,7 +425,13 @@ expr
     ;
     
 primaryExpression
-    :   ^(  DOT primaryExpression
+    :   ^(DOT primaryExpression
+                (   IDENT
+                |   THIS
+                |   SUPER
+                )
+        )
+    |   ^(ARROW primaryExpression
                 (   IDENT
                 |   THIS
                 |   SUPER
index fac6454a39fa9aecf76aa154f7200b72e9be1b78..1e94f812069a3f7d8cc8d4cbdefaa3e3768a14bc 100644 (file)
@@ -71,6 +71,8 @@ class PupRoutineCreator
                     type = p.getChild(0).getType();
                     break;
                 case CharjParser.FUNCTION_METHOD_DECL:
+                case CharjParser.BLOCK:
+                case CharjParser.FORMAL_PARAM_LIST:
                     System.out.println("local var, not puping...");
                     return;
                 case CharjParser.TYPE:
@@ -84,11 +86,14 @@ class PupRoutineCreator
                         case CharjParser.POINTER_TYPE: System.out.println("found pointer");
                             pointerVarPup(idNode);
                             break;
+                        default:
+                            System.out.println("unknown type -- THIS IS AN ERROR in method varPup, in PupRoutineCreator.java");
+                            break;
                     }
                     return;
             }
         }
-        System.out.println("after for");
+        System.out.println("THIS IS AN ERROR in method varPup, in PupRoutineCreator.java");
     }
 
     protected void primitiveVarPup(CharjAST idNode)
@@ -109,7 +114,7 @@ class PupRoutineCreator
         int index = pupNode.getChild(4).getChildren().size() - 1;
 
         pupNode.getChild(4).getChild(index).addChild(createNode(CharjParser.METHOD_CALL, "METHOD_CALL"));
-        pupNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.DOT, "."));
+        pupNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.ARROW, "ARROW"));
         pupNode.getChild(4).getChild(index).getChild(0).getChild(0).addChild(idNode.dupNode());
         pupNode.getChild(4).getChild(index).getChild(0).getChild(0).addChild(createNode(CharjParser.IDENT, "pup"));
         pupNode.getChild(4).getChild(index).getChild(0).addChild(createNode(CharjParser.ARGUMENT_LIST, "ARGUMENT_LIST"));