windows flex/bison parser freeze

Started by
1 comment, last by assainator 10 years, 11 months ago

Hello all,

I've been trying to build a compiler for learning purposes. I'm creating the lexer with gnu flex and a parser with bison. I've been using these tools on Linux but my main development platform is windows (Visual Studio). But last week I ran into a problem: When I run the parser, the application freezes. If I pause the application (using VS' debugger pause) it always stops at the same location in the C library.

The callstack:

stackb.jpg

The line of code at which the application pauses:


        else if ( !ReadFile( (HANDLE)_osfhnd(fh), buffer, cnt, (LPDWORD)&os_read,
                    NULL ) || os_read < 0 || (size_t)os_read > cnt)

I validated that the stream is valid and is the correct file.

I'm using the gnuwin32 version of flex on windows to generate the lexer.

I've reduced the flex file to:


%{
#include <iostream>
using namespace std;

#include "muse.tab.h"

#define YY_DECL extern "C" int yylex()
%}

%option yylineno

%%
.* { std::cout << "hello"; return T_USING; }		;
%%


Is there anyone who has encountered this issue before?

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

Advertisement

Is there anyone who has encountered this issue before?

Not on Earth, but then again no one has ever made a parser that seeks .*.
Firstly, don’t do this. It matches 0 or more of any character, which means at the end of the file it can still keep matching things.
If you want to test it, just use ..


Even if that does not fix the problem, you should be able to fix it by loading the file manually and sending it as a byte stream. This is really better practice anyway for parsers and certainly a habit into which you will want to get for loading all types of things in the future.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Switching to parsing a byte stream fixed my issue. Thanks for the advice.

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

This topic is closed to new replies.

Advertisement