[gnu.utils.bug] flex and yyleng

vern@acacia.LBL.Gov (Vern Paxson) (05/23/89)

In article <8905192245.AA15478@lanai.cs.ucla.edu>,
    steven@CS.UCLA.EDU (Steven Berson) writes:

> This is not a bug, but I have a yacc/lex pair that I would like to
> change to bison/flex.  I use yyleng (defined as extern) in my parser
> which should be defined by lex.  Is there some equivalent way to
> get the length of a token recognized by my lexical analyzer from
> flex.


flex makes yyleng available only within the scanner source file itself;
this is because it potentially is not a variable at all but instead a
macro (this will be the case with the next release, which I can finally
honestly say will be forthcoming Real Soon Now).  The motivation behind
this is to avoid the overhead (albeit small) of computing and storing
the value except when it's used.  So if you want to access the value
elsewhere, I'd suggest something like:

	%{
	extern int token_length;
	#define RETURN_LENGTH(val) { token_length = yyleng; return val; }
	%}
	...
	[a-z]+	RETURN_LENGTH(TOK_ID);
	...


		Vern


	Vern Paxson			      vern@csam.lbl.gov [lbl-csam.arpa]
	Real Time Systems		      ucbvax!csam.lbl.gov!vern
	Lawrence Berkeley Laboratory	      (415) 486-6580