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

C grammar should capture acceptable but non-standard C code #67

Open
bdamm opened this issue Nov 3, 2017 · 2 comments
Open

C grammar should capture acceptable but non-standard C code #67

bdamm opened this issue Nov 3, 2017 · 2 comments

Comments

@bdamm
Copy link

bdamm commented Nov 3, 2017

Production C code may be extended with non-standard grammars. For example:

  • "__attribute__((packed))" and "__attribute((suppress))" may be after parameters, type qualifiers, function declarations, and even anonymous unions. It's tempting to consider it a sub to Spacing given how widely declared it can be.
  • An empty file with nothing but comments is considered valid by at least clang and gcc. The grammar rejects it for requiring at least one ExternalDeclaration.
  • gcc (did not test clang) will accept a function declaration terminated with a SEMI:
int func() { /* code in here. Or not. */ }; // <-- Note the SEMI.
  • Also, a struct with an empty declarator is considered valid:
struct a { int b;  ;  };
  • "__inline" appears to be an acceptable alternative to "inline" for clang. Didn't test gcc on that one.
  • An "asm" keyword and a non-trivial grammar is allowed by gcc and clang (and they might not be quite the same grammar, not 100% sure yet.)
  • "\%" is parsed by gcc and clang as a valid escape (and is reduced to just %) but the grammar rejects this.
  • __attribute__((format(printf, blah, etc))) also see, but disallowed by the current grammar.

Once I figure out pull requests I can get provide a diff with all of these.

@bdamm
Copy link
Author

bdamm commented Nov 8, 2017

I'm going to go ahead and prepare a pull request for these changes. They should help the grammar be real-world useful, even though it won't any longer be strictly standards compliant.

@bdamm bdamm changed the title C grammar could capture accepted but non-standard C code C grammar should capture acceptable but non-standard C code Nov 9, 2017
bdamm pushed a commit to bdamm/peg that referenced this issue Nov 9, 2017
bdamm pushed a commit to bdamm/peg that referenced this issue Nov 9, 2017
bdamm pushed a commit to bdamm/peg that referenced this issue Nov 9, 2017
bdamm pushed a commit to bdamm/peg that referenced this issue Nov 9, 2017
bdamm pushed a commit to bdamm/peg that referenced this issue Nov 14, 2017
bdamm pushed a commit to bdamm/peg that referenced this issue Nov 14, 2017
@bdamm
Copy link
Author

bdamm commented Jul 23, 2019

I've done what I can, I decided not to address __attribute in the grammar and instead stripped it out in preprocessing. So no more work on this from me.

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

No branches or pull requests

1 participant