anchor.diff:          ;
   assign  : '<' value (',' value)* '>' 
           ;
  -value	: ID
  +value   : ID
           | INT
           | STRING
           ;
   nodeset : '(' ')' 
           | '(' nodes (',' nodes)* ')'
           ;
  -nodes	: ID indices*
  -	;
  +nodes   : ID indices*
  +        ;
   indices : '[' expr ']'
  -	| '[' expr '...' expr ']'
  -	;
  -portset	: '(' port (',' port)* ')'
  -	;
  -port	: ID '?'  # portInput
  +        | '[' expr '...' expr ']'
  +        ;
  +portset : '(' port (',' port)* ')'
  +        ;
  +port    : ID '?'  # portInput
           | ID '!'  # portOutput
           ;
  -expr 	: ID             # exprParameter
  +expr    : ID             # exprParameter
           | INT            # exprInteger
           | '-' expr       # exprUnaryMin
           | expr '+' expr  # exprAddition 
  
positive.code:  */
  
  c       : '#C' FUNC
          ;
  			
  /**
   * Port Automata
   */
  
  pa              : '#PA' pa_stmt* 
                  ;
  pa_stmt	        : ID '*'? '--' sync_const '->' ID 
                  ;
  sync_const      : '{' '}'
  	        | '{' ID (',' ID)* '}'
                  ;
  
  /**
   * Constraint Automata with State Memory
   */
  
  cam             : '#CAM' cam_stmt* 
                  ;
  cam_stmt        : ID '*'? '--' sync_const ',' e '->' ID 
                  ;
  		
  		
  e	: t OP e                               # cam_exInfix
  	| PO t				       # cam_exInfix
  	| t
  	;
  t 	: STRING                               # cam_termString
  	| INT                                  # cam_termInteger
  	| ID                                   # cam_termPortOrMem
  	| ID '\''                              # cam_termMemoryNext
  	| ID '(' t (',' t )* ')'               # cam_termFunc
  	| '(' e ')' 
  	;
  
  /**
   * Work Automata
   */
  
  wa              : '#WA' wa_stmt* 
                  ;
  wa_stmt         : ID '*'? ':' wa_jc                           # wa_stmtInvar
                  | ID '*'? '--' sync_const ',' wa_jc '->' ID   # wa_stmtTrans
                  ;
  wa_jc           : 'true'           # wa_jcTrue
                  | ID '==' INT      # wa_jcEql
                  | ID '<=' INT      # wa_jcLeq
                  | wa_jc '&' wa_jc  # wa_jcAnd
                  ;
  
  /**
   * Tokens
  
negative.code: 
  file    : includes body EOF 
          ;
  incl    : 'include' PATH
          ;
  body    : (comp | defn)*
          ;
  defn    : 'define' ID params? portset '{' atom '}'  # defnAtomic
          | 'define' ID params? nodeset '{' body '}'  # defnComposed
          | nodes '=' nodes                           # defnJoin
          ;
  comp    : ID assign? nodeset                        # compReference 
          | 'for' ID '=' expr '...' expr '{' body '}' # compForLoop
          ;
  atom    : java   # atomJava
          | c      # atomC
          | pa     # atomPA
          | cam    # atomCAM
  