Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Lex and Yacc

Posted on 1998-10-25
8
Medium Priority
?
228 Views
Last Modified: 2010-04-15
How do I get Lex and Yacc to read files for input?
0
Comment
Question by:laeuchli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1253817
Lex is a parser - you feed it a description of a grammar it is to read (such as C or C++) and it can parse that grammar.

Yacc (or Yet Another Compiler Compiler) uses Lex to parse a grammar which is fed back as a stream of tokens - yacc's purpose is to allow a 'compiler' to produce executables...

So you have to describe the grammar to lex, then use yacc (or yuour own program) to make use of the parsed input.

Start by having a really good read of the man pages for lex and yacc.

The GNU/Linux versions of these are Flex and Bison.

Cheers,

Raymond.
0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253818
I know how to program lex/yacc, I want to know how to feed it text files. Up to now I have been typeing in the info by hand.

0
 
LVL 3

Accepted Solution

by:
elfie earned 200 total points
ID: 1253819
If you are using one input file, you can use redirection:
eg. prog < input_file.

If you want to change your program, you can modify the function 'main'. Inside 'main' and fopen is done.
A normal way of working is parse the option of the program (eg add a -f option) and then pass the file name to the fopen call.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Author Comment

by:laeuchli
ID: 1253820
I don't quite understand please explain.

0
 
LVL 3

Expert Comment

by:elfie
ID: 1253821
When you are programming lex/yacc and you compile it, in some source there must be a main function. Normally inside this main function the input and output are opened.
If you can't find it , try doing a 'grep' in the source files.

So if you want to change the source files, first look for this function, then change it. When you are about to change it, a 'clean' solution is use argument parsing (eg. getopt) to parse (argc, argv).

need more info? explain what you don't understand, and we'll try to answer.
0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253822
I found the main but the part where the files are opened is not there.What do I do?
0
 
LVL 3

Expert Comment

by:elfie
ID: 1253823
can you do a grep for 'fopen' in the source files?

or

See which functions are called in the main functions and check the first few of them for an fopen call.

If no fopen can be found, check for the usage for a stdin filedescriptor.
0
 
LVL 5

Author Comment

by:laeuchli
ID: 1253824
ohh in the source files. I will look.Thanks.



0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question