Merged arrays into Charj mainline.
authorJonathan Lifflander <jliffl2@illinois.edu>
Mon, 14 Jun 2010 15:44:45 +0000 (10:44 -0500)
committerJonathan Lifflander <jliffl2@illinois.edu>
Mon, 14 Jun 2010 15:44:45 +0000 (10:44 -0500)
1  2 
src/langs/charj/src/charj/translator/Charj.g
src/langs/charj/src/charj/translator/Charj.stg
src/langs/charj/src/charj/translator/CharjEmitter.g
src/langs/charj/src/charj/translator/CharjSemantics.g
src/langs/charj/src/charj/translator/ClassSymbol.java
src/langs/charj/src/charj/translator/Translator.java

index 8bd1ba11c9705a7f5f03ce5bc085907e8e231752,45a7e930992cdcc3bfd1083f6cd49cbde62746fa..94e671962dcc279bec1f9f866ce21ac51745ff53
@@@ -181,25 -79,25 +182,28 @@@ tokens 
      INTERFACE_TOP_LEVEL_SCOPE;
      IMPLEMENTS_CLAUSE;
      LABELED_STATEMENT;
 -    LOCAL_MODIFIER_LIST;
      CHARJ_SOURCE;
      METHOD_CALL;
 +    ENTRY_METHOD_CALL;
      MODIFIER_LIST;
+     NEW_EXPRESSION;
      PAREN_EXPR;
      POST_DEC;
      POST_INC;
      PRE_DEC;
      PRE_INC;
      QUALIFIED_TYPE_IDENT;
+     RANGE_EXPRESSION;
      STATIC_ARRAY_CREATOR;
      SUPER_CONSTRUCTOR_CALL;
+     TEMPLATE_INST;
      THIS_CONSTRUCTOR_CALL;
      TYPE;
 -    UNARY_MINUS;
 -    UNARY_PLUS;
 +    SIMPLE_TYPE;
 +    OBJECT_TYPE;
 +    REFERENCE_TYPE;
 +    POINTER_TYPE;
 +    PROXY_TYPE;
      PRIMITIVE_VAR_DECLARATION;
      OBJECT_VAR_DECLARATION;
      VAR_DECLARATOR;
@@@ -260,13 -145,23 +265,21 @@@ typeDeclaratio
      |   interfaceDefinition
      |   enumDefinition
      |   chareDefinition
 -    |   chareArrayDefinition
      ;
  
+ templateList
+     : 'class'! IDENT (','! 'class'! IDENT)*
+     ;
+ templateDeclaration
+     : 'template' '<' templateList '>' classDefinition
+         -> ^('template' templateList classDefinition)
+     ;
  classDefinition
 -    : 'public'? 'class' IDENT ('extends' type)? ('implements' typeList)? '{'
 -            classScopeDeclaration*
 -        '}' ';'?
 -        -> ^('class' IDENT ^('extends' type)? ^('implements' typeList)? classScopeDeclaration*)
 +    :   PUBLIC? CLASS IDENT (EXTENDS type)? ('implements' typeList)? '{'
-             classScopeDeclaration*
-         '}' ';'?
++      classScopeDeclaration* '}' ';'?
 +        -> ^(TYPE CLASS IDENT ^(EXTENDS type)? ^('implements' typeList)? classScopeDeclaration*)
      ;
  
  chareType
@@@ -313,9 -213,11 +326,11 @@@ typeLis
  classScopeDeclaration
      :   modifierList?
          (   genericTypeParameterList?
-             (   type IDENT formalParameterList arrayDeclaratorList? (block | ';')
+             (   type IDENT formalParameterList (block | ';')
                  ->  ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? type IDENT
-                     formalParameterList arrayDeclaratorList? block?)
+                     formalParameterList block?)
 -            |   'void' IDENT formalParameterList (block | ';')
 -                ->  ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList block?)
++            /*|   'void' IDENT formalParameterList (block | ';')
++                ->  ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList block?)*/
              |   ident=IDENT formalParameterList block
                  ->  ^(CONSTRUCTOR_DECL[$ident, "CONSTRUCTOR_DECL"] modifierList? genericTypeParameterList? IDENT
                          formalParameterList block)
  interfaceScopeDeclaration
      :   modifierList?
          (   genericTypeParameterList?
-             (   type IDENT formalParameterList arrayDeclaratorList? ';'
+             (   type IDENT formalParameterList ';'
                  ->  ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList?
-                         type IDENT formalParameterList arrayDeclaratorList?)
+                         type IDENT formalParameterList)
 -            |   'void' IDENT formalParameterList ';'
 -                ->  ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList)
++            /*|   'void' IDENT formalParameterList ';'
++                ->  ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList)*/
              )
          |   simpleType interfaceFieldDeclaratorList ';'
              ->  ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType interfaceFieldDeclaratorList)
@@@ -363,15 -267,15 +380,15 @@@ interfaceFieldDeclarato
  
  
  variableDeclaratorId
-     :   IDENT^ arrayDeclaratorList?
 -    :   IDENT^ domainExpression?
++    :   ^(IDENT domainExpression?)
      ;
  
  variableInitializer
      :   arrayInitializer
 -    |   newExpression
 +    |   expression
      ;
  
- arrayDeclarator
/*arrayDeclarator
      :   '[' ']'
          ->  ARRAY_DECLARATOR
      ;
@@@ -439,27 -359,16 +472,27 @@@ localModifie
  type
      :   simpleType
      |   objectType
-     :   qualifiedTypeIdent AT arrayDeclaratorList?
-         ->  ^(PROXY_TYPE qualifiedTypeIdent arrayDeclaratorList?)
-     |   qualifiedTypeIdent arrayDeclaratorList?
-         ->  ^(OBJECT_TYPE qualifiedTypeIdent arrayDeclaratorList?)
 +    |   VOID
 +    ;
 +
 +constructorType
++    :   qualifiedTypeIdent AT domainExpression?
++        ->  ^(PROXY_TYPE qualifiedTypeIdent domainExpression?)
++    |   qualifiedTypeIdent domainExpression?
++        ->  ^(OBJECT_TYPE qualifiedTypeIdent domainExpression?)
      ;
  
 +
  simpleType
-     :   primitiveType arrayDeclaratorList?
-         ->  ^(SIMPLE_TYPE primitiveType arrayDeclaratorList?)  
+     :   primitiveType domainExpression?
 -        ->  ^(TYPE primitiveType domainExpression?)  
++        ->  ^(SIMPLE_TYPE primitiveType domainExpression?)  
      ;
  
  objectType
-     :   qualifiedTypeIdent AT arrayDeclaratorList?
-         ->  ^(PROXY_TYPE qualifiedTypeIdent arrayDeclaratorList?)
-     |   qualifiedTypeIdent arrayDeclaratorList?
-         ->  ^(POINTER_TYPE qualifiedTypeIdent arrayDeclaratorList?)
 -    :   qualifiedTypeIdent domainExpression?
 -        ->  ^(TYPE qualifiedTypeIdent domainExpression?)
++    :   qualifiedTypeIdent AT domainExpression?
++        ->  ^(PROXY_TYPE qualifiedTypeIdent domainExpression?)
++    |   qualifiedTypeIdent domainExpression?
++        ->  ^(POINTER_TYPE qualifiedTypeIdent domainExpression?)
      ;
  
  qualifiedTypeIdent
@@@ -472,20 -381,20 +505,20 @@@ typeIden
      ;
  
  primitiveType
 -    :   'boolean'
 -    |   'char'
 -    |   'byte'
 -    |   'short'
 -    |   'int'
 -    |   'long'
 -    |   'float'
 -    |   'double'
 +    :   BOOLEAN
 +    |   CHAR
 +    |   BYTE
 +    |   SHORT
 +    |   INT
 +    |   LONG
 +    |   FLOAT
 +    |   DOUBLE
      ;
  
- genericTypeArgumentList
/*genericTypeArgumentList
      :   lt='<' genericTypeArgument (',' genericTypeArgument)* genericTypeListClosing
          ->  ^(GENERIC_TYPE_ARG_LIST[$lt, "GENERIC_TYPE_ARG_LIST"] genericTypeArgument+)
-     ;
+     ;*/
  
  genericTypeArgument
      :   type
@@@ -754,31 -669,29 +810,30 @@@ postfixedExpressio
      :   (   primaryExpression
              ->  primaryExpression
          )
--        // ... and than the optional things that may follow a primary
--        // expression 0 or more times.
 -        (   outerDot='.'                 
++        // ... and than the optional things that may follow a primary expression 0 or more times.
 +        (   outerDot=DOT                 
              // Note: generic type arguments are only valid for method calls,
              // i.e. if there is an argument list
-             (   (   genericTypeArgumentList?  
+             (   (   templateInstantiation?  
                      IDENT
                      ->  ^($outerDot $postfixedExpression IDENT)
                  ) 
                  (   arguments
-                     ->  ^(METHOD_CALL $postfixedExpression genericTypeArgumentList? arguments)
+                     ->  ^(METHOD_CALL $postfixedExpression templateInstantiation? arguments)
                  )?
 -            |   'this'
 -                ->  ^($outerDot $postfixedExpression 'this')
 -            |   s='super' arguments
 +            |   THIS
 +                ->  ^($outerDot $postfixedExpression THIS)
 +            |   s=SUPER arguments
                  ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"] $postfixedExpression arguments)
 -            |   (   'super' innerDot='.' IDENT
 -                    ->  ^($innerDot ^($outerDot $postfixedExpression 'super') IDENT)
 +            |   (   SUPER innerDot=DOT IDENT
 +                    ->  ^($innerDot ^($outerDot $postfixedExpression SUPER) IDENT)
                  )
                  (   arguments
                      ->  ^(METHOD_CALL $postfixedExpression arguments)
                  )?
              )
-         |   (AT genericTypeArgumentList? IDENT arguments)
-             ->  ^(ENTRY_METHOD_CALL ^(AT $postfixedExpression IDENT) genericTypeArgumentList? arguments)
++        |   (AT templateInstantiation? IDENT arguments)
++            ->  ^(ENTRY_METHOD_CALL ^(AT $postfixedExpression IDENT) templateInstantiation? arguments)
          |   '[' expression ']'
              ->  ^(ARRAY_ELEMENT_ACCESS $postfixedExpression expression)
          )*
@@@ -793,20 -706,20 +848,20 @@@ primaryExpressio
      |   literal
      |   newExpression
      |   qualifiedIdentExpression
-     |   genericTypeArgumentList 
 -    |   templateInstantiation 
 -        (   s='super'
++    |   templateInstantiation
 +        (   s=SUPER
              (   arguments
-                 ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"] genericTypeArgumentList arguments)
+                 ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"] templateInstantiation arguments)
              |   IDENT arguments
-                 ->  ^(METHOD_CALL ^(DOT SUPER IDENT) genericTypeArgumentList arguments)
 -                ->  ^(METHOD_CALL ^('.' 'super' IDENT) templateInstantiation arguments)
++                ->  ^(METHOD_CALL ^(DOT SUPER IDENT) templateInstantiation arguments)
              )
          |   IDENT arguments
-             ->  ^(METHOD_CALL IDENT genericTypeArgumentList arguments)
+             ->  ^(METHOD_CALL IDENT templateInstantiation arguments)
 -        |   t='this' arguments
 +        |   t=THIS arguments
-             ->  ^(THIS_CONSTRUCTOR_CALL[$t, "THIS_CONSTRUCTOR_CALL"] genericTypeArgumentList arguments)
+             ->  ^(THIS_CONSTRUCTOR_CALL[$t, "THIS_CONSTRUCTOR_CALL"] templateInstantiation arguments)
          )
 -    |   (   'this'
 -            ->  'this'
 +    |   (   THIS
 +            ->  THIS
          )
          (   arguments
              ->  ^(THIS_CONSTRUCTOR_CALL[$t, "THIS_CONSTRUCTOR_CALL"] arguments)
@@@ -839,41 -742,34 +894,39 @@@ qualifiedIdentExpressio
          // And now comes the stuff that may follow the qualified identifier.
          (   arguments
              ->  ^(METHOD_CALL qualifiedIdentifier arguments)
 -        |   outerDot='.'
 -            (   templateInstantiation 
 -                (   s='super' arguments
 +        |   outerDot=DOT
-             (   genericTypeArgumentList 
++            (   templateInstantiation
 +                (   s=SUPER arguments
                      ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"]
-                             qualifiedIdentifier genericTypeArgumentList arguments)
+                             qualifiedIdentifier templateInstantiation arguments)
 -                |   'super' innerDot='.' IDENT arguments
 -                    ->  ^(METHOD_CALL ^($innerDot ^($outerDot qualifiedIdentifier 'super') IDENT)
 +                |   SUPER innerDot=DOT IDENT arguments
 +                    ->  ^(METHOD_CALL ^($innerDot ^($outerDot qualifiedIdentifier SUPER) IDENT)
-                             genericTypeArgumentList arguments)
+                             templateInstantiation arguments)
                  |   IDENT arguments
-                     ->  ^(METHOD_CALL ^($outerDot qualifiedIdentifier IDENT) genericTypeArgumentList arguments)
+                     ->  ^(METHOD_CALL ^($outerDot qualifiedIdentifier IDENT) templateInstantiation arguments)
                  )
 -            |   'this'
 -                ->  ^($outerDot qualifiedIdentifier 'this')
 -            |   s='super' arguments
 +            |   THIS
 +                ->  ^($outerDot qualifiedIdentifier THIS)
 +            |   s=SUPER arguments
                  ->  ^(SUPER_CONSTRUCTOR_CALL[$s, "SUPER_CONSTRUCTOR_CALL"] qualifiedIdentifier arguments)
              )
          )?
      ;
  
  newExpression
 -    :   'new' domainExpression arguments?
 -        ->  ^(NEW_EXPRESSION arguments? domainExpression)
 +    :   n=NEW
-         (   primitiveType newArrayConstruction          // new static array of primitive type elements
-             ->  ^(STATIC_ARRAY_CREATOR[$n, "STATIC_ARRAY_CREATOR"] primitiveType newArrayConstruction)
-         |   genericTypeArgumentList? qualifiedTypeIdent
-                 newArrayConstruction                // new static array of object type reference elements
-             ->  ^(STATIC_ARRAY_CREATOR[$n, "STATIC_ARRAY_CREATOR"] genericTypeArgumentList? qualifiedTypeIdent newArrayConstruction)
++        (
++            domainExpression arguments?
++            ->  ^(NEW_EXPRESSION arguments? domainExpression)
 +        |   constructorType arguments
 +            -> ^(NEW constructorType arguments)
 +        )
      ;
      
- newArrayConstruction
/*newArrayConstruction
      :   arrayDeclaratorList arrayInitializer
      |   '['! expression ']'! ('['! expression ']'!)* arrayDeclaratorList?
-     ;
+     ;*/
  
  arguments
      :   lp='(' expressionList? ')'
index 324f8775cf1dd3db75e55b95194fbe7c68f96977,5266339cadd25b072788c29248a1030685dcc6d0..25178534a77f0df1db66058d9d90dc70227d2432
@@@ -97,70 -80,64 +97,79 @@@ interfaceExtends(ts) ::
  : public <ts; separator=", public ">
  >>
  
 -classDeclaration_h(ident, ext, csds) ::=
 +type_preamble_h(sym) ::=
  <<
 -/* superclass: <ext> */
 -class <ident>: public CBase_<ident> {
 -    <csds; separator="\n">
 -};
 +<sym.Includes:{include| #include \<<include>\>
 +}>
 +<sym.Usings:{using| using <using>;
 +}>
 +<sym.MemberTypeNames:{name| class <name>;
 +}>
  >>
  
 -classWrapper_h(ident, ext, csds, class1) ::=
 +chare_preamble_h(sym) ::=
  <<
 -<if(debug)>/* \<typeDeclaration> */<endif>
 -
 -#include "<ident>.decl.h"
 -
 -<classDeclaration_h(ident=ident, ext=ext, csds=csds)>
 +<type_preamble_h(sym)>
 +>>
  
 -<if(debug)>/* \</typeDeclaration> */<endif>
 +type_epilogue_h(sym) ::=
 +<<
  >>
  
 -templateDeclaration_h(tident, ident, ext, csds) ::=
 +chare_epilogue_h(sym) ::=
  <<
 -#include "<ident>.decl.h"
 -template \<class <tident; separator=", class ">\>
 -<classDeclaration_h(ident=ident, ext=ext, csds=csds)>
 +<type_epilogue_h(sym)>
  >>
  
- classDeclaration_h(sym, ident, ext, csds) ::=
 -classDeclaration_cc(ident, ext, csds) ::=
++classDeclaration_h(sym, ident, ext, csds, tident) ::=
  <<
 -<if(debug)>/* \<typeDeclaration> */<endif>
 +<type_preamble_h(sym)>
++<if(tident)>
++<templateDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds, tident = tident)>
++<else>
 +<classDeclaration_h_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds)>
++<endif>
 +<type_epilogue_h(sym)>
 +>>
  
 +classDeclaration_h_cont(pds, sym, ident, ext, csds) ::=
 +<<
 +<if(first(pds))>namespace <first(pds)>
 +{
 +    <classDeclaration_h_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds)>
 +} // namespace <first(pds)>
 +<else>
 +<if(ext)>
 +class <ident> : public <ext> {
 +<else>
 +class <ident> {
 +<endif>
  
 -#include "<ident>.decl.h"
 -/* superclass: <ext> */
 -class <ident>: public CBase_<ident> {
 -    <csds; separator="\n">
 +    <csds; separator="\n\n">
  };
 -#include "<ident>.def.h"
 -<if(debug)>/* \</typeDeclaration> */<endif>
 +<endif>
 +>>
  
++templateDeclaration_h(pds, sym, ident, ext, csds, tident) ::=
++<<
++template \<class <tident; separator=", class ">\>
++<classDeclaration_h_cont(pds=pds, sym=sym, ident=ident, ext=ext, csds=csds)>
+ >>
  
 +classDeclaration_cc(sym, ident, ext, csds) ::=
 +<<
 +<classDeclaration_cc_cont(pds = sym.packageNames, sym = sym, ident = ident, ext = ext, csds = csds)>
 +>>
  
 -charedeclaration_ci(chareType, arrayDim, ident, ext, csds) ::=
 +classDeclaration_cc_cont(pds, sym, ident, ext, csds) ::=
  <<
 -<if(debug)>/* \<typeDeclaration> */<endif>
 -module <ident> {
 -<if(ext)>
 -    extern module <ext>;
 -    <chareType><if(arrayDim)> [<arrayDim>]<endif> <ident>: <ext> {
 +<if(first(pds))>namespace <first(pds)>
 +{
 +    <classDeclaration_cc_cont(pds = rest(pds), sym = sym, ident = ident, ext = ext, csds = csds)>
 +} // namespace <first(pds)>
  <else>
 -    <chareType><if(arrayDim)> [<arrayDim>]<endif> <ident> {
 +<csds; separator="\n\n">
  <endif>
 -        <csds; separator="\n">
 -    }
 -}
 -
 -<if(debug)>/* \</typeDeclaration> */<endif>
 -
  >>
  
  
@@@ -301,19 -237,10 +310,19 @@@ var_decl_cc(id, initializer) ::
  <id><if(initializer)> = <initializer><endif>
  >>
  
 +var_decl_h(id, initializer) ::=
 +<<
 +<id>
 +>>
 +
 +var_decl_ci(id, initializer) ::=
 +<<
 +<id><if(initializer)> = <initializer><endif>
 +>>
  
- var_decl_id(id, array_decl_list) ::=
+ var_decl_id(id, domainExp) ::=
  <<
- <id><if(array_decl_list)> <array_decl_list><endif>
+ <id><if(domainExp)>(<domainExp>)<endif>
  >>
  
  
@@@ -323,28 -250,25 +332,29 @@@ var_id_decl(id, adl) ::
  >>
  
  
 -mod_list(mods) ::=
 +mod_list_cc(accmods, localmods, charjmods, othermods) ::=
  <<
 -<if(mods)><mods; separator=" "><endif>
 +<if(localmods)><localmods; separator=" "> <endif><if(othermods)><othermods; separator=" "> <endif>
  >>
  
 +mod_list_h(accmods, localmods, charjmods, othermods) ::=
 +<<
 +<if(accmods)><accmods; separator=" ">: <endif><if(othermods)><othermods; separator=" "> <endif>
 +>>
  
 -local_mod_list(mods) ::=
 +mod_list_ci(accmods, localmods, charjmods, othermods) ::=
  <<
 -<if(mods)><mods; separator=" "><endif>
 +<if(charjmods)><charjmods; separator=" "> <endif>
  >>
 - 
  
- local_var_decl(modList, type, declList) ::=
+ local_var_decl(modList, type, declList, domainExps) ::=
  <<
 -<if(modList)>
 -<modList> <type> <declList>
 -<else>
 -<type> <declList>;
 -<endif>
 +<if(modList)><modList> <endif><type> <declList>;
 +>>
 +
- local_mod_list(mods) ::= <<
++local_mod_list(mods) ::= 
++<<
 +<mods; separator=" ">
  >>
  
  
@@@ -484,23 -407,10 +494,30 @@@ arguments(exprs) ::
  <exprs; separator=", ">
  >>
  
 ->>
 +print(exprs) ::=
 +<<
 +<if(first(exprs))>cout <exprs : { n | \<\< <n> }>;<endif>
 +>>
 +
 +println(exprs) ::=
 +<<
 +cout<if(first(exprs))> <exprs : { n | \<\< <n> }><else> <endif>\<\< endl;
 +>>
 +
 +exit(expr) ::=
 +<<
 +<if(expr)>exit(<expr>)<else>exit(0)<endif>;
 +>>
 +
 +exitall() ::=
 +<<
 +CkExit();
 +>>
 +
+ range_constructor(range, others, len) ::=
+ <<
+ <if(range)>
+ Domain\<<len>\>(<range>)<if(others)>, <others; separator=", "><endif>
+ <else>
+ <endif>
++>>
index 8de9fc6d6c8aff8bbd6ae133683e750139e75d82,0406c7033abf669d14f648d9993cfb5722145b58..e680c7d00a36ae5c2f8cd93e2393e64c128344d4
@@@ -148,17 -153,12 +148,24 @@@ typeDeclaratio
                  ext={$su.st}, 
                  csds={$csds})
          ->
 -    |   ^('interface' IDENT (^('extends' type+))? interfaceScopeDeclaration*)
++    |   ^('template' (i0+=IDENT*) ^('class' i1=IDENT (^('extends' su=type))? (^('implements' type+))? (csds+=classScopeDeclaration)*))
++        -> {emitH()}? templateDeclaration_h(
++            tident={$i0},
++            ident={$i1.text},
++            ext={$su.st},
++            csds={$csds})
++        -> 
 +    |   ^(INTERFACE IDENT (^('extends' type+))? interfaceScopeDeclaration*)
          -> template(t={$text}) "/*INTERFACE-not implemented*/ <t>"
 -    |   ^('enum' IDENT (^('implements' type+))? classScopeDeclaration*)
 +    |   ^(ENUM IDENT (^('implements' type+))? classScopeDeclaration*)
          -> template(t={$text}) "/*ENUM-not implemented*/ <t>"
 -    |   ^(chareType IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
 -        -> {emitCC()}? classDeclaration_cc(
 +    |   ^(TYPE chareType IDENT (^('extends' type))? (^('implements' type+))?
 +        {
 +            currentClass = (ClassSymbol)$IDENT.symbol;
 +        }
 +        (csds+=classScopeDeclaration)*)
 +        -> {emitCC()}? chareDeclaration_cc(
 +                sym={currentClass},
                  ident={$IDENT.text}, 
                  ext={$su.st}, 
                  csds={$csds})
@@@ -195,53 -198,78 +202,50 @@@ enumConstan
      ;
  
  classScopeDeclaration
 -@init { boolean entry = false; }
 +@init
 +{
 +    boolean entry = false;
 +    boolean migrationCtor = false;
 +}
      :   ^(FUNCTION_METHOD_DECL m=modifierList? g=genericTypeParameterList? 
-             ty=type IDENT f=formalParameterList a=arrayDeclaratorList? 
+             ty=type IDENT f=formalParameterList
              b=block?)
 -        { 
 -            if ($m.st != null) {
 -                // determine whether this is an entry method
 -                entry = listContainsToken($m.start.getChildren(), ENTRY);
 -            }
 +        {
 +            // determine whether it's an entry method
 +            if($m.start != null)
 +                entry = listContainsToken($m.start.getChildren(), CHARJ_MODIFIER_LIST);
          }
          -> {emitCC()}? funcMethodDecl_cc(
 +                sym={currentClass},
                  modl={$m.st}, 
                  gtpl={$g.st}, 
 -                ty={$ty.text},
 +                ty={$ty.st},
                  id={$IDENT.text}, 
                  fpl={$f.st}, 
-                 adl={$a.st},
                  block={$b.st})
          -> {emitH()}? funcMethodDecl_h(
                  modl={$m.st}, 
                  gtpl={$g.st}, 
 -                ty={$ty.text},
 +                ty={$ty.st},
                  id={$IDENT.text}, 
                  fpl={$f.st}, 
-                 adl={$a.st},
                  block={$b.st})
          -> {(emitCI() && entry)}? funcMethodDecl_ci(
                  modl={$m.st}, 
                  gtpl={$g.st}, 
 -                ty={$ty.text},
 -                id={$IDENT.text}, 
 -                fpl={$f.st}, 
 -                block={$b.st})
 -        ->
 -    |   ^(VOID_METHOD_DECL m=modifierList? g=genericTypeParameterList? IDENT 
 -            f=formalParameterList b=block?)
 -        { 
 -            // determine whether this is an entry method
 -            if ($m.st != null) {
 -                entry = listContainsToken($m.start.getChildren(), ENTRY);
 -            }
 -        }
 -        -> {emitCC()}? voidMethodDecl_cc(
 -                modl={$m.st}, 
 -                gtpl={$g.st}, 
 -                id={$IDENT.text}, 
 -                fpl={$f.st}, 
 -                block={$b.st})
 -        -> {emitCI() && entry}? voidMethodDecl_ci(
 -                modl={$m.st}, 
 -                gtpl={$g.st}, 
 -                id={$IDENT.text}, 
 -                fpl={$f.st}, 
 -                block={$b.st})
 -        -> {emitH()}? voidMethodDecl_h(
 -                modl={$m.st}, 
 -                gtpl={$g.st}, 
 +                ty={$ty.st},
                  id={$IDENT.text}, 
                  fpl={$f.st}, 
-                 adl={$a.st},
                  block={$b.st})
          ->
-     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
-         -> {emitH()}? class_var_decl(
+     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList[null, false])
+         -> {emitCC() || emitH()}? class_var_decl(
              modl={$modifierList.st},
              type={$simpleType.st},
              declList={$variableDeclaratorList.st})
          ->
-     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList)
-         -> {emitH()}? class_var_decl(
+     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList[$objectType.st, false])
 -        /*{
 -            if ($currentClass != null) {
 -                $currentClass.members.put(
 -            }
 -        }*/
+         -> {emitCC() || emitH()}? class_var_decl(
              modl={$modifierList.st},
              type={$objectType.st},
              declList={$variableDeclaratorList.st})
      ;
      
  interfaceScopeDeclaration
-     :   ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? type IDENT formalParameterList arrayDeclaratorList?)
+     :   ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? type IDENT formalParameterList)
          -> template(t={$text}) "/*interfaceScopeDeclarations-not implemented */ <t>"
-     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
 -    |   ^(VOID_METHOD_DECL modifierList? genericTypeParameterList? IDENT formalParameterList)
 -        -> template(t={$text}) "/*interfaceScopeDeclarations-not implemented */ <t>"
+     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList[$simpleType.st, false])
          -> template(t={$text}) "/*interfaceScopeDeclarations-not implemented */ <t>"
-     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList)
+     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList[$objectType.st, false])
          -> template(t={$text}) "/*interfaceScopeDeclarations-not implemented */ <t>"
      ;
  
@@@ -289,33 -318,59 +293,65 @@@ variableDeclaratorList[StringTemplate o
          -> var_decl_list(var_decls={$var_decls})
      ;
  
- variableDeclarator
-     :   ^(VAR_DECLARATOR id=variableDeclaratorId initializer=variableInitializer?)
-         -> {emitCC()}? var_decl_cc(id={$id.st}, initializer={$initializer.st})
-         -> {emitH()}?  var_decl_h(id={$id.st}, initializer={$initializer.st})
-         -> {emitCI()}? var_decl_ci(id={$id.st}, initializer={$initializer.st})
+ variableDeclarator[StringTemplate obtype, boolean output]
+     :   ^(VAR_DECLARATOR id=variableDeclaratorId[output] initializer=variableInitializer[obtype, output]?)
 -        -> {$output}? var_decl(id={$id.st}, initializer={$initializer.st})
 -        -> {!$output}? var_decl(id={$id.st})
++        -> {$output && emitCC()}? var_decl_cc(id={$id.st}, initializer={$initializer.st})
++        -> {$output && emitH()}?  var_decl_h(id={$id.st}, initializer={$initializer.st})
++        -> {$output && emitCI()}? var_decl_ci(id={$id.st}, initializer={$initializer.st})
++        -> {!$output && emitCC()}? var_decl_cc(id={$id.st})
++        -> {!$output && emitH()}?  var_decl_h(id={$id.st})
++        -> {!$output && emitCI()}? var_decl_ci(id={$id.st})
          ->
 -    ;
 +    ; 
      
- variableDeclaratorId
-     :   ^(IDENT adl=arrayDeclaratorList?)
-         -> var_decl_id(id={$IDENT.text}, arrayDeclList={$adl.st})
+ variableDeclaratorId[boolean output]
+     :   ^(IDENT de=domainExpression[null]?)
+         -> {$output}? var_decl_id(id={$IDENT.text}, domainExp={$de.st})
+         -> {!$output}? var_decl_id(id={$IDENT.text})
+         ->
      ;
  
- variableInitializer
+ variableInitializer[StringTemplate obtype, boolean output]
      :   arrayInitializer
          -> {$arrayInitializer.st}
+     |   newExpression[obtype, output]
+         -> {$newExpression.st}
 +    |   expression
 +        -> {$expression.st}
      ;
  
- arrayDeclaratorList
+ rangeItem
+     :   dl=DECIMAL_LITERAL
+         -> template(t={$dl.text}) "<t>"
+     |   IDENT
+         -> template(t={$IDENT.text}) "<t>"
+     ;
+ rangeExpression
+     :   ^(RANGE_EXPRESSION (ri+=rangeItem)*)
+         -> template(t={$ri}) "Range(<t; separator=\",\">)"
+     ;
+ rangeList returns [int len]
+     :   (r+=rangeExpression)*
+         { $len = $r.size(); }
+         -> template(t={$r}) "<t; separator=\", \">"
+         
+     ;
+ domainExpression[List<StringTemplate> otherParams]
+     :   ^(DOMAIN_EXPRESSION rl=rangeList)
+         -> range_constructor(range={$rl.st}, others={$otherParams}, len={$rl.len})
+     ;
+ /*arrayDeclaratorList
      :   ^(ARRAY_DECLARATOR_LIST ARRAY_DECLARATOR*)  
          -> template(t={$text}) "<t>"
-     ;
+     ;*/
      
  arrayInitializer
-     :   ^(ARRAY_INITIALIZER variableInitializer*)
+     :   ^(ARRAY_INITIALIZER variableInitializer[null, false]*)
          -> template(t={$text}) "/* arrayInitializer-not implemented */ <t>"
      ;
  
@@@ -435,33 -436,18 +471,33 @@@ typ
      ;
  
  simpleType
-     :   ^(SIMPLE_TYPE primitiveType arrayDeclaratorList?)
-         -> simple_type(typeID={$primitiveType.st}, arrDeclList={$arrayDeclaratorList.st})
 -    :   ^(TYPE primitiveType domainExpression[null]?)
 -        -> type(typeID={$primitiveType.st}, arrDeclList={$domainExpression.st})
++    :   ^(SIMPLE_TYPE primitiveType domainExpression[null]?)
++        -> simple_type(typeID={$primitiveType.st}, arrDeclList={$domainExpression.st})
      ;
  
  objectType
 -    :   ^(TYPE qualifiedTypeIdent domainExpression[null]?)
 -        -> type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$domainExpression.st})
 +    : proxyType -> {$proxyType.st;}
 +    | nonProxyType -> {$nonProxyType.st}
 +    ;
 +
 +nonProxyType
-     :   ^(OBJECT_TYPE qualifiedTypeIdent arrayDeclaratorList?)
-         -> obj_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
-     |   ^(POINTER_TYPE qualifiedTypeIdent arrayDeclaratorList?)
-         -> pointer_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
-     |   ^(REFERENCE_TYPE qualifiedTypeIdent arrayDeclaratorList?)
-         -> reference_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
++    :   ^(OBJECT_TYPE qualifiedTypeIdent domainExpression[null]?)
++        -> obj_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$domainExpression.st})
++    |   ^(POINTER_TYPE qualifiedTypeIdent domainExpression[null]?)
++        -> pointer_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$domainExpression.st})
++    |   ^(REFERENCE_TYPE qualifiedTypeIdent domainExpression[null]?)
++        -> reference_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$domainExpression.st})
      ;
  
 -qualifiedTypeIdent
 -    :   ^(QUALIFIED_TYPE_IDENT (t+=typeIdent)+) 
 -        -> template(types={$t}) "<types; separator=\".\">"
 +proxyType
-     :   ^(PROXY_TYPE qualifiedTypeIdent arrayDeclaratorList?)
-         -> proxy_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$arrayDeclaratorList.st})
++    :   ^(PROXY_TYPE qualifiedTypeIdent domainExpression[null]?)
++        -> proxy_type(typeID={$qualifiedTypeIdent.st}, arrDeclList={$domainExpression.st})
 +    ;
 +
 +qualifiedTypeIdent returns [ClassSymbol type]
 +    :   ^(QUALIFIED_TYPE_IDENT (t+=typeIdent)+)
 +        {$type = (ClassSymbol)$QUALIFIED_TYPE_IDENT.symbol;}
 +        -> template(types={$t}) "<types; separator=\"::\">"
      ;
  
  typeIdent
@@@ -473,18 -459,37 +509,37 @@@ primitiveTyp
  @init {
  $st = %{$start.getText()};
  }
 -    :   'boolean'
 +    :   BOOLEAN
          -> template() "bool"
 -    |   'char'
 -    |   'byte'
 +    |   CHAR
 +    |   BYTE
          -> template() "char"
 -    |   'short'
 -    |   'int'
 -    |   'long'
 -    |   'float'
 -    |   'double'
 +    |   SHORT
 +    |   INT
 +    |   LONG
 +    |   FLOAT
 +    |   DOUBLE
      ;
  
+ templateArg
+     :   genericTypeArgument
+         -> {$genericTypeArgument.st}
+     |   literal
+         -> {$literal.st}
+     ;
+ templateArgList
+     :   params+=templateArg+
+         -> template(params={$params}) "<params; separator=\", \">"
+     ;
+ templateInstantiation
+     :   ^(TEMPLATE_INST templateArgList)
+         -> template(args={$templateArgList.st}) "\<<args>\>"
+     |   ^(TEMPLATE_INST ts=templateInstantiation)
+         -> template(inst={$ts.st}) "\<<inst>\>"
+     ;
  genericTypeArgumentList
      :   ^(GENERIC_TYPE_ARG_LIST (gta+=genericTypeArgument)+)
          -> template(gtal={$gta}) "\<<gtal; separator=\", \">\>"
@@@ -537,16 -542,16 +592,16 @@@ blockStatemen
  
  
  localVariableDeclaration
-     :   ^(PRIMITIVE_VAR_DECLARATION localModifierList? simpleType variableDeclaratorList)
+     :   ^(PRIMITIVE_VAR_DECLARATION localModifierList? simpleType vdl=variableDeclaratorList[null, true])
          -> local_var_decl(
 -            modList={null},
 +            modList={$localModifierList.st},
              type={$simpleType.st},
-             declList={$variableDeclaratorList.st})
-     |   ^(OBJECT_VAR_DECLARATION localModifierList? objectType variableDeclaratorList)
+             declList={$vdl.st})
+     |   ^(OBJECT_VAR_DECLARATION localModifierList? objectType vdl=variableDeclaratorList[$objectType.st, true])
          -> local_var_decl(
 -            modList={null},
 +            modList={$localModifierList.st},
              type={$objectType.st},
-             declList={$variableDeclaratorList.st})
+             declList={$vdl.st})
      ;
  
  
@@@ -742,9 -726,9 +799,9 @@@ primaryExpressio
          -> template(pe={$pe.st}, ex={$ex.st}) "<pe>[<ex>]"
      |   literal
          -> {$literal.st}
-     |   newExpression
+     |   newExpression[null, false]
          -> {$newExpression.st}
 -    |   'this'
 +    |   THIS
          -> {%{$start.getText()}}
      |   arrayTypeDeclarator
          -> {$arrayTypeDeclarator.st}
@@@ -775,20 -748,23 +832,31 @@@ arrayTypeDeclarato
          -> template(t={$text}) "<t>"
      ;
  
- newExpression
+ newExpression[StringTemplate obtype, boolean output] returns [StringTemplate initArray]
+     :   ^(NEW_EXPRESSION arguments? domainExpression[$arguments.args])
+         -> {$output}? template(domain={$domainExpression.st},type={$obtype}) "new <type>(<domain>)"
+         -> {!$output}? template() ""
+         ->
++    |   ^(NEW proxyType arguments)
++        -> template(t={$proxyType.st}, a={$arguments.st}) "<t>::ckNew(<a>)"
++    |   ^(NEW nonProxyType arguments)
++        -> template(q={$nonProxyType.st}, a={$arguments.st}) "new <q>(<a>)"
+     ;
+ /*newExpression
      :   ^(  STATIC_ARRAY_CREATOR
              (   primitiveType newArrayConstruction
              |   genericTypeArgumentList? qualifiedTypeIdent newArrayConstruction
              )
          )
          -> template(t={$text}) "<t>"
 +    |   ^(NEW proxyType arguments)
 +        -> template(t={$proxyType.st}, a={$arguments.st}) "<t>::ckNew(<a>)"
 +    |   ^(NEW nonProxyType arguments)
 +        -> template(q={$nonProxyType.st}, a={$arguments.st}) "new <q>(<a>)"
      ;
- newArrayConstruction
+ */
/*newArrayConstruction
      :   arrayDeclaratorList arrayInitializer
          -> array_construction_with_init(
                  array_decls={$arrayDeclaratorList.st},
index e7d3fcf92581f901dec23725412ac5b11b390d50,50810c78ef4962a155aaaf814020cc25103fa28d..c9ff0cbcf12115af89258e96232bb34d5a713fde
@@@ -113,58 -107,40 +113,63 @@@ packageDeclaratio
          }
      ;
      
 -importDeclarations returns [List<CharjAST> packageNames]
 -@init {
 -      packageNames = new ArrayList<CharjAST>();
 -}
 -    :   (^('import' qualifiedIdentifier './*'?)
 -              { packageNames.add($qualifiedIdentifier.start); })*
 +importDeclaration
 +    :   ^(IMPORT qualifiedIdentifier '.*'?)
 +        { addImport($qualifiedIdentifier.start); }
      ;
  
 +readonlyDeclaration
 +    :   ^(READONLY localVariableDeclaration)
 +    ;
  
 -typeDeclaration[List<CharjAST> imports] returns [ClassSymbol sym]
 +typeDeclaration returns [ClassSymbol sym]
  scope ScopeStack; // top-level type scope
 -    :   ^('template' i1=IDENT* typeDeclaration[$imports])
 +    :   ^(TYPE classType IDENT
 +            (^('extends' parent=type))? (^('implements' type+))?
 +            {
 +                Scope outerScope = $ScopeStack[-1]::current;
 +                $sym = new ClassSymbol(symtab, $IDENT.text, outerScope.resolveType($parent.text), outerScope);
 +                outerScope.define($sym.name, $sym);
 +                currentClass = $sym;
 +                $sym.definition = $typeDeclaration.start;
 +                $sym.definitionTokenStream = input.getTokenStream();
 +                $IDENT.symbol = $sym;
 +                $ScopeStack::current = $sym;
 +                String classTypeName = $classType.text;
 +                if (classTypeName.equals("class")) {
 +                } else if (classTypeName.equals("chare")) {
 +                    currentClass.isChare = true;
 +                } else if (classTypeName.equals("group")) {
 +                    currentClass.isChare = true;
 +                } else if (classTypeName.equals("nodegroup")) {
 +                    currentClass.isChare = true;
 +                } else if (classTypeName.equals("chare_array")) {
 +                    currentClass.isChare = true;
 +                } else if (classTypeName.equals("mainchare")) {
 +                    currentClass.isChare = true;
 +                    currentClass.isMainChare = true;
 +                } else System.out.println("Error: type " + classTypeName + " not recognized.");
 +                importPackages($sym, imports);
 +            }
 +            classScopeDeclaration*)
 +            {
 +                //System.out.println("Members for type " + $sym.name + ":");
 +                //for (Map.Entry<String, Symbol> entry : $sym.members.entrySet()) {
 +                //    System.out.println(entry.getKey());
 +                //}
 +            }
++    |   ^('template' i1=IDENT* typeDeclaration)
+         {
+             // JL: Need to fill the templateArgs in ClassSymbol, and push this down
+             // to the class subtree
+         }
 -    |   ^('class' i2=IDENT (^('extends' type))? (^('implements' type+))? 
 -        {
 -            Scope outerScope = $ScopeStack[-1]::current;
 -            $sym = new ClassSymbol(symtab, $i2.text, null, outerScope);
 -            outerScope.define($sym.name, $sym);
 -            currentClass = $sym;
 -            $sym.definition = $typeDeclaration.start;
 -            $sym.definitionTokenStream = input.getTokenStream();
 -            $i2.symbol = $sym;
 -            $ScopeStack::current = $sym;
 -            importPackages($sym, $imports);
 -        }
 -            classScopeDeclaration*)
      |   ^('interface' IDENT (^('extends' type+))?  interfaceScopeDeclaration*)
      |   ^('enum' IDENT (^('implements' type+))? enumConstant+ classScopeDeclaration*)
 -    |   ^(chareType IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
 -    |   ^('chare_array' ARRAY_DIMENSION IDENT (^('extends' type))? (^('implements' type+))? classScopeDeclaration*)
 +    ;
 +
 +classType
 +    :   CLASS
 +    |   chareType
      ;
  
  chareType
@@@ -184,40 -157,18 +189,43 @@@ scope ScopeStack
      :   ^(FUNCTION_METHOD_DECL m=modifierList? g=genericTypeParameterList? 
              ty=type IDENT f=formalParameterList a=arrayDeclaratorList? 
              b=block?)
 -    |   ^(VOID_METHOD_DECL m=modifierList? g=genericTypeParameterList? IDENT 
 -            f=formalParameterList b=block?)
 -    |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList[false])
 -    |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList[false])
 +        {
 +            ClassSymbol returnType = currentClass.resolveType($ty.text);
 +            MethodSymbol sym = new MethodSymbol(symtab, $IDENT.text, currentClass, returnType);
 +            currentMethod = sym;
 +            sym.definition = $classScopeDeclaration.start;
 +            sym.definitionTokenStream = input.getTokenStream();
 +            currentClass.define($IDENT.text, sym);
 +            $FUNCTION_METHOD_DECL.symbol = sym;
 +        }
 +    |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType
-             ^(VAR_DECLARATOR_LIST field[$simpleType.type]+))
++            ^(VAR_DECLARATOR_LIST field[$simpleType.type, false]+))
 +    |   ^(OBJECT_VAR_DECLARATION modifierList? objectType
-             ^(VAR_DECLARATOR_LIST field[$objectType.type]+))
++            ^(VAR_DECLARATOR_LIST field[$objectType.type, false]+))
 +        {
 +            ClassSymbol type = $objectType.type;
 +            if (type != null && type.isChare) currentClass.addExtern(type.getName());
 +        }
      |   ^(CONSTRUCTOR_DECL m=modifierList? g=genericTypeParameterList? IDENT f=formalParameterList 
              b=block)
          {
 -              if (currentClass != null) {
 +            if (astmod.isMigrationCtor($CONSTRUCTOR_DECL)) currentClass.migrationCtor = $CONSTRUCTOR_DECL;
++            if (currentClass != null) {
+                 currentClass.constructor = $classScopeDeclaration.start;
 -            } 
++            }
          }
      ;
- field [ClassSymbol type]
-     :   ^(VAR_DECLARATOR ^(IDENT arrayDeclaratorList?) variableInitializer?)
 +
-             VariableSymbol sym = new VariableSymbol(symtab, $IDENT.text, $type);
++field [ClassSymbol type, boolean localdef]
++    :   ^(VAR_DECLARATOR variableDeclaratorId[localdef] variableInitializer?)
 +    {
-             currentClass.define($IDENT.text, sym);
++            VariableSymbol sym = new VariableSymbol(symtab, $variableDeclaratorId.ident, $type);
 +            sym.definition = $field.start;
 +            sym.definitionTokenStream = input.getTokenStream();
 +            $VAR_DECLARATOR.symbol = sym;
++            currentClass.define($variableDeclaratorId.ident, sym);
 +    }
 +    ;
      
  interfaceScopeDeclaration
      :   ^(FUNCTION_METHOD_DECL modifierList? genericTypeParameterList? 
          // Interface constant declarations have been switched to variable
          // declarations by Charj.g; the parser has already checked that
          // there's an obligatory initializer.
-     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList)
-     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList)
+     |   ^(PRIMITIVE_VAR_DECLARATION modifierList? simpleType variableDeclaratorList[false])
+     |   ^(OBJECT_VAR_DECLARATION modifierList? objectType variableDeclaratorList[false])
      ;
  
- variableDeclaratorList
-     :   ^(VAR_DECLARATOR_LIST variableDeclarator+)
+ variableDeclaratorList[boolean localdef]
+     :   ^(VAR_DECLARATOR_LIST variableDeclarator[localdef]+)
      ;
  
- variableDeclarator
-     :   ^(VAR_DECLARATOR ^(IDENT arrayDeclaratorList?) variableInitializer?)
+ variableDeclarator[boolean localdef]
+     :   ^(VAR_DECLARATOR variableDeclaratorId[localdef] variableInitializer?)
      ;
      
- variableDeclaratorId
-     :   ^(IDENT arrayDeclaratorList?)
 -variableDeclaratorId[boolean localdef]
 -    :   ^(IDENT domainExpression? 
++variableDeclaratorId[boolean localdef] returns [String ident]
++    :   ^(IDENT domainExpression?
+         { 
+             if (currentClass != null && !localdef) {
+                 currentClass.initializers.add($variableDeclaratorId.start);
+             }
++
++            $ident = $IDENT.text;
+         } )
+     ;
+ rangeItem
+     :   DECIMAL_LITERAL
+     |   IDENT
+     ;
+ rangeExpression
+     :   ^(RANGE_EXPRESSION rangeItem)
+     |   ^(RANGE_EXPRESSION rangeItem rangeItem)
+     |   ^(RANGE_EXPRESSION rangeItem rangeItem rangeItem)
+     ;
+ rangeList
+     :   rangeExpression*
+     ;
+ domainExpression
+     :   ^(DOMAIN_EXPRESSION rangeList)
      ;
  
  variableInitializer
@@@ -317,45 -268,23 +350,45 @@@ otherModifie
  
  type
      :   simpleType
 -    |   objectType 
 +    |   objectType
 +    |   VOID
      ;
  
 -simpleType
 -    :   ^(TYPE primitiveType domainExpression?)
 +simpleType returns [ClassSymbol type]
 +    :   ^(SIMPLE_TYPE primitiveType arrayDeclaratorList?)
 +        {
 +            $type = symtab.resolveBuiltinType($primitiveType.text);
 +        }
      ;
      
 -objectType
 -    :   ^(TYPE qualifiedTypeIdent domainExpression?)
 +objectType returns [ClassSymbol type]
 +    :   ^(OBJECT_TYPE qualifiedTypeIdent arrayDeclaratorList?)
 +    |   ^(REFERENCE_TYPE qualifiedTypeIdent arrayDeclaratorList?)
 +    |   ^(PROXY_TYPE qualifiedTypeIdent arrayDeclaratorList?)
 +    |   ^(POINTER_TYPE qualifiedTypeIdent arrayDeclaratorList?)
 +        {
 +            $type = $qualifiedTypeIdent.type;
 +        }
      ;
  
 -qualifiedTypeIdent
 -    :   ^(QUALIFIED_TYPE_IDENT typeIdent+) 
 +qualifiedTypeIdent returns [ClassSymbol type]
 +@init {
 +String name = "";
 +}
 +    :   ^(QUALIFIED_TYPE_IDENT (typeIdent {name += $typeIdent.name;})+) 
 +        {
 +            $type = null;
 +            /*System.out.println("trying to resolve type " + name + " in type " + currentClass);*/
 +            if (currentClass != null) $type = currentClass.resolveType(name);
 +            /*System.out.println("got " + $type);*/
 +            if ($type == null) $type = symtab.resolveBuiltinType(name);
 +            $QUALIFIED_TYPE_IDENT.symbol = $type;
 +        }
      ;
  
 -typeIdent
 +typeIdent returns [String name]
-     :   ^(IDENT genericTypeArgumentList?)
+     :   ^(IDENT templateInstantiation?)
 +        { $name = $IDENT.text; }
      ;
  
  primitiveType
@@@ -407,13 -345,8 +449,13 @@@ blockStatemen
      ;
      
  localVariableDeclaration
-     :   ^(PRIMITIVE_VAR_DECLARATION localModifierList? simpleType variableDeclaratorList)
-     |   ^(OBJECT_VAR_DECLARATION localModifierList? objectType variableDeclaratorList)
+     :   ^(PRIMITIVE_VAR_DECLARATION localModifierList? simpleType variableDeclaratorList[true])
+     |   ^(OBJECT_VAR_DECLARATION localModifierList? objectType variableDeclaratorList[true])
 +        {
 +            ClassSymbol type = $objectType.type;
 +            /*System.out.println("looked up type " + type + " for declaration " + $objectType.text);*/
 +            if (type != null && type.isChare && currentClass != null) currentClass.addExtern(type.getName());
 +        }
      ;
  
  statement
@@@ -559,14 -471,22 +601,15 @@@ arrayTypeDeclarato
      ;
  
  newExpression
-     :   ^(  STATIC_ARRAY_CREATOR
-             (   primitiveType newArrayConstruction
-             |   genericTypeArgumentList? qualifiedTypeIdent newArrayConstruction
-             )
-         )
+     :   ^(NEW_EXPRESSION arguments? domainExpression)
+         {
+             if (currentClass != null) {
+                 currentClass.initializers.add($newExpression.start);
+             }
+         }
 +    |   ^(NEW type arguments)
      ;
  
 -/*newExpression
 -    :   ^(  STATIC_ARRAY_CREATOR
 -            (   primitiveType newArrayConstruction
 -            |   genericTypeArgumentList? qualifiedTypeIdent newArrayConstruction
 -            )
 -        )
 -    ;*/
 -
  newArrayConstruction
      :   arrayDeclaratorList arrayInitializer
      |   expression+ arrayDeclaratorList?
index 42f072a2974c8116ee1379ad73a2855c80a7d187,f5f228bebf2dbde655179a4fd5a4e651b88d777a..e4c727df5e46617f96700f839eac96cf705921e1
@@@ -7,27 -7,33 +7,31 @@@ public class ClassSymbol extends Symbol
  
      public ClassSymbol superClass;
      public List<String> interfaceImpls;
+     public List<String> templateArgs;
+     public List<CharjAST> initializers;
+     public CharjAST constructor;
  
 -    Map<String, PackageScope> imports = 
 +    Map<String, PackageScope> imports =
          new LinkedHashMap<String, PackageScope>();
 +    List<String> includes = new ArrayList<String>();
 +    List<String> usings = new ArrayList<String>();
 +    List<String> externs = new ArrayList<String>();
  
 -    /** List of all fields and methods */
 +    /** Record of all fields and methods */
      public Map<String, Symbol> members = new LinkedHashMap<String, Symbol>();
 -    public Map<String, String> aliases = new LinkedHashMap<String, String>();
 -
 -    /** The set of method names (without signatures) for this class.  Maps
 -     *  to a list of methods with same name but different args
 -     protected Map<String, List<MethodSymbol>> methods =
 -     new HashMap<String, List<MethodSymbol>>();
 -     */
 -
 -    /** List of unmangled methods for this class. Used to distinguish
 -     *  var from method name in expressions.  x = f; // what is f?
 -     */
 -    protected Set<String> methodNames = new HashSet<String>();
 +    public Map<String, VariableSymbol> fields = new LinkedHashMap<String, VariableSymbol>();
 +    public Map<String, MethodSymbol> methods = new LinkedHashMap<String, MethodSymbol>();
  
      public boolean hasCopyCtor = false;
 +    public boolean isPrimitive = false;
 +    public boolean isChare = false;
 +    public boolean isMainChare = false;
 +
 +    public CharjAST migrationCtor = null;
  
      public ClassSymbol(
 -            SymbolTable symtab, 
 +            SymbolTable symtab,
              String name) {
          super(symtab, name);
          type = this;
          this(symtab, name);
          this.superClass = superClass;
          this.scope = scope;
+       this.initializers = new ArrayList<CharjAST>();
+       constructor = null;
  
          // manually add automatic class methods and symbols here
 +        this.includes.add("charm++.h");
 +        this.includes.add("list");
 +        this.usings.add("std::list");
 +        this.includes.add("string");
 +        this.usings.add("std::string");
 +        this.includes.add("vector");
 +        this.usings.add("std::vector");
 +        this.includes.add("map");
 +        this.usings.add("std::map");
 +        this.includes.add("iostream");
 +        this.usings.add("std::cout");
 +        this.usings.add("std::endl");
      }
  
      public Scope getEnclosingScope() {
index 8c4398072a6aa81f6ac6f04bbc9ad1b708dfc3f4,f0bdce59c819cc6b8a0a331976ce5a3056804de7..901b8bfee813cdeb5523ca4111eb8b97eab1e550
@@@ -92,17 -88,18 +92,23 @@@ public class Translator 
          m_nodes.setTokenStream(tokens);
          m_nodes.setTreeAdaptor(m_adaptor);
  
 -        // do AST rewriting in semantic phase
 -        if (m_printAST) printAST("Before Semantic Pass", "before.html");
 -        ClassSymbol sem = semanticPass();
 +        // do AST rewriting and semantic checking
 +        if (m_printAST) printAST("Before Modifier Pass", "before_mod.html");
 +        modifierPass();
 +        m_nodes = new CommonTreeNodeStream(m_ast);
 +        m_nodes.setTokenStream(tokens);
 +        m_nodes.setTreeAdaptor(m_adaptor);
 +        if (m_printAST) printAST("Before Semantic Pass", "before_sem.html");
-         semanticPass();
++      ClassSymbol sem = semanticPass();
+       modifyNodes(sem);
 -        if (m_printAST) printAST("After Semantic Pass", "after.html");
++        //semanticPass();
 +        if (m_printAST) printAST("After Semantic Pass", "after_sem.html");
  
+       m_nodes = new CommonTreeNodeStream(m_ast);
+         m_nodes.setTokenStream(tokens);
+         m_nodes.setTreeAdaptor(m_adaptor);
          // emit code for .ci, .h, and .cc based on rewritten AST
 -        m_nodes.reset();
          String ciOutput = translationPass(OutputMode.ci);
          writeTempFile(filename, ciOutput, OutputMode.ci);
  
          return sem.charjSource(m_symtab);
      }
  
 -              CharjAST ast2_1 = new CharjAST(CharjParser.T__140, ".");
+     private CharjAST addConstructor(ClassSymbol sem) {
+       CharjAST ast1 = new CharjAST(CharjParser.CONSTRUCTOR_DECL, 
+                                    "CONSTRUCTOR_DECL");
+       CharjAST ast2 = new CharjAST(CharjParser.IDENT, 
+                                    sem.getScopeName());
+       CharjAST ast3 = new CharjAST(CharjParser.FORMAL_PARAM_LIST, 
+                                    "FORMAL_PARAM_LIST");
+       CharjAST ast4 = new CharjAST(CharjParser.BLOCK, "BLOCK");
+       
+       ast1.addChild(ast2);
+       ast1.addChild(ast3);
+       ast1.addChild(ast4);
+       sem.definition.addChild(ast1);
+       return ast1;
+     }
+     private void modifyNodes(ClassSymbol sem) {
+       /* Add constructor */
+       if (sem.constructor == null) {
+           sem.constructor = addConstructor(sem);
+       }
+       /* Insert array initializers into the constructor */
+       for (CharjAST init : sem.initializers) {
+           System.out.println("processing init token = " + init.getType());
+           if (init.getType() == CharjParser.IDENT) {
+               CharjAST ast1 = new CharjAST(CharjParser.EXPR, "EXPR");
+               CharjAST ast2 = new CharjAST(CharjParser.METHOD_CALL, "METHOD_CALL");
++              CharjAST ast2_1 = new CharjAST(CharjParser.DOT, ".");
+               CharjAST ast2_2 = new CharjAST(CharjParser.IDENT, init.getText());
+               CharjAST ast2_3 = new CharjAST(CharjParser.IDENT, "init");
+               CharjAST ast4 = new CharjAST(CharjParser.ARGUMENT_LIST, "ARGUMENT_LIST");
+               ast1.addChild(ast2);
+               ast2.addChild(ast2_1);
+               ast2_1.addChild(ast2_2);
+               ast2_1.addChild(ast2_3);
+               ast2.addChild(ast4);
+               ast4.addChildren(init.getChildren());
+               //System.out.println(sem.constructor.toStringTree());
+               sem.constructor.getChild(2).addChild(ast1);
+           } else if (init.getType() == CharjParser.NEW_EXPRESSION) {
+               //(OBJECT_VAR_DECLARATION (TYPE (QUALIFIED_TYPE_IDENT (Array (TEMPLATE_INST (TYPE double(Symbol(double_primitive, ClassSymbol[double]: {}, ))))))) (VAR_DECLARATOR_LIST (VAR_DECLARATOR ccc (NEW_EXPRESSION (ARGUMENT_LIST (EXPR get)) (DOMAIN_EXPRESSION (RANGE_EXPRESSION 1))))))
+           }
+           
+       }
+     }
      private String translationPass(OutputMode m) throws
          RecognitionException, IOException, InterruptedException
      {