help-flex
[Top][All Lists]
Advanced

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

Problem with C++ flex on Solaris


From: Greg Bronzert
Subject: Problem with C++ flex on Solaris
Date: Tue, 19 Feb 2002 13:47:37 -0500

Hi all,
 
I'm currently working on a parser and I've run into a strange problem
when compiling on a Sun. I'm using flex 2.5.4 to do the parsing in C++.
Everything works great on Windows and Linux (Redhat 7.1), but the parser
seems to hit an EOF immediately in any file I try to parse when compiled
on Sun Solaris.
 
To be more specific, the code that is auto-generated by flex doesn't
seem to properly read the input file and triggers an EOF immediately.
I've created a very simple parser to test this phenomenon. It simply
counts the lines in a file. When compiled on a Sun using flex 2.5.4 and
gcc 2.9.5, it always comes up with 0 lines... regardless of the input
file.  The program works fine when compiled on other platforms. The
source for the test program is at the bottom of this post.
 
I'm using the command: flex -+ -olex.yy.cpp lexer.cpp to compile the lex
code. I need the C++ feature of flex because I have to parse many files
of the same type into an object structure. I'm wondering if this bug is
specific to the C++ flex features. I tried a version of this test program that
didn't use the C++ option and it worked. I imagine it's a problem with
passing in the fstream object. I've tried several things, like changing all
istream references to std::istream, but none of it's worked.
 
I'd really appreciate any input on this, as this is my first time doing
a lot compiling on the Sun platform.  I've searched via google for any
similar problems, but I've come up blank.  I'm assuming it has something
to do with the Sun I/O libraries, but I'm not familiar with them at all.
 
Please contact me if you have suggestions,
Greg (address@hidden)
 
***********************************************************
%OPTION NOYYWRAP
%OPTION NEVER-INTERACTIVE
%OPTION STACK
 
%{
 
#define STRICT
#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>
#include <time.h>
 
// GLOBAL VARIABLES
int nline = 0;
// Include stack
 
%}
 
%x BASIC
 
alpha   [a-zA-Z]
dig             [0-9]
name            ({alpha}|{dig}|[_\-+<])({alpha}|{dig}|[>_.\-/$\{\}' ])*
num1            [-+]?{dig}+\.?([eE][-+]?{dig}+)?
num2            [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
number  {num1}|{num2}
type            (string|double|integer)
gen                     (exponential|uniform|periodic|trigger|SA)
ws                      [ \t]+
 
%%
%{
        BEGIN BASIC;
%}
<BASIC>.                ;
<BASIC>\n  nline++;
 
<<EOF>> {
                                cout << "EOF reached, terminating
                                scanner.\n";
                                yyterminate();
                                }
 
%%
 
int main( int argc, char *argv[] )
{
 
        ifstream *fin = '\0';
        char * filepath = NULL;
        FlexLexer *mlexer=NULL;
 
        if ( argc != 2 ) {
                cout << "File parameter required.\n";
                return 0;
        }
 
        filepath = argv[1];
 
        fin = new ifstream();
        fin->open( filepath, ios::nocreate);
        if ( !fin->is_open() ) {
                cerr << "\nCould not open File (" << filepath << ") for
                reading\n"; return false;
        }
        mlexer = new yyFlexLexer(fin);
        mlexer->yylex();
 
        delete mlexer;
        fin->close();
        delete fin;
 
        cout << nline << " lines in file.\n";
 
        return 0;
 
}
 
-----------------------------------------
Greg Bronzert
Mitre
address@hidden
Voice: (703) 883-2706
Fax: (703) 883-3308
 

reply via email to

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