Manejo de excepciones

He desarrollado una gramática compleja usando Antlr 3 usando el árbol AST. ANTLR genera el Lexer y el analizador. El problema es que cuando el usuario ingresa una sintaxis que no es válida, por ejemplo, la gramática está esperando ';'. El usuario no ingresa esto, luego en mi IDE de Eclipse obtengo la siguiente excepción:

 line 1:24 mismatched input '<EOF>' expecting ';'

¿Cómo se puede manejar esta excepción porque trato de atrapar esta excepción, pero la excepción no está atrapada? ¿Es esta una excepción en absoluto? Parece que no entiendo por qué esta excepción no se captura. Traté de averiguarlo, sin embargo, el sitio web de Antlr parece estar inactivo desde hace algún tiempo.

Miré lo siguiente:Manejo de excepciones ANTLR con "$3$quot;, Java y seguí ese ejemplo, pero cuando el Lexer genera el código agregando la RuntimeException (), obtengo un código inalcanzable.

No estoy seguro de qué hacer.

Cuando intento obtener el número de errores de sintaxis del analizador, muestra 0.

EDITAR:

He encontrado una solución que funciona mirando:ANTLR no lanza errores en una entrada no válida

Sin embargo, cuando intento recuperar el mensaje de excepción, es nulo. ¿He configurado todo correctamente? Por favor vea ejemplo de gramática:

grammar i;

options {
output=AST;
}

@header {
package com.data;
}

@rulecatch {
    catch(RecognitionException e) {
        throw e;
   }
}

// by having these below it makes no difference
/**@parser::members {
    @Override
    public void reportError(RecognitionException e) {
        throw new RuntimeException("Exception : " + " " + e.getMessage());
    }
}

@lexer::members {
    @Override
    public void reportError(RecognitionException e) {
       throw new RuntimeException("Exception : " + " " + e.getMessage());
    }
}*/

EDITAR:

Por favor, vea lo que tengo hasta ahora:

grammar i;

options {
output=AST;
}

@header {
package com.data;
}

@rulecatch {
    // ANTLR does not generate its normal rule try/catch
    catch(RecognitionException e) {
        throw e;
    }
}

@parser::members {
    @Override
    public void displayRecognitionError(String[] tokenNames, RecognitionException e) {
        String hdr = getErrorHeader(e);
        String msg = getErrorMessage(e, tokenNames);
        throw new RuntimeException(hdr + ":" + msg);
    }
}

@lexer::members {
    @Override
    public void displayRecognitionError(String[] tokenNames, RecognitionException e) {
        String hdr = getErrorHeader(e);
        String msg = getErrorMessage(e, tokenNames);
        throw new RuntimeException(hdr + ":" + msg);
    }
}

operatorLogic   : 'AND' | 'OR';
value       : STRING;
query       : (select)*;
select      : 'SELECT'^ functions 'FROM table' filters?';';
operator    : '=' | '!=' | '<' | '>' | '<=' | '>=';
filters : 'WHERE'^ conditions;
members : STRING operator value;
conditions  : (members (operatorLogic members)*);
functions   : '*';
STRING  : ('a'..'z'|'A'..'Z')+;
WS      : (' '|'\t'|'\f'|'\n'|'\r')+ {skip();}; // handle white space between keywords

public class Processor {

public Processor() {

}

/**
 * This method builds the MQL Parser.
 * @param args the args.
 * @return the built IParser.
 */
private IParser buildMQLParser(String query) {
    CharStream cs = new ANTLRStringStream(query);
    // the input needs to be lexed
    ILexer lexer = new ILexer(cs);
          CommonTokenStream tokens = new CommonTokenStream();
    IParser parser = new IParser(tokens);
    tokens.setTokenSource(lexer);
    // use the ASTTreeAdaptor so that the grammar is aware to build tree in AST format
    parser.setTreeAdaptor((TreeAdaptor) new ASTTreeAdaptor().getASTTreeAdaptor());
return parser;
}

/**
 * This method parses the MQL query.
 * @param query the query.
 */
public void parseMQL(String query) {
    IParser parser = buildMQLParser(query);
    CommonTree commonTree = null;
    try {
                     commonTree = (CommonTree) parser.query().getTree();
                    }
    catch(Exception e) {
        System.out.println("Exception :" + " " + e.getMessage());
    }
}
}

public class ASTTreeAdaptor {

public ASTTreeAdaptor() {

}

/**
 * This method is used to create a TreeAdaptor.
 * @return a treeAdaptor.
 */
public Object getASTTreeAdaptor() {
    TreeAdaptor treeAdaptor = new CommonTreeAdaptor() {
        public Object create(Token payload) {
        return new CommonTree(payload);
        }
    };
    return treeAdaptor; 
}
}

Entonces cuando ingrese lo siguiente: SELECCIONAR * DE la tabla

sin un ';' Me sale una excepción MokatchTokenException:

catch(Exception e) {
     System.out.println("Exception : " + " " e);
}

Cuando intento

e.getMessage();

devuelve nulo.

Respuestas a la pregunta(2)

Su respuesta a la pregunta