Git Product home page Git Product logo

Comments (10)

inducer avatar inducer commented on July 17, 2024

Sorry--I don't currently have time to look at or help with this. But I'd be happy to take a patch.

from pycparserext.

maximumspatium avatar maximumspatium commented on July 17, 2024

I have the same issue. I need pycparserext to parse a real-world C source code (QEMU) with uses GNU extensions. It chokes on function prototypes containing pointer to pointer params like this:

typedef struct Error {
    int dummy;
} Error;
void func_with_pp_param(const char *, Error **);

Adding a name to the last param, i.e.

void func_with_pp_param(const char *, Error **p);

makes the parsing magically work. Vanilla CParser works as well.

Any chances to get a support for such constructs in pycparserext?

from pycparserext.

inducer avatar inducer commented on July 17, 2024

Sure, I'd be happy to review a patch.

from pycparserext.

maximumspatium avatar maximumspatium commented on July 17, 2024

After spending several evenings learning PLY basics, I suspect some conflict in the pycparser/pycparserext grammar. Pycparserext:state107 behaves differently compared to pycparser:state77. That's where the things actually go wrong. My bet is that commenting out p_xxx_declarator_2 resolves that conflict.

To be able to spot the issue, one need to analyze low-level PLY parsing tables which is beyond my current knowledge level. Anyway, I'll continue to investigate.

BTW, enabling debug output with the following code:

gnu_parser = GnuCParser(yacc_debug=True)

dumps a lot of conflict warnings:

Generating LALR tables
WARNING: 121 shift/reduce conflicts
WARNING: 8 reduce/reduce conflicts
WARNING: reduce/reduce conflict in state 224 resolved using rule (primary_expression -> gnu_statement_expression)
WARNING: rejected rule (statement -> gnu_statement_expression) in state 224

I'm not sure how serious they are and whether the original parser has them too...

from pycparserext.

inducer avatar inducer commented on July 17, 2024

Those do look significant. Also, thanks for pointing out yacc_debug=True--I did not know about this. I don't have a lot of time to debug this myself, but I welcome any progress you might be able to make. One aspect of this is that pycparser is a moving target, so these may have crept in as the code kept changing out from under pycparserext.

from pycparserext.

jackrosenthal avatar jackrosenthal commented on July 17, 2024

I should have a fix ready in PR #37

from pycparserext.

maximumspatium avatar maximumspatium commented on July 17, 2024

@jackrosenthal Thank you for fixing that! This issue was a major roadblock in a project I'm working on. I'll test your fix later today and report the result.

from pycparserext.

maximumspatium avatar maximumspatium commented on July 17, 2024

@jackrosenthal I just tested your fix - it works like a charm, even for complex sources like QEMU. Unit tests (python -m pytest) do pass as well. Thank you very much!

@inducer Andreas, would you kindly merge the PR #37? I'll in turn contribute an appropriate unit test covering this corner case.

from pycparserext.

inducer avatar inducer commented on July 17, 2024

@maximumspatium Done. I would much appreciate a PR with a unit test for this. Thanks for offering.

from pycparserext.

inducer avatar inducer commented on July 17, 2024

Closing via merge of #37.

from pycparserext.

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.