Thread View: gnu.utils.bug
2 messages
2 total messages
Started by Steven Berson
Fri, 19 May 1989 22:45
(none)
Author: Steven Berson
Date: Fri, 19 May 1989 22:45
Date: Fri, 19 May 1989 22:45
21 lines
808 bytes
808 bytes
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. The particular part of the code is: extern yyleng; . . . $$ = strcpy(malloc(yyleng+1),yytext); . . . Thanks, Steven Berson steven@cs.ucla.edu
Re: flex and yyleng
Author: Vern Paxson
Date: Mon, 22 May 1989 18:55
Date: Mon, 22 May 1989 18:55
33 lines
1577 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads