For development, I handled tree grammar error reporting with the following
code. It simply searches back in the token stream until it hits an input
token and uses that for location information. I also print out the token
index offset between the error token and the reporting token so I get an
idea of where the error occurred. Note that I stopped changing this as soon
it was working enough to allow debugging the tree grammar so don't expect
much.


  pANTLR3_COMMON_TOKEN searchToken = NULL;
  unsigned int testIndex = 0;
  if(ex->index > 0)
  {
    testIndex = ex->index - 1;
    pANTLR3_BASE_TREE searchBaseTree =
thisTreeNodeStream->get(thisTreeNodeStream,testIndex);
    searchToken = searchBaseTree->getToken(searchBaseTree);


    //If UP token
    if(errorToken->type == 3)
    {
      //Go back in the stream until we hit a token that is not UP and has a
column not -1
      while(searchToken->type == 3 || searchToken->charPosition == -1)
      {
        testIndex--; //FIXME - Maybe dangerous?
        searchBaseTree =
thisTreeNodeStream->get(thisTreeNodeStream,testIndex);
        searchToken = searchBaseTree->getToken(searchBaseTree);
      //printf("searchToken->toString
%s\n",searchToken->toString(searchToken)->chars);
      }

    }
    //If DOWN token
    else if(errorToken->type == 2)
    {
      //Go back in the stream until we hit a token that is not UP
      while(searchToken->type == 2)
      {
        testIndex--; //FIXME - Maybe dangerous?
        searchBaseTree =
thisTreeNodeStream->get(thisTreeNodeStream,testIndex);
        searchToken = searchBaseTree->getToken(searchBaseTree);
     // printf("searchToken->toString
%s\n",searchToken->toString(searchToken)->chars);
      }
    }
    //If no column info(imaginary token?)
    else if(errorToken->charPosition == -1)
    {
      //Go back in the stream until we hit a token that is not UP and has a
column not -1
      while(searchToken->type == 3 || searchToken->type == 2 ||
searchToken->charPosition == -1)
      {
        testIndex--; //FIXME - Maybe dangerous?
        searchBaseTree =
thisTreeNodeStream->get(thisTreeNodeStream,testIndex);
        searchToken = searchBaseTree->getToken(searchBaseTree);
      //printf("searchToken->user1 %d\n",searchToken->user1);
     // printf("searchToken->type %d\n",searchToken->type);
     // printf("searchToken->toString
%s\n",searchToken->toString(searchToken)->chars);
      }
    }
    else
    {
      searchToken = errorToken;
    }
  }
  //This must be the first node in the tree
  else
  {
    searchToken = errorToken;
  }

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

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to