anchor.diff:  PLUS                    : '+' ;
   SUBTRACT                : '-' ;
   // Comparison
  +LESS_THAN               : '<' ;
  +LESS_THAN_EQUAL         : '<=' ;
   EQUAL                   : '=' ;
   NOT_EQUAL               : '!=' ;
  +GREATER_THAN_EQUAL      : '>=' ;
  +GREATER_THAN            : '>' ;
   // Brackets
   OPEN_PAREN              : '(' ;
   CLOSE_PAREN             : ')' ;
  
positive.code:     | RANDOM name=symbol ':' parameters+=symbol (X parameters+=symbol)* '->' range=symbol
      ;
      
  rule_definition
      : IF formula THEN rule_definition ELSE rule_definition #conditionalRule
      | f=formula (p=potential)? #formulaWithOptionalPotentialRule
      ;
      
  formula
      : '(' formula ')' #termWithParentheses
      | functor=symbol '(' ( args+=formula (',' args+=formula)* )? ')' #formulaFunctionApplication
      | NOT formula #notFunctionApplication
      | leftconj=formula AND rightconj=formula #andFunctionApplication
      | leftconj=formula OR rightconj=formula #orFunctionApplication
      | IF condition=formula THEN thenbranch=formula ELSE elsebranch=formula #ifThenElseFunctionApplication
      | quantified_expression #termQuantifiedExpression
      | constant #termConstant
      | variable #termVariable
      ;
      
  quantified_expression
      : FOR ALL index=variable ':' body=formula #forAll
      | THERE EXISTS index=variable ':' body=formula #thereExists
      ;
      
  constant
      : CONSTANT
      ;
      
  variable
      : VARIABLE
      ;
  
  potential
      :  // parenthesis, e.g.:(1+2)
       '(' potential ')' #potentialWithParentheses
         // exponentiation, e.g. 2^3^4 -> 2^(3^4)
       |<assoc=right> base=potential '^' exponent=potential #potentialExponentiation
         // multiplication or division, e.g.: 2*3/2 -> 2*(3/2)
       | leftop=potential op=('*' | '/') rightop=potential #potentialMultiplicationOrDivision
         // addition or subtraction, e.g.: 1-2+3 -> (1-2)+3
       | leftop=potential op=('+' | '-') rightop=potential #potentialAdditionOrSubtraction
         // i.e. a constant value between [0-1]
       | atomic_potential #potentialValue
      ;
  
  atomic_potential
      : INTEGER
      | RATIONAL
      ;
  
  symbol
  
negative.code:     
  statement
      : declaration
      | term     // <number-typed> term;
      ;
  
  declaration
  