Menu

#111 Init code not repeated in yyreset()

feature request
open
3
2015-02-15
2010-12-14
No

I'm just starting to learn about JFlex, so this might not be accurate.

Between %init{ and %init} one can place code to initialize user variables. The code is copied verbatim to the generated lexer's constructor.

Looking at the generated lexer source, I cannot find that initialization code in the yyreset(Reader) function, so the user variables are not reset with the rest of the lexer. But, if one manually implements line/column counting (as you recommend for performance reasons) for example, that counting should start from zero each time the lexer is reset. Therefore the init code should be repeated in the yyreset function.

Maybe it's meant to be so. There might be (resource demanding) things that you want to construct only once, not recreate on each reset. In that case an additional %reset directive might be necessary.

The obvious workaround is to construct a new lexer object on each parser reset.

Discussion

  • Gerwin Klein

    Gerwin Klein - 2010-12-14
    • milestone: 104412 --> feature request
    • priority: 5 --> 3
     
  • Gerwin Klein

    Gerwin Klein - 2010-12-14

    Hi Roland,

    repeating init code in yyreset would not be safe, it is meant for constructors and for setting up resources. Resetting something to an initial/neutral state is different.

    The standard procedure would indeed be to create a new Lexer object each time. This should be a cheap operation, all tables etc are static, so the objects to be created are small.

    yyreset is a performance optimisation for repeated scanning of very small strings or similar applications, not usually things where you would need to keep and reset state.

    That said, an additional %{reset directive would be reasonably easy to add. I'll think about that.

    Cheers,
    Gerwin

     
  • Roland Bluethgen

    > yyreset is a performance optimisation for repeated scanning of very small
    > strings or similar applications, not usually things where you would need to
    > keep and reset state.

    Ok, in this case I suggest to state that fact more clearly in the documentation.

    So long, Roland

     
  • Gerwin Klein

    Gerwin Klein - 2015-02-15