flex
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > flex




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    flex  
j0mbolar


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-21-05 07:50 AM

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






[ Post a follow-up to this message ]



    Re: flex  
Thomas Maier-Komor


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-27-05 12:58 PM

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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:11 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register