On 4 Apr 2013, at 14:48, Akim Demaille <a...@lrde.epita.fr> wrote:

> Le 3 avr. 2013 à 20:28, Hans Aberg <haber...@telia.com> a écrit :
> 
>> On 3 Apr 2013, at 04:52, Adam Smalin <acidzombi...@gmail.com> 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



_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to