473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Flex, Bison and ifstream

Hello,
is there a way to feed an ifstream to a parser generated with flex and
bison? I could see that flex wants a FILE* for reading, but I only
have an ifstream (actually and ifstream*) for input.
It seems that flex++ can use an ifstream; but how does the generated
lexer then work with bison?
Or is there a (portable) way to get a FILE* from an ifstream?

Thanks in advance,
Oliver Gerlich

PS: can you recommend an open news server for reading and posting to
this newsgroup (as a replacement for Google Groups)?

Sep 7 '05 #1
2 6551

ol***@gmx.de wrote:
Hello,
is there a way to feed an ifstream to a parser generated with flex and
bison? I could see that flex wants a FILE* for reading, but I only
have an ifstream (actually and ifstream*) for input.
It seems that flex++ can use an ifstream; but how does the generated
lexer then work with bison?


man flex

You can also use flex to generate a C++ scanner class, using
the -+
option (or, equivalently, %option c++), which is automatically
speci-
fied if the name of the flex executable ends in a $-1òù+òù,
such as flex++.
When using this option, flex defaults to generating the scanner
to the
file lex.yy.cc instead of lex.yy.c. The generated scanner
includes the
header file FlexLexer.h, which defines the interface to
two C++
classes.

....

yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
constructs a yyFlexLexer object using the given
streams for
input and output. If not specified, the streams default
to cin
and cout, respectively.

Sep 7 '05 #2
ol***@gmx.de writes:
is there a way to feed an ifstream to a parser generated with flex and
bison? I could see that flex wants a FILE* for reading, but I only
have an ifstream (actually and ifstream*) for input.


For Flex, you can provide a replacement YY_INPUT macro that reads from a
stream, instead of from the FILE* yyin.

%{
#undef YY_INPUT
#define YY_INPUT(buf,result,max) (result = a_stream.readsome(buf,max))
%}

This only works with Flex - it's not portable to AT&T Lex, MKS Lex, etc.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Sep 7 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Uwe Ziegenhagen | last post by:
Hello, my fellows and me implement a c++ tool that is able to divide blank/tab separated files into <number>, <text>, <c-singlelinecomment> and <multilinecomment>. So far it's not working bad,...
0
by: Tom Heathcote | last post by:
Apologies for posting a flex++ question rather than a C++ question, but there does not appear to be a flex++ newsgroup... I am trying to rebuild some old lexical scanner / analyzer code, which I...
8
by: pavel.orehov | last post by:
Hi, I am using flex and bizon to write HTTP parser. I am passing well flex and bison tools but can't compile their output. ================= Flex file (http_parser.lpp) ============== %{...
4
by: daniele.calisi | last post by:
Hi everyone, after some days spent in long searches with google, I still not have found a solution with this problem: I need to use flex (or flex++) and bison (but not bison++) in order to...
6
by: Volker Hetzer | last post by:
Hi! We are finding ourselves in a situation where we have to parse several more or less free format text files. In the past, on linux, we had flex and bison for generating very fast parsers for...
13
by: jc | last post by:
I have written a parser using bison and flex to read ASAP2 file for CAN communications. entire development was done in an unix environment and now the code is ready to be integrated to an existing...
2
by: eng.sharif | last post by:
i want use bison and flex in visual stdio 2005 for make small compiler by use Custom Build Rules in Visual C++ 2005 "FlexBison.rules file " but when i compile "example.y" i get error...
1
by: eng.sharif | last post by:
want use bison and flex in visual stdio 2005 for make small compiler by use Custom Build Rules in Visual C++ 2005 "FlexBison.rules file " but when i compile "example.y" i get error...
3
by: Tinkertim | last post by:
Hello to all, I've been using C for a long time however I'm about to take my first splash into making a parser. I have some interesting things to accomplish and I'm hoping to get some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.