Member 12702368 Ответов: 0

Как я могу получить номер строки и столбца для каждого токена в antlr4?


I am new with antlr4 ... I search a lot to get number of line and column for each token in antlr4 ... I have a well knewoleadge on flex and bison and I make a complete compiler for php with flex and bison ... in flex and bison I was get the number of line and column by a simple code :

in bison.y I define struct :

    struct R{
        int i;
        float f;
        char c;
        char* str;
        int myLineNo;
        int myColno;

        }r;

namespace_name_parts: // rule 
      T_STRING {

 $


и в гибком.я пишу :

int lineNo = 1;
int colNo = 1;
"while"                   {

                               yylval.r.myLineNo= lineNo; 
                               yylval.r.myColno = colNo; 
                               colNo += strlen(yytext); 
                               return T_WHILE ;         
                          }


this way I can get the line of number and column with flex and bison ... NOTE : I need the line of number and column for print my own type checking error 

so can help me to get the number of line and column for each token in antlr4


Что я уже пробовал:

Я ищу в сети, но не могу найти то, что хочу

0 Ответов