0
votes

I have this simple grammar

grammar Monto;
import util;

documento: .*? monto .+;
monto: SYMBOL INT+;

SYMBOL: '$';

And when I run that I get this error:

line 1:0 mismatched input '<EOF>'

I added EOF to my main rule but it does not works, I tried with this

documento: .*? monto .+ EOF;

or this

documento: .*? monto .+? EOF;

The curious is when I run that from cmd(ANTLR4 tool) it works

EDITED

I'm using ANLTR 4.7.1 and this is how I create the lexers and parsers

public GrammarModule(String text) {
    CharStream input = CharStreams.fromString(text);
    demandantesLexer = new DemandantesLexer(input);
    demandantesParser = new DemandantesParser(new CommonTokenStream(demandantesLexer));
    demandadosLexer = new DemandadosLexer(input);
    demandadosParser = new DemandadosParser(new CommonTokenStream(demandadosLexer));
    direccionLexer = new DireccionLexer(input);
    direccionParser = new DireccionParser(new CommonTokenStream(direccionLexer));
    fechaLexer = new FechaLexer(input);
    fechaParser = new FechaParser(new CommonTokenStream(fechaLexer));
    montoLexer = new MontoLexer(input);
    montoParser = new MontoParser(new CommonTokenStream(montoLexer));
    numCuentaLexer = new NumCuentaLexer(input);
    numCuentaParser = new NumCuentaParser(new CommonTokenStream(numCuentaLexer));
    oficioLexer = new OficioLexer(input);
    oficioParser = new OficioParser(new CommonTokenStream(oficioLexer));
    referenciaLexer = new ReferenciaLexer(input);
    referenciaParser = new ReferenciaParser(new CommonTokenStream(referenciaLexer));
}

Invoking the parsers

fechaParser.documento().fecha().getText();
montoParser.documento().monto().getText();

so on...

1
If it finds EOF at line 1, column 0, that means the input stream is empty. Maybe you should show us how you invoke the parser.sepp2k
Question edited!Julian Solarte
That still doesn't show how you invoke the parser(s), only how you create them, but the fact that you create multiple lexers over the same input stream is already highly suspicious. What are you trying to do there?sepp2k
Edited again, What I wanna is use the same input for several grammarsJulian Solarte

1 Answers

1
votes

All of your lexers read from the same stream and presumably all of your grammars consume the entire input (at least Monto does and I expect Fecha does as well). You also don't appear to reset the input stream between the invocations of the different parsers. So after you invoke the Fecha parser, the input stream will be empty because the parser consumed all the input. So when you invoke the Monto parser, it reads from an empty stream and produces an error because the grammar does not match the empty input.

Instead you should just create a different CharStream instance for each lexer.