Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

flex
I'm looking through lex and yacc documentaion, and it offers two
different functions input and unput to change the source of where lex
reads from.

They are:
int input(void)
{
char c;

if(targv >= arglim) return 0;

if((c = targv[0][offset++]) != '\0') return c;

targv++;
offset = 0;
return ' ';
}

and

void output(int ch)
{
if(ch == 0) return ;
if(offset) {
offset--;
return ;
}

targv--;

offset = strlen(*targv);
}

but using flex we have to use other means to change the
source from where it reads from.

This is done through modifying the macro YY_INPUT
by first undefing it then defining our own version.

what I am reading provides a modifiable version suitable for solving
the problem they present in the chapter.

It is as follows:

#undef YY_INPUT
#define YY_INPUT(buf, result, max)  (result = myinput(buf, max))

int myinput(char *buf, int max)
{
int len, copylen;

if(targv >= arglim)
return 0;

len = strlen(*targv) - offset;

if(len >= max)
copylen = max - 1;
else
copylen = len;

if(len > 0) memcpy(buf, targv[0] + offset, copylen);

if(targv[0][offset + copylen] == '\0') {
buf[copylen] = ' ';
copylen++;
offset = 0;
targv++;
}
return copylen;
}


It doesn't include an unput function because it
says that flex handles unput itself.

But my question is how? If I change the source of input
for flex and just provide it with a chunk of data(in this case
a continuous sequence of multibyte characters), then how does it manage
to handle the unput operation if need be?

--
j0mbolar


Report this thread to moderator Post Follow-up to this message
Old Post
j0mbolar
09-21-05 08:56 AM


Re: flex
j0mbolar schrieb:
[snip]
>
> But my question is how? If I change the source of input
> for flex and just provide it with a chunk of data(in this case
> a continuous sequence of multibyte characters), then how does it manage
> to handle the unput operation if need be?
>
> --
> j0mbolar
>

just take a look at the output of flex. It uses an intermediate buffer,
where it puts the data it gets from input. So it can handle unput,
by modifying the access offset to this buffer...

Tom

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Maier-Komor
09-27-05 12:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:05 AM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.