help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: yylineno


From: John W. Millaway
Subject: Re: yylineno
Date: Sun, 17 Jun 2001 10:03:20 -0700 (PDT)

> How do you (or would you) keep track of the token offset within the line?
> 

By this, do you mean the "column"?  If your tokens do not span lines,
then you can use yyleng. If the tokens do span lines,
then you have to rescan the token. Yuk!

%%
  /* This is untested code. But in the right spirit ! */
  static int yycol=0, next_col=0;
  char* _p;

  /* Update yycol for tokens that do not contain '\n' */
  #define COL()  yycol=next_col; next_col += yyleng

  /* Update yycol for tokens that may possibly contain '\n' */
  #define COLN() do{ \
                   yycol=next_col; \
                   for(_p=yytext; *_p; _p++,next_col++)  \
                      if( *_p == '\n' )  \
                         next_col = -1; \
                 }while(0)

  #define NEWL() yycol = next_col= 0

foo|bar  { COL();  printf("%d: %s\n" ,  yycol, yytext); }
\n       { NEWL(); printf("%d: NEWL\n", yycol); }
foo\nbar { COLN(); printf("%d: %s\n" ,  yycol, yytext); }

%%

-John



__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]