[antlr-interest] EarlyExitException Problem

Luís Reis luiscubal at gmail.com
Tue Jul 21 09:58:22 PDT 2009


Hello, I had a grammar written in Antlr 3 and I am getting
EarlyExitExceptions.
This grammar attempts to match things like:

"[1..3]", "[ 1 .. 3]", "[ 1 .. x ]", "[x..1]", etc.

However, when provided  "[1..3]", it exits with an EarlyExitException.
line 1:3 required (...)+ loop did not match anything at character '.'
MismatchedTokenException(5!=7)
line 1:5 mismatched input ']' expecting TO

I believe it is a problem related to float parsing. The remaining examples
are parsed properly.
How do I prevent this problem?

I managed to simplify the grammar and reduce it to the following(the
original grammar is a lot more complex since it has support for other
statements):

//GRAMMAR STARTS HERE
grammar MyGrammarName;

options{
    backtrack = true;
    output = AST;
}

tokens{
    LARRAY = '[';
    RARRAY = ']';
    DOT = '.';
    TO = '..'; //I've tried declaring TO before DOT, declaring TO as a
separate rule and several variations.
}

@header{

package javapackage;

}

@lexer::header{

package javapackage;

}

test    :    LARRAY exp TO exp RARRAY;

exp    :    WORD|constant;

constant:    INTCONST|FLOATCONST;

WORD    :    ALPHA ALPHADIGIT*;

fragment ALPHA
    :    ('a'..'z')|('A'..'Z')|'_';

fragment ALPHADIGIT
    :    ALPHA|DIGIT;

FLOATCONST
    :
        (DIGIT+ ('e'|'E') '-'? DIGIT+)
    |        (DIGIT* DOT DIGIT+ (('e'|'E') '-'? DIGIT+)?)
    ;

INTCONST:    (NONZERODIGIT DIGIT*);

fragment NONZERODIGIT
    :    '1'..'9';

fragment DIGIT
    :    '0'|NONZERODIGIT;


IGNORED    :    (WS|LINEBREAK)+
        { $channel = HIDDEN; };

fragment LINEBREAK
    :    '\u000D'
    |    '\n'
        ;

fragment WS : (' ' | '\t' | '\f')+;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090721/c8277dc7/attachment.html 


More information about the antlr-interest mailing list