Sign in to follow this  
assainator

windows flex/bison parser freeze

Recommended Posts

assainator    685

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?

Share this post


Link to post
Share on other sites
L. Spiro    25619

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

Edited by L. Spiro

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this