[antlr-interest] ANTLR3.0b2 - Best practice to end parsing ?
David CROSSON
david.crosson at wanadoo.fr
Tue Jul 18 08:24:10 PDT 2006
I'm looking for the best way to stop scanning
a data stream which contains structured text
data blocks; Do you thing that the following :
SampleParser.all_return rc;
while(true) {
rc=parser.all();
BaseTree tree = (BaseTree)rc.getTree();
if (tree.isNil()) break;
}
is the best way to end the scan once all the
structured data blocsk have been found ?
grammar SampleParser;
options {
filter=true;
output=AST;
}
@header {
package stackdumpparser.parsers;
}
@lexer::header {
package stackdumpparser.parsers;
}
all : 'A' {System.out.println("Found");}
;
public void testBasic() throws RecognitionException, InterruptedException {
CharStream in = new ANTLRStringStream("BABAA");
SampleParserLexer lexer = new SampleParserLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SampleParser parser = new SampleParser(tokens);
int i=0;
SampleParser.all_return rc;
while(true) {
rc=parser.all();
BaseTree tree = (BaseTree)rc.getTree();
if (tree.isNil()) break;
}
}
Best regards,
Crosson david.
More information about the antlr-interest
mailing list