help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parsing '\x00' -- appears to be the only thing preventing parsing bi


From: Chris verBurg
Subject: Re: Parsing '\x00' -- appears to be the only thing preventing parsing binary data
Date: Tue, 30 Mar 2021 14:01:54 -0700

Running bison (first) with -d should produce a bison.tab.h file, that your flex 
input should #include to get the definitions of %token names.

-Chris



> On Mar 30, 2021, at 1:34 PM, Stephen Taylor <stnh.email@icloud.com> wrote:
> 
> 
> That appears to give me an error in lex:
> 
> %option noyywrap                                                              
>                                                     
>                                                                               
>                                                     
> %%                                                                            
>                                                     
> \x00  { return ZERO; }                                                        
>                                                     
> .|\n  { return *yytext; }                                                     
>                                                     
> %%                                                                            
>                                                     
>        
> 
>
> Error:
> 
> flex -8 gmr.l
> gcc  -c lex.yy.c
> gmr.l: In function ‘yylex’:
> gmr.l:2:10: error: ‘ZERO’ undeclared (first use in this function); did you 
> mean ‘EIO’?
>  \x00  { return ZERO; }
>           ^~~~
>           EIO
> gmr.l:2:10: note: each undeclared identifier is reported only once for each 
> function it appears in
> Makefile:13: recipe for target 'lex.yy.o' failed
> make: *** [lex.yy.o] Error 1
> 
> 
> Bison likes it.
> Tried quoting the \x00 but thats not right it appears.
> 
> 
> 
>> On Mar 30, 2021, at 16:15, Chris verBurg <cheetomonster@gmail.com> wrote:
>> 
>> 
>> I don’t know how you’ve set up your flex/bison interface, but I’m guessing 
>> from your quoting that you have flex return each character as a token?  Can 
>> you special-case 0 to not have the token value 0?  That is, flex does this:
>> 
>> \x00  { return ZERO; }
>> 
>> And then in your grammar:
>> 
>> %token ZERO
>> 
>> and use ZERO instead of ‘\x00’?
>> 
>> (Note: typed this on a phone..not 100% sure the syntax is right.)
>> 
>> -Chris
>> 
>> 
>>> On Mar 30, 2021, at 12:37 PM, Stephen Taylor via Users list for the GNU 
>>> Bison parser generator <help-bison@gnu.org> wrote:
>>> 
>>> I am trying to parse binary files and obviously need to write rules that 
>>> include the 8-bit value 0x00 — flex appears to allow me to obtain an 8-bit 
>>> scanner using the -8 option. I seem to be able to use ‘\x01’ to ‘\xFF’ for 
>>> individual terminal symbols in Bison rules. Unfortunately, ‘\x00’ is used 
>>> to denote end of input. Looking at the output tables, there appears to be 
>>> no real reason to do this (other than convenience) and I am wondering if 
>>> anyone has a workaround? 
>>> Thanks !
>>> Steve
>>> 
>>> 
>>> 
>>> 
>> 
> 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]