[antlr-interest] Proper way to run the parser and lexer as a shell with Antlr 3

Bruce Trask bruce.trask at mdesystems.com
Sat May 5 22:35:07 PDT 2007


Hello,
   
  What is the proper way to run the lexer and parser in a loop so it can behave as "shell", taking input from System.in?  I have tried some different attempts but am having some trouble with the input streams getting closed ?
   
  Here was another attempt but it did not work either:
  import org.antlr.runtime.*;
import java.io.*;
import org.antlr.tool.*;
  
public class TestBruce {
    public static void main(String[] args) throws Exception {
 
 
 ANTLRInputStream input = new ANTLRInputStream(System.in); 
 while(true)
     {
  
  System.out.print(">>> ");
  
  // create a lexer that feeds off of input CharStream
  bruceLexer lexer = new bruceLexer(input);
 
  System.out.println("after");
  // create a buffer of tokens pulled from the lexer
  CommonTokenStream tokens = new CommonTokenStream(lexer);
 
  // create a parser that feeds off the tokens buffer
  bruceParser parser = new bruceParser(tokens);
  // begin parsing at rule r
  parser.hello();
  input.reset();
     }
    }
}
   
  Thanks in advance,
Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070505/1790937b/attachment-0001.html 


More information about the antlr-interest mailing list