Giter VIP home page Giter VIP logo

Comments (9)

zaach avatar zaach commented on August 15, 2024

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.

ProjectMoon avatar ProjectMoon commented on August 15, 2024

I see. Is this in the documentation at all?

from jison.

ProjectMoon avatar ProjectMoon commented on August 15, 2024

This has fixed the problem.

from jison.

zaach avatar zaach commented on August 15, 2024

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.

neizod avatar neizod commented on August 15, 2024

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.

ProjectMoon avatar ProjectMoon commented on August 15, 2024

Maybe this issue should be reopened since people are commenting on it.

from jison.

zaach avatar zaach commented on August 15, 2024

Yes, I'll leave this open until we have an option for longest rule matching.

from jison.

zaach avatar zaach commented on August 15, 2024

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.

neizod avatar neizod commented on August 15, 2024

wow! thank you for improving this. :)

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.