newbie question - lex

newbie question - lex

Post by necr » Wed, 18 Apr 2001 10:29:31



I am having some problems running anything I write in Lex.

I am a complete newbie on Lex and have a slight idea what I am doing in
UNIX. I am using UNIX on a Red Hat 5.1 machine if that helps.

All I would like to know is how to compile and run a file. I am not to
bothered what is in the file cause that is for me to learn, I am just having
problems getting it to run. This is everything I did.

In unix I typed:

vi file1.L

to create my lex file

I then inserted the following code:

%%example
Print("found example");

I then saved this (you can tell this is a University example cause it
probably doesn't even work).

Back in unix I did the following:

lex file.L

This produced a file called lex.yy.c

I now did the following:

cc -o file1 lex.yy.c -ll

At this point it pause then says:
Id: cannot open -ll : No such file or directory

So I take off -ll

It then says:
/usr/lib/crt1.o(.text+0x36): undefined reference to 'main'
/tmp/cca003821.o : In function 'yylex':
/tmp/cca003821.o(.text+0x2eb): underfined reference to 'yywrap'
/tmp/cca003821.o : In function 'input':
/tmp/cca003821.o(.text+0x9f7): underfined reference to 'yywrap'

So what went wrong?! How do I correct it and how do I get some silly lex
command to do something?

Could someone post a very simple guide on how to make a lex file, compile
and execute it, you will be helping out a very poor student who can't buy
any books :-)

Thanks
::necro::

 
 
 

newbie question - lex

Post by Anthony Borl » Wed, 18 Apr 2001 14:36:40



Quote:

> I am having some problems running anything I write in Lex.

> I am a complete newbie on Lex and have a slight idea what I am doing in
> UNIX. I am using UNIX on a Red Hat 5.1 machine if that helps.

> All I would like to know is how to compile and run a file. I am not to
> bothered what is in the file cause that is for me to learn, I am just
having
> problems getting it to run. This is everything I did.

> In unix I typed:

> vi file1.L

> to create my lex file

> I then inserted the following code:

> %%example
> Print("found example");

> I then saved this (you can tell this is a University example cause it
> probably doesn't even work).

> Back in unix I did the following:

> lex file.L

> This produced a file called lex.yy.c

> I now did the following:

> cc -o file1 lex.yy.c -ll

> At this point it pause then says:
> Id: cannot open -ll : No such file or directory

> So I take off -ll

> It then says:
> /usr/lib/crt1.o(.text+0x36): undefined reference to 'main'
> /tmp/cca003821.o : In function 'yylex':
> /tmp/cca003821.o(.text+0x2eb): underfined reference to 'yywrap'
> /tmp/cca003821.o : In function 'input':
> /tmp/cca003821.o(.text+0x9f7): underfined reference to 'yywrap'

> So what went wrong?! How do I correct it and how do I get some silly lex
> command to do something?

> Could someone post a very simple guide on how to make a lex file, compile
> and execute it, you will be helping out a very poor student who can't buy
> any books :-)

> Thanks
> ::necro::

The problem is in your command-line; try:

   cc lex.yy.c -ll -o file1

Now, as long as linker can find the library (call 'l'), your link stage
should now proceed correctly.

I hope this helps.

 
 
 

1. newbie lex question: parsing Postscript

I'm a newcomer to the lex tool, parsing Macintosh
generated postscript files for use on a UNIX print
spooler. Things like:

  "%%Title:"[^'\r']*          {printf("%s\n", yytext);}
  "%%Creator:"[^'\r']*        {printf("%s\n", yytext);}
  "%%For:"[^'\r']*            {printf("%s\n", yytext);}

and the like I want to send to stdout, I want to skip
over the rest or send it to /dev/null. In other words,
all that I want to appear on the output are these and
only these lines.

Currently, my printfs and even the stuff I don't want
appears in the output stream.
Is there a token I can put at the bottom of all these
to trap everything else and do a noop?

sed would be my first choice, but it chokes when it
doesn't see a \n in the input stream and gives up,
(Mac Postscript end of lines are just <cr>) thus the
matching up to [^'\r']* construct.

While we're at it. If anybody can point me to any ftp
site w/ Postscript job processing routines, it would
be greatly appreciated.

___________________________Ron Creamer_______________________________

   HQ: 501 Camridge Street              | Voice  : 617/374-6000
       Cambridge, MA 02141              | FAX    : 617/374-6020

2. ANONYMOUS+LOGON ??

3. lex newbie question

4. Using Atari partitions patch

5. Lex maximum - Error when compiling with "lex"

6. Answer Garden

7. newbie LEX problem

8. Domain server for ppp

9. lex question

10. lex question: how to set search specification at run-time

11. Simple lex v. yacc question

12. lex & nawk : Questions

13. LEX question