Comments (3)
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.
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.
Jison now supports proper lexical tie-ins since cf6a3b1
from jison.
Related Issues (20)
- jison: command not found HOT 1
- %empty directive doesn't execute semantic actions, /* empty */ does HOT 2
- Using "constructor" as a literal causes a parse error
- Try online version should be updated to the latest current version
- It generates incorrect FOLLOWs and parsing table when using LL(1) algorithm.
- Security issue HOT 8
- Security Notice & Bug Bounty - Command Injection - huntr.dev HOT 1
- Create jison grammar
- Jison not assuming correct grammar HOT 1
- Generating code from parser result and grammar
- Missing tag
- Insufficient input validation in npm package jison <= 0.4.18 may lead to OS command injection attacks.
- A pathological example that blows up
- Tests generate SyntaxError: Function statements require a function name HOT 2
- Docs are offline HOT 7
- LALR(1) implementation is not LALR(1)
- Yacc/Lex compatible online editor/tester
- EOF token is returned only once in recursive grammar
- Enhance `showPosition()` to Accurately Display Error Position by Line Number
- Bug in docs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jison.