[antlr-interest] Post CommonTokenStream in the parser constructor

Luke Silver LukeSilver at web.de
Tue Mar 13 01:33:14 PDT 2007


OK, I managed it. IŽve only inserted a new constructor in my parser:

public MyParser(MyLexer lexer) {
super(new CommonTokenStream(lexer));
}

And now the following parser call works:

MyLexer lexer = new MyLexer(input);
MyParser parser = new MyParser(lexer);


Luke Silver



> Hi everybody,
> 
> is it possible to call the CommonTokenStream constructor in the parser?
> (ANTLR v3.0b5, Java)
> 
> Now I call it this way:
> 
> MyLexer lexer = new MyLexer(input);
> CommonTokenStream tokens = new CommonTokenStream(lexer);
> MyParser parser = new MyParser(tokens);
> //parse grammar
> parser.grammar();
> 
> and in the class MyParser.java:
> 
>  public MyParser(TokenStream input) {
>             super(input);
>             ruleMemo = new HashMap[48+1];
>          }
> 
> 
> And now I would like to do something like this:
> 
> MyLexer lexer = new MyLexer(input);
> MyParser parser = new MyParser(lexer);
> //parse grammar
> parser.grammar();
> 
> and in the class MyParser.java:
> 
> public MyParser(TokenSource tokenSource) {
>      CommonTokenStream tokens = new CommonTokenStream(tokenSource);
>      MyParser = new MyParser(tokens);
> }
> 
> 
> Best wishes,
> Luke
_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000066



More information about the antlr-interest mailing list