Getting pointer declarations

  ant, antlr4, c++, python-3.x

I’m parsing C++ using ANTLR4 grammars and I have a basic code that I cannot get without having too much noisy/unrelated output.

The code I’m trying to parse is simple,

Person *p;
char *buf;
int *i;

I tried visiting on multiplicativeExpression, PointerDeclarator etc but I either didn’t get useful result or I was getting very verbose result.

I knew what I want is like anything * anything; so I tried to modify the grammar like below

ptrDeclarator: expressionStatement (pointerOperator Const?)* expressionStatement;

But I wasn’t able to get any result when visiting ptrDeclarator.

Can you please tell me how can I get simple pointer declarations?

Thanks

Source: Windows Questions C++

LEAVE A COMMENT