Giter VIP home page Giter VIP logo

Comments (3)

zaach avatar zaach commented on August 15, 2024

Sort of. You can set flags during semantic actions for the lexer to observe and obey. The yy object can be used to share state within actions. Jison does not support actions mid-rule, though, so it would have to be broken up.

I've done similar things on the scanner level, where scanning certain tokens changes the state to modify the result of the next scan, but at the parser level you do get more contextual power.

But there's also a catch 22 situation that is related to issue #12. The lookahead token is used to determine if the parser should reduce, but the semantic action of the reduction may modify the state such that the next token is actually something different, as with lexical tie-ins.

Currently, any state modifications by the semantic action won't be seen by the lexer on the next token it shifts, because it was already shifted for the lookahead token and cached. Only on the token after next will the lexer observe the new state, so you can sort of do this today with a sort of token padding.

Perhaps the solution to this as well as #12 is to simply rescan the input after the actions runs. It just warps my mind that the lookahead token could be different than next actual token. I'll probably ask on the Bison list how this works also.

Hrmm, anyway, I'll work on this while resolving issue #12.

from jison.

zaach avatar zaach commented on August 15, 2024

Ah, I received a nice explanation from the Bison list. The key is that the lookahead token is not needed when there is only one possible action at a given state. So for lexical tie-ins, there should only be one possible action – a reduction – so the semantic action could execute before the lexer scans for the next token. I'll work on this tonight.

from jison.

zaach avatar zaach commented on August 15, 2024

Jison now supports proper lexical tie-ins since cf6a3b1

from jison.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.