help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bison location tracking ..


From: Laurence Finston
Subject: Re: bison location tracking ..
Date: Wed, 9 Jun 2004 13:26:34 +0200 (MEST)

On Tue, 8 Jun 2004, Vardhan Varma wrote:

> Hello,
>  From bison archives I got your email ..since you said
> you haven't had any unsolvable problems so far .. I
> thought may be you can suggset a way around
>

Thanks for the vote of confidence, but please do cc any follow-ups
to address@hidden --- someone might have a better answer.

> I've defined yylocation type to struct { offset, size
> }, and all that's working great.
>
> my problem is blank RHS .. offset gets set to zero.
> so  in rule like
> atoms:   /* blank */
>      | atoms ATOM
> since first blank rule gets fired, the offset & size
> are set to zero.
>
> Do you have any workaround/solution for this
>
> --Regards
> --Vardhan
>

Since there are no symbols on the right-hand side, there are no
`yylocation' structs for them, and no
address@hidden, @2, ... @n' items (or whatever they're called) to reference
them.

Normally, one needn't set the location of the rule (address@hidden') in this 
case,
because the position in the input stream won't have changed, since no new
tokens have been passed to `yyparse()'.

If you need to keep track of your position in the input stream independently of
the symbols on the right-hand sides of your rules, you can do this in the
object passed to `yyparse()', and from it to `yylex()', by means of the `void*'
parameter, if you're generating a reentrant parser.  I recommend generating a
reentrant parser anyway, even if one has no current plans to use multiple
threads and/or processes in one's application.

>
>
>
> PS: on your flex+file offset .. I too had the same
> problem .. found a workaround by reading  full file in
> buffer, using yy_scan_buffer(), and using
> yytet - buffer_address as the offset in file , Hope
> that helps.
>

>
> =====
> --
> Vardhan
>

My problem was that Flex swallowed characters from the input file under certain
circumstances.  Thanks for your suggestion, but I'm quite happy with my version
of `yylex()'.  I also certainly don't want to read
an entire input file, which might be huge, into a buffer, just for the sake of
being able to use Flex.  Nor would I want the added complication of reading it
in piecemeal.

Flex can work very well, and I use it for other purposes, but I think there are
sometimes good reasons for writing one's own version of `yylex()', particularly
for use in combination with Bison.

Laurence






reply via email to

[Prev in Thread] Current Thread [Next in Thread]