anchor.diff:  DOT             : '.';
   NOT             : '¬';
   
  -// -- Common lexing rules with Crsx.g4.
  +// -- Common lexing rules with TransScript.g4.
   //    Cannot extract these rules yet as the antlr meta parser generator does not support modular grammars yet 
   
   CONSTRUCTOR     : StartConstructorChar ConstructorChar* // '$' is for internal use only.
  
positive.code: /*
   * Copyright (c) 2015 IBM Corporation.
   *
   * This is the Crsx Core grammar specification.
   *
   * To avoid conflicts with the Crsx grammar,
   * every production starts with a 'c' for 'c'ore
   */
  
  /* 
  %MS: Comments are directly above the respective line and 
                start with %MS or %LV
                and ANTLR code is distinguished by: 'antlr'.
  */
  
  
  /* Open:
     Map <- depends on plank to stabilize
     cform <-  MS: think through, comment
     properties for (term) variables
     As Sort, inline sort annotation for easier Code Generation
  */
  
  grammar Core;
  
  
negative.code:     : cdecl+
      ;
  
  cdecl
      : RULE  cterm ARROW cterm                               /* Rule declaration */
      | DATA  csortvars? CONSTRUCTOR cforms                   /* Data sort declaration */
      | EXTERN? FN csortvars? csort CONSTRUCTOR csorts?       /* Function sort declaration */
      | IMPORT MODULE CONSTRUCTOR                             /* Import module declaration */
      | IMPORT GRAMMAR CONSTRUCTOR                            /* Import grammar declaration */
      ;
  
  
  // -- Term
  
  cterm
      : CONSTRUCTOR cterms?                                               /* Constant/Construction */
      | METAVAR cterms?                                                   /* Meta variable/substitution */
      | LSQUARE VARIABLE<boundvar=x> RSQUARE cterm<bound=x>               /* Bound term. 
                                                                             VARIABLE<boundvar=x> means VARIABLE is a bound variable we call x
                                                                             cterm<bound=x>       means x is bound in the context of the cterm */
      | cliteral                                                          /* Literal construction */
      | cvariable                                                         /* Variable */
      | LCURLY cmapentries? RCURLY                                        /* Association map */
      ;
  
  /* TODO: inline when antlr-based meta parser generator support (()*)? */
  cterms
      : LPAR cterm (COMMA cterm)* RPAR                    /* Term list */
      ;
  
  cliteral
      : STRING                                                    /* String literal */
      | NUMBER                                                    /* Number literal */
      ; 
  
  cvariable
      : VARIABLE<variable>  /* Variable occurrence */
                            /* <variable> means 1. maps VARIABLE to a syntactic variable
                                                2. look for a bound variable that matches VARIABLE 
                                                   in the current tracked bound variables (innermost scope first). 
                                                   VARIABLE is free if not found in scope.  */
      ;
  
  cmapentries
      : cmapentry (COMMA cmapentry)*
      ;
  
  cmapentry
      : COLON METAVAR                                      /* property reference (match/construct)      */
      | NOT METAVAR                                        /* no property references (match only)       */
      | METAVAR COLON cterm                                /* match property value / construct          */
      | VARIABLE                                           /* match / construct variable property       */
      | NOT VARIABLE                                       /* no variable (match only)                  */
      | VARIABLE COLON cterm                               /* match variable property value / construct */
      | STRING                                             /* match / construct named property          */
      | NOT STRING                                         /* no named property (match only)            */
      | STRING COLON cterm                                 /* match named property value / construct    */
      ;
  
  
  // -- Sorts
  
  