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

TypeLoadException with custom AST Node

Expand Messages
  • bonotake2004
    Hi, all- I m now trying to use another AST node instead of CommonAST along with a past message(http://groups.yahoo.com/group/antlr- interest/message/3953). But
    Message 1 of 3 , Mar 31, 2004
      Hi, all-

      I'm now trying to use another AST node instead of CommonAST along
      with a past message(http://groups.yahoo.com/group/antlr-
      interest/message/3953).
      But on some rules (elements) I failed and ASTFactory raised an error
      under C#.NET:

      Unexpected exception: System.TypeLoadException: Unable to load AST
      Node Type: 'LocationAST'
      at antlr.ASTFactory.loadNodeTypeObject(String nodeTypeName)
      at antlr.ASTFactory.createFromNodeName(String nodeTypeName)
      at antlr.ASTFactory.create(Token tok, String ASTNodeTypeName)
      ...

      where 'LocationAST' is the class of my new node.

      I tried parser.ASTNodeClass() method but it didn't work neither.
      Does anyone know the cause of this problem?


      Thanks in advance,

      Takeo
    • Robin Debreuil
      Hi Takeo san, My guess would be you didn t specify the full namespace in the grammar... For example: CompileUnit ; should really be:
      Message 2 of 3 , Mar 31, 2004
        Hi Takeo san,

        My guess would be you didn't specify the full namespace in the grammar...
        For example:

        CompileUnit <AST=CompileUnit>;

        should really be:

        CompileUnit <AST=My.Full.Namespace.CompileUnit>;

        Maybe not though...

        Cheers,
        Robin
      • bonotake2004
        Hi, Robin san :-) ... grammar... ... You re right. Assigning full namespace works fine. Thanks! BTW, I found that, in #3953, line number was set to AST node
        Message 3 of 3 , Mar 31, 2004
          Hi, Robin san :-)

          --- In antlr-interest@yahoogroups.com, "Robin Debreuil" <robin@d...>
          wrote:
          > My guess would be you didn't specify the full namespace in the
          grammar...
          > For example:
          >
          > CompileUnit <AST=CompileUnit>;
          >
          > should really be:
          >
          > CompileUnit <AST=My.Full.Namespace.CompileUnit>;

          You're right. Assigning full namespace works fine. Thanks!

          BTW, I found that, in #3953, "line number" was set to AST node in
          constructor AST( Token t ), but it didn't work in this way.
          If you want to make it you have to set the number in overrided
          initialize methods, like the following (in C# manner):

          public override void initialize(Token t)
          {
          setText( t.getText() ); // transfer token text.
          setType( t.Type ); // transfer token type.
          iline = t.getLine(); // transfer token line number.
          }

          Cheers,
          Takeo
        Your message has been successfully submitted and would be delivered to recipients shortly.