Loading ...
Sorry, an error occurred while loading the content.

14405RE: [antlr-interest] Re: Bug in ANTLR C# implementation

Expand Messages
  • Maassen, H.A.M.
    Dec 1, 2004
    • 0 Attachment
      > Interesting. But the tree parsers must be initialized in the same way
      > off a parser right?.
      > On second thought, perhaps you are suggesting that the method should
      > be removed from C# tree parsers too?.

      From the online manual:

      CalcLexer lexer =
      new CalcLexer(new DataInputStream(System.in));
      CalcParser parser = new CalcParser(lexer);
      parser.expr();
      CommonAST t = (CommonAST)parser.getAST();
      CalcTreeWalker walker = new CalcTreeWalker();
      walker.expr(t);

      To get this to work in C# (assuming that the CalcTreeWalker does tree-reformatting) I'd have to change it to:

      CalcLexer lexer =
      new CalcLexer(new DataInputStream(System.in));
      CalcParser parser = new CalcParser(lexer);
      parser.expr();
      CommonAST t = (CommonAST)parser.getAST();
      CalcTreeWalker walker = new CalcTreeWalker();

      CalcTreeWalker.initializeASTFactory(walker.getASTFactory());

      walker.expr(t);

      That extra line feels kind of random to me :) Seems like it should just be done automatically in the constructor. Without a manual call, the procedure is never run.


      static public void initializeASTFactory( ASTFactory factory )
      {
      factory.setMaxNodeType(163); // 163 is generated by ANTLR
      }

      Regards, Harald Maassen
    • Show all 10 messages in this topic