Solved

How to mention in the lex grammar to give the input as a char[] and get output as char[]?

Posted on 2008-09-29
2
355 Views
Last Modified: 2013-11-18
I have written a lex grammar which takes the input from stdin and output to stdout. But I want to pass the input as char[] (eg: char *input_buffer, int input_length) and get output as char[] (eg: char *output_buffer, int output_length). Anyone please help me out this.
0
Comment
Question by:anton_shiban
  • 2
2 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 250 total points
Comment Utility
The obvious way would be to create a file with the string, and then feed that to the scanner (similar for output).

Alternatively, you could re-define the input() function (or the YY_INPUT macro for flex) to get your input from the string instead of the file stream.
There's no such thing for output though. But generally, the output of a scanner is fed to a parser (generated by yacc for example), so that shouldn't be an issue ... right ?
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
May I ask why you gave a B grade ? That usually means that something was missing in the answer and/or that something is still unclear. If so, please feel free to ask for clarification where needed.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now