Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!ukc!axion!uzi-9mm.fulcrum.bt.co.uk!simonp From: simonp@fulcrum.bt.co.uk (Simon Parsons) Newsgroups: comp.lang.c Subject: Re: Question about Lex Message-ID: Date: 30 May 91 08:10:50 GMT References: <1991May29.081912.16808@fel.tno.nl> Sender: news@fulcrum.bt.co.uk (News with an UZI) Organization: Fulcrum Communications Ltd., Birmingham, England Lines: 42 In-Reply-To: gtir5@fel.tno.nl's message of 29 May 91 08: 19:12 GMT In article <1991May29.081912.16808@fel.tno.nl> gtir5@fel.tno.nl (Ger Timmens) writes: Path: uzi-9mm.fulcrum.bt.co.uk!axion!ukc!mcsun!hp4nl!tnofel!felfs!gtir5 From: gtir5@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@fulcrum.bt.co.uk