LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-08-2005, 06:11 AM   #1
fssengg
Member
 
Registered: Feb 2005
Location: Kerala(God's own country)
Distribution: Redhat-8
Posts: 35

Rep: Reputation: 15
Unhappy problem with yacc


hai
I am writing a program using lex & yacc.inspite of reading input from the standard input how can i take input to my program from a file say "dat"?
 
Old 03-08-2005, 11:53 PM   #2
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
One easy way is to just feed the file into your program after it's compiled. Like so:

Code:
program_name < file.dat
 
Old 03-09-2005, 05:07 AM   #3
fssengg
Member
 
Registered: Feb 2005
Location: Kerala(God's own country)
Distribution: Redhat-8
Posts: 35

Original Poster
Rep: Reputation: 15
Actually what i want is the program must read the file name and open that file.How is it possible?
 
Old 03-09-2005, 10:56 AM   #4
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Probably what I'd do, if there doesn't need to be much in the way of a main() function, is to add a main() to the yacc/bison input file, and open the file from there. The Lex and YACC HOWTO shows an example of writing your own main() function.

For reading files, C has fopen; you can then get input with fscanf or fgets. C++ has ifstream, which lets you use the >> stream input operator.

There's probably also a way to add the file-opening part to the (f)lex token-expansion definitions. I've used this before to create objects, assign pointers and stuff; you could probably expand this to include opening a file.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
does ubuntu have lex and yacc,how to use them?? akshay_jp Linux - Software 4 05-26-2010 06:36 PM
LEX and YACC with C gr33ndata Programming 4 11-18-2007 05:12 PM
Bison and Yacc Compatibility Problem oulevon Programming 1 10-23-2005 10:56 PM
yacc problem zchoyt Programming 0 03-23-2005 08:23 AM
yacc, Bison Config Linux - General 6 02-21-2002 02:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration