help-bison
[Top][All Lists]
Advanced

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

Re: %prec doesn't seem to work?


From: Hans Aberg
Subject: Re: %prec doesn't seem to work?
Date: Thu, 4 Apr 2013 15:02:50 +0200

On 4 Apr 2013, at 14:48, Akim Demaille <address@hidden> wrote:

> Le 3 avr. 2013 à 20:28, Hans Aberg <address@hidden> a écrit :
> 
>> On 3 Apr 2013, at 04:52, Adam Smalin <address@hidden> wrote:
>> 
>>> ... I have no idea how i can fix this without rewriting it all.
>> 
>> Have you tried getting the lexer to emit two '>' when it sees a ">>", say by 
>> using an parenthesis-matching integer count?

> I'm not sure what you mean here, if you don't teach the scanner ">>" but ">",
> on ">>" it will return '>' and '>'.  I don't see what you mean with
> the counter.

One can check the correctness of matching pairs by having an integer, starting 
at 0, increased (resp. decreased) whenever an opening (resp. closing) pair is 
encountered. Matching is fine if one never gets below 0.

So the idea is that the lexer rule '<' increases an integer for this pair, and 
'>' decreases it. Then the lexer rule for ">>" checks if this integer is 
positive; if it is, it sets a flag, and emits a '>', decreasing the integer. 
The lexer first always checks if this flag is set, if it is, it resets the 
flag, decreases the integer, and emits '>'.

There is an additional complication: one needs to know when '<' is not a 
matching pair, in which case the integer should not be increased.   

Hans





reply via email to

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