Next: , Previous: , Up: flex   [Contents][Index]


14 Values Available To the User

This chapter summarizes the various values available to the user in the rule actions.

char *yytext

holds the text of the current token. It may be modified but not lengthened (you cannot append characters to the end).

If the special directive %array appears in the first section of the scanner description, then yytext is instead declared to be an array of YYLMAX characters, where YYLMAX is a parameter that you can redefine with a %yylmax option if you don’t like the default value (generally 8KB). Using %array results in somewhat slower scanners, but the value of yytext becomes immune to calls to yyunput(), which potentially destroy its value when yytext is a character pointer. The opposite of %array is %pointer, which is the default.

You cannot use %array when generating C++ scanner classes (the ‘-+’ flag).

int yyleng

holds the length of the current token.

FILE *yyin

is the file which by default flex reads from. In target languages other than C/C++, expect it to have whatever native type is associated with I/O streams. It may be redefined but doing so only makes sense before scanning begins or after an EOF has been encountered. Changing it in the midst of scanning will have unexpected results since flex buffers its input; use yyrestart() instead. Once scanning terminates because an end-of-file has been seen, you can assign yyin to be the new input file and then call the scanner again to continue scanning.

void yyrestart( FILE *new_file )

may be called to point yyin at the new input file. In target languages other than C/C++, expect the argument to have whatever tyoe is associated with I/O streams. The switch-over to the new file is immediate (any previously buffered-up input is lost). Note that calling yyrestart() with yyin as an argument thus throws away the current input buffer and continues scanning the same input file.

FILE *yyout

is the output stream to which yyecho() actions are done. It can be reassigned by the user. In target languages other than C/C++, expect it to have whatever tyoe is associated with I/O streams.

yy_current_buffer()

returns a yybuffer handle to the current buffer.

yystart()

returns an integer value corresponding to the current start condition. You can subsequently use this value with yybegin() to return to that start condition.


Next: Interfacing with Yacc, Previous: Miscellaneous Controls, Up: flex   [Contents][Index]