Comments (9)
The lexer will return the first rule to match, so if "+" comes before
"+=", it will return the "+" token and then "=" as separate tokens.
Put the longer rules before the shorter ones to avoid that.
On Sat, Aug 20, 2011 at 12:53 PM, ProjectMoon
[email protected]
wrote:
This almost assuredly a problem where I don't understand quite how to use the lexer. My lexer specifies "=" as '=' and "+=" as 'PLUSEQUAL'.
However, the parser will fail with stuff like:
x += 5;
It will say expecting an = sign instead.
x = 5;
works fine. I'm guessing this has something to do with precedence that I'm missing. I'm using the jscore example. I added a lexer to the file.The grammar is here: https://gist.github.com/1159333
Reply to this email directly or view it on GitHub:
#58
Zach Carter
from jison.
I see. Is this in the documentation at all?
from jison.
This has fixed the problem.
from jison.
This is a good point, since flex will use the longest matching rule. I may expose an option to have it behave as flex does. Maybe in the future that behavior will be the default.
from jison.
I agree that the lexical part should match the longest rule. Since this makes grouping the same attribute easier.
Flex
%%
i(sabella)? { printf("noun"); }
is { printf("verb"); }
s { printf("alpb"); }
%%
Both i
and isabella
return noun
, while is
return verb
.
Jison
("i"("sabella")?) alert("noun")
("is") alert("verb")
("s") alert("alpb")
Both i
and isabella
still return noun
, but is
return noun
and then alpb
. To fix this, I need to forget the powerful regex and rewrite this code like:
("isabella") alert("noun")
("is") alert("verb")
("i") alert("noun")
("s") alert("alpb")
That's make the lexical part too heavy.
from jison.
Maybe this issue should be reopened since people are commenting on it.
from jison.
Yes, I'll leave this open until we have an option for longest rule matching.
from jison.
There's now a "flex" mode where the lexer uses the rule with the logest match. Just put:
%options flex
in your lexer grammar before the rules section.
from jison.
wow! thank you for improving this. :)
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.