Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

= and += #58

Closed
ProjectMoon opened this issue Aug 20, 2011 · 9 comments
Closed

= and += #58

ProjectMoon opened this issue Aug 20, 2011 · 9 comments
Labels

Comments

@ProjectMoon
Copy link

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

@zaach
Copy link
Owner

zaach commented Aug 20, 2011

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
reply@reply.github.com
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

@ProjectMoon
Copy link
Author

I see. Is this in the documentation at all?

@ProjectMoon
Copy link
Author

This has fixed the problem.

@zaach
Copy link
Owner

zaach commented Aug 26, 2011

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.

@neizod
Copy link

neizod commented Oct 15, 2011

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.

@ProjectMoon ProjectMoon reopened this Oct 16, 2011
@ProjectMoon
Copy link
Author

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

@zaach
Copy link
Owner

zaach commented Oct 16, 2011

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

zaach added a commit that referenced this issue Jan 20, 2012
@zaach
Copy link
Owner

zaach commented Jan 20, 2012

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.

@zaach zaach closed this as completed Jan 20, 2012
@neizod
Copy link

neizod commented Jan 21, 2012

wow! thank you for improving this. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants