c - yylineno has always the same value in yacc file -


this question has answer here:

for 1 project in compilers have 1 problem in syntax analyzer, when go add symbol in symbol table, take same value in yylineno...

i did in begining:

%{      int yylex(void);     int yyerror(char* yaccprovidedmessage);         extern int yylineno;     //i declare yylineno lexical analyzer     extern char *yytext;     extern file *yyin;             int scope=0;       int max_scope; %} 

and in grammar when go add in symbol table:

i.e

lvalue: id {          printf("<-id");              add_data_to_symbol_table((char*)($1),scope,yylineno);         printf("lineno:%d",yylineno);          }         ; 

in output when give input different lines doesnt recognize new line

if(x<=2) {      if(t<1)     {         k=2;        } } 

the lineno never change,always have 1 value...

any ideas?

assuming using yylineno flex, should add line

%option yylineno 

to flex specification. beware not advisable export yylineno directly grammar, grammar may request ahead tokens tokenizer , yylineno may have been updated. professed way of handling yylineno through yylval. i've seen bison has new line-numbering features (see @1 , @@ etc.) integrates more effortlessly flex.

p.s: me talking bison, mentioned yacc. if committed yacc, pass through yylval.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -