Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 {

 $


and in flex.l I write :

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


What I have tried:

I search on net but can't find what I want
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900