Question about Lex

Simon Parsons simonp at fulcrum.bt.co.uk
Thu May 30 18:10:50 AEST 1991


In article <1991May29.081912.16808 at fel.tno.nl> gtir5 at fel.tno.nl (Ger Timmens) writes:

   Path: uzi-9mm.fulcrum.bt.co.uk!axion!ukc!mcsun!hp4nl!tnofel!felfs!gtir5
   From: gtir5 at fel.tno.nl (Ger Timmens)
   Newsgroups: comp.lang.c
   Date: 29 May 91 08:19:12 GMT
   Organization: TNO Physics and Electronics Laboratory
   Lines: 29

>   This is what I do:
>
>   1. lex lexcommands         /* ==> lex.yy.c */
>   2. cc lex.yy.c             /* ==> a.out    */
>   3. a.out < input > output  /* ==> output   */
>
>   I've got the following problem:
>   When I encounter a string in the file *input* I want to
>   generate an error message reporting the line number and
>   file.
>   However I cannot include the following in my *lexcommands* file:
>
>   "string"       fprintf(stderr,"Found *string* on line %d in %s.\n",
>			  __LINE__,__FILE__);
>
>   since this would report the line number in the file *lex.yy.c* !
>
>   Is there a solution to this problem ?
>   I've experimented with #line, but I did not succeed.

Within your lex script have a local line number counter,
and have a rule or part of a rule.

"\n"    { LineNo++; }

Therefore LineNo will always be correct.

Simon
--
        "Hey girl, as I've always said, I prefer your lips red, 
         Not what the good lord made, but what he intended."
                                                         
      Simon Parsons, Fulcrum Communications Ltd.- simonp at fulcrum.bt.co.uk



More information about the Comp.lang.c mailing list