🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.utils.bug
Article #1619

Re: flex and yyleng

#1619
From: Vern Paxson
Date: Mon, 22 May 1989 18:55
33 lines
1577 bytes
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
Technical Details
Message-ID: <2699@helios.ee.lbl.gov>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!shelby!agate!helios.ee.lbl.gov!acacia.LBL.Gov!vern
References: <8905192245.AA15478@lanai.cs.ucla.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!shelby!agate!helios.ee.lbl.gov!acacia.LBL.Gov!vern
From: vern@acacia.LBL.Gov (Vern Paxson)
Newsgroups: gnu.utils.bug
Subject: Re: flex and yyleng
Message-ID: <2699@helios.ee.lbl.gov>
Date: 22 May 89 18:55:22 GMT
References: <8905192245.AA15478@lanai.cs.ucla.edu>
Sender: usenet@helios.ee.lbl.gov
Distribution: gnu
Lines: 33