anchor.diff:  grammar prolog;
   
   program 
  -    : clauselist query?
  +    : clauselist query? EOF
       ;
   
   clauselist 
  
positive.code:     ;
  
  clause 
      : (predicate '.') | (predicate ':-') (predicatelist '.')
      ;
  
  predicatelist 
  
negative.code:     ;
  
  atom 
      : '[' ']'
      | '{' '}'
      | SMALLATOM
      | GRAPHIC_TOKEN
      | QUOTED_TOKEN
      | '\'' STRING '\'' //FIXME escapes in strings
      | '"' STRING '"'
      | '`' STRING '`'
      | ';'
      | '!'
      ;
  
  
  integer
      : DECIMAL
      | BINARY
      | OCTAL
      | HEX
      ;
  
  // Lexer
  
  SMALLATOM
      : LCLETTER CHARACTER*
      ;
  
  VARIABLE
      : UCLETTER CHARACTER*
      ;
  
  DECIMAL: DIGIT+ ;
  BINARY: [01]+ ;
  OCTAL: [0-7]+ ;
  HEX: [0-9a-fA-F]+ ;
  
  FLOAT
      : DECIMAL '.' [0-9]+ ( [eE] [+-] DECIMAL )?
      ;
  
  fragment CHARACTER
      : LCLETTER
      | UCLETTER
      | DIGIT
      | SPECIAL
      ;
  
  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
      ;
  
  fragment SPECIAL
      : '+' | '-' | '*' | '/' | '\\' | '^' | '~' | ':' | '.' | '?' | '#' | '$' | '&'
      ;
  
  STRING
      : CHARACTER+
      ;
  
  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);
  