Related articles |
---|
Problem with GIF file scanner (flex) kxn@dcs.ed.ac.uk (1997-01-25) |
Re: Problem with GIF file scanner (flex) WStreett@shell.monmouth.com (1997-01-26) |
Re: Problem with GIF file scanner (flex) vern@daffy.ee.lbl.gov (1997-01-29) |
From: | kxn@dcs.ed.ac.uk (Kristian Nilssen) |
Newsgroups: | comp.compilers |
Date: | 25 Jan 1997 22:10:06 -0500 |
Organization: | Department of Computer Science, University of Edinburgh |
Keywords: | flex, question, comment |
The following flex code is supposed to scan a GIF file. A GIF file
begins with a Header and then a Logical Screen Descriptor. For some
unknown reason, flex will not enter the Logical_Screen_Descriptor
state. Also, am I right in using the character class [\x00-\xff] to
represent ANY 8bit char as found in a GIF file?
CODE...
byte [\x00-\xff]
%x Header Logical_Screen_Descriptor
%%
%{
BEGIN Header;
%}
<Header>"GIF89a" {
BEGIN Logical_Screen_Descriptor;
printf("Lexer: Header: yytext is %s\n", yytext);
printf("HEADER\n");
return(HEADER);
}
<Logical_Screen_Descriptor>{byte} {
unput(yytext[0]);
read_logical_screen_descriptor();
if(gif_ptr->gct_present) {
BEGIN Global_Colour_Table;
}
else {
BEGIN Data;
}
printf("LOGICAL_SCREEN_DESCRIPTOR\n");
return(LOGICAL_SCREEN_DESCRIPTOR);
}
INPUT...
GIF89aHm blah blah lots of freaky characters blah.
OUTPUT...
--scanner backing up
--(end of buffer or a NUL)
--accepting rule at line 44 ("GIF89a")
Lexer: Header: yytext is GIF89a
HEADER
--scanner backing up
--(end of buffer or a NUL)
--scanner backing up
--(end of buffer or a NUL)
--scanner backing up
--(end of buffer or a NUL)
--scanner backing up
--(end of buffer or a NUL)
--accepting rule at line 56 ("H")
Lexer: Unrecognised header H
HEADER
parse error
Cheers,
Kristian.
[Hmmn. People don't often use flex for scanning non-text data, so you may
have tripped over a bug. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.