GithubHelp home page GithubHelp logo

Comments (6)

Addisonbean avatar Addisonbean commented on August 17, 2024 1

The #[no_reduce(LParen)] worked great, and then I was able to get it working with out that by looking further into that java compiler link your shared here. Thank you!

from plex.

goffrie avatar goffrie commented on August 17, 2024

There's already some support for this, though undocumented, haha. Look for
"overriding" and "no_reduce".

On Oct 18, 2016 19:24, "Yuki Izumi" [email protected] wrote:

This isn't a feature request, more feeling out: would you be interested in
a PR that added precedence operators to automatically solve shift–reduce
conflicts? (per bison's %left / %right / %nonassoc) If so, I might give
it a shot. (No guarantees I'm actually capable of it!)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#12, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABLtTrE3vbNDGrmAc7aeBI-vJQ-W2vcgks5q1X9igaJpZM4KafmF
.

from plex.

goffrie avatar goffrie commented on August 17, 2024

See https://github.com/rudi-c/cs444-java-compiler-in-rust/blob/master/ast/src/parser.rs for an old example of how I used them. If you want to improve the interface or make them more general, or whatever, that would be great!

from plex.

kivikakk avatar kivikakk commented on August 17, 2024

Great, will look at this tonight! Thanks :)

from plex.

Addisonbean avatar Addisonbean commented on August 17, 2024

Sorry if this is the wrong place for this, but I am getting a shift reduce conflict, and am unable to figure out how to use these macros to fix it. Here is the code:

expr: Expr {
    // #[overriding]
    Ident(var) Equals expr[rhs] => Expr {
        span: span!(),
        node: Expr_::Assign(var, Box::new(rhs)),
    },
    expr[e] LParen RParen => Expr {
        span: span!(),
        node: Expr_::FuncCall(e),
    },
    term[t] => t,
}

That second line, the one commented out, was my attempt at trying to solve the error, but that did nothing to fix it. Do you have any idea how I'd use these macros to fix this problem?

Here is the error:

error: shift-reduce conflict:
state: expr -> Ident Equals expr •
       expr -> expr • LParen RParen
token: LParen

Thank you for your time!

from plex.

goffrie avatar goffrie commented on August 17, 2024

So I believe you can fix this by using #[no_reduce(LParen)], but I don't recommend that as a proper solution. The normal way to fix this kind of issue in an LR grammar is to introduce precedence levels for different kinds of expressions (in this case, you'd want the function-call expression to have higher precedence than the assignment-expression). I don't know of a good reference to point you to off-hand, but any classical compiler textbook should cover this kind of thing. Hope this helps!

from plex.

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.