[antlr-interest] Check individual stmt?

Sam Harwell sharwell at pixelminegames.com
Tue May 5 08:30:41 PDT 2009


Hi Bill,

If the identifiers are uniquely determined by the lexer, you'll gain a
significant performance advantage by something like this:

for ( Token token = lexer.nextToken(); token != null; token =
lexer.nextToken() )
{
  if ( token.getType() == Token.EOF )
    break;

  if ( token.getType() == ID )
    checkSymbolTable(token);
}


The lexer can be reset to a new ANTLRStringStream input by calling
setCharStream(new ANTLRStringStream(text)). You don't need to call
reset() after setting it to the new char stream.

Sam

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Bill Steer
Sent: Tuesday, May 05, 2009 9:52 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Check individual stmt?

Hello.  My grammar processes a "program," which consists of individual 
"statements."  Those statements are just semicolon-delimited 
expressions.  I'm storing all of the statements in a string and using 
the corresponding string as input to ANTLR.  So far, so good.  But I 
need to check the content of each individual statement to see if the IDs

in it are in a symbol table or not.  Is it possible, from an input point

of view, to send ANTLR a series of statements, one at a time?  I'm 
thinking here about the ANTLRStringStream, not the rule to run.  Do I 
have to create a new ANTLRStringStream and corresponding lexer each time

I feed it a new statement, or can the ANTLRStringStream be reset to a 
new input string?

Thanks very much for any help.

Bill


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list