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

Parehthesized compount statements #538

Open
Mesyanzhin opened this issue Apr 26, 2024 · 3 comments
Open

Parehthesized compount statements #538

Mesyanzhin opened this issue Apr 26, 2024 · 3 comments

Comments

@Mesyanzhin
Copy link

Mesyanzhin commented Apr 26, 2024

This expression are processed correctly:

            float __left_0 = (  {
              float __x1_1 = __K1;
              float __x2_1 = __K2;
              ( __x1_1 < __x2_1 ) ? __x1_1 : __x2_1;
            } );

But this valid expression

            float __df_3 = __iz_3 / (  {
              float __x1_4 = __T1;
              float __x2_4 = __T2;
              ( __x1_4 > __x2_4 ) ? __x1_4 : __x2_4;
            } );

causes a traceback with parsing error:

pycparser.plyparser.ParseError: :14:36: before: {

@eliben
Copy link
Owner

eliben commented Apr 29, 2024

Can you provide a minimal, complete reproducer?

@Mesyanzhin
Copy link
Author

Mesyanzhin commented May 10, 2024

Can you provide a minimal, complete reproducer?

pycparser version:

__version__ = '2.22'

Input:

from pycparser import c_parser, c_generator

src1 = '''
float f1( float __K1, float __K2 ) {
    float __left_0 = (  {
        float __x1_1 = __K1;
        float __x2_1 = __K2;
        ( __x1_1 < __x2_1 ) ? __x1_1 : __x2_1;
    } );
    return __left_0;
}
'''

src2 = '''
float f2( float __iz_3, float __T1, float __T2 ) {
    float __df_3 = __iz_3 / (  {
        float __x1_4 = __T1;
        float __x2_4 = __T2;
        ( __x1_4 > __x2_4 ) ? __x1_4 : __x2_4;
    } );
    return __df_3;
}
'''

def c2c(src):
    parser = c_parser.CParser()
    ast = parser.parse(src)
    generator = c_generator.CGenerator()
    return generator.visit(ast)

print(c2c(src1))
print(c2c(src2))

Output:

/home/artem/PycharmProjects/TestPy3/envs/bin/python /home/artem/PycharmProjects/TestPy3/c2c.py 
float f1(float __K1, float __K2)
{
  float __left_0 =   {
    float __x1_1 = __K1;
    float __x2_1 = __K2;
    (__x1_1 < __x2_1) ? (__x1_1) : (__x2_1);
  }
;
  return __left_0;
}


Traceback (most recent call last):
  File "/home/artem/PycharmProjects/TestPy3/c2c.py", line 32, in <module>
    print(c2c(src2))
  File "/home/artem/PycharmProjects/TestPy3/c2c.py", line 27, in c2c
    ast = parser.parse(src)
  File "/home/artem/PycharmProjects/TestPy3/pycparser/c_parser.py", line 147, in parse
    return self.cparser.parse(
  File "/home/artem/PycharmProjects/TestPy3/pycparser/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/home/artem/PycharmProjects/TestPy3/pycparser/ply/yacc.py", line 1199, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/home/artem/PycharmProjects/TestPy3/pycparser/ply/yacc.py", line 193, in call_errorfunc
    r = errorfunc(token)
  File "/home/artem/PycharmProjects/TestPy3/pycparser/c_parser.py", line 1945, in p_error
    self._parse_error(
  File "/home/artem/PycharmProjects/TestPy3/pycparser/plyparser.py", line 67, in _parse_error
    raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: :3:32: before: {

Process finished with exit code 1

@eliben
Copy link
Owner

eliben commented May 11, 2024

Thanks. This is probably not too hard to fix for someone motivated enough to dig into the code. PRs welcome :)

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

No branches or pull requests

2 participants