anchor.diff:      ;
   
   atom 
  -    : smallatom | '\'' string '\''
  +    : '[' ']'
  +    | '{' '}'
  +    | SMALLATOM
  +    | GRAPHIC_TOKEN
  +    | QUOTED_TOKEN
  +    | '\'' STRING '\'' //FIXME escapes in strings
  +    | '"' STRING '"'
  +    | '`' STRING '`'
  +    | ';'
  +    | '!'
       ;
   
  -smallatom 
  -    : LCLETTER | smallatom character
  +
  +integer
  +    : DECIMAL
  +    | BINARY
  +    | OCTAL
  +    | HEX
       ;
   
  -variable 
  -    : UCLETTER | variable character
  +// Lexer
  +
  +SMALLATOM
  +    : LCLETTER CHARACTER*
       ;
   
  -numeral 
  -    : DIGIT | numeral DIGIT
  +VARIABLE
  +    : UCLETTER CHARACTER*
       ;
   
  -character 
  -    : LCLETTER | UCLETTER | DIGIT | special
  +DECIMAL: DIGIT+ ;
  +BINARY: [01]+ ;
  +OCTAL: [0-7]+ ;
  +HEX: [0-9a-fA-F]+ ;
  +
  +FLOAT
  +    : DECIMAL '.' [0-9]+ ( [eE] [+-] DECIMAL )?
       ;
   
  -special 
  -    : '+' | '-' | '*' | '/' | '\\' | '^' | '~' | ':' | '.' | '?' | '#'| '$' | '&'
  +fragment CHARACTER
  +    : LCLETTER
  +    | UCLETTER
  +    | DIGIT
  +    | SPECIAL
       ;
   
  -string 
  -    : character | string character
  +GRAPHIC_TOKEN: GRAPHIC | '\\' ;
  +fragment GRAPHIC: [#$&*+-./:<=>?@^~] ; // 6.5.1 graphic char
  +
  +QUOTED_TOKEN: NON_QUOTE_CHAR | '\'\'' | '"' | '`' ;
  +fragment NON_QUOTE_CHAR // 6.4.2.1
  +    : GRAPHIC
  +    | LCLETTER | UCLETTER // == alphanumeric char 6.5.2
  +    // the others partly duplicate stuff, like allowing single space
       ;
   
  -LCLETTER
  -    : [a-z_]+;
  +fragment SPECIAL
  +    : '+' | '-' | '*' | '/' | '\\' | '^' | '~' | ':' | '.' | '?' | '#' | '$' | '&'
  +    ;
   
  -UCLETTER
  -    : [A-Z]+;
  +STRING
  +    : CHARACTER+
  +    ;
   
  -DIGIT
  -    : [0-9]+;
  +fragment LCLETTER
  +    : [a-z_];
  +
  +fragment UCLETTER
  +    : [A-Z];
  +
  +fragment DIGIT
  +    : [0-9];
   
   WS
      : [ \t\r\n]+ -> skip
      ;
  +
  +COMMENT: '%' ~[\n\r]* ( [\n\r] | EOF) -> channel(HIDDEN) ;
  +MULTILINE_COMMENT: '/*' ( MULTILINE_COMMENT | . )*? ('*/' | EOF) -> channel(HIDDEN);
  
positive.code: grammar prolog;
  
  program 
      : clauselist query?
      ;
  
  clauselist 
  
negative.code:     ;
  
  predicate 
      : atom
      | atom '(' termlist ')'
      ;
  
  termlist 
      : term ( ',' term )*
      ;
  
  term 
      : VARIABLE
      | atom
      | integer
      | FLOAT
      | structure
      ;
  
  structure 
  