Menu

#2951 keyword in attributes

open
nobody
None
Front-end
5
2020-08-19
2019-11-19
No

SDCC currently does not allow the use of keywords in attributes, e.g.

[[const::int]] i++;

will result in a compiler error.

However, the current C2X standard draft states " If a keyword (6.4.1) that satisfies the syntactic requirements of an identifier (6.4.2) is contained in an attribute token, it is considered an identifier."

I don't know how we should implement this in the parser / lexer.

Philipp

Discussion

  • Sergey Belyashov

    In same way as block comments and string literals, imho.

     
    • Philipp Klaus Krause

      Attributes are more complicated:

      • Comments and string litzerals start with a single token (/* or // or ") while attributes start with a token sequence ([ [). So in the lexer, we know if we are in a string literal or comment, but for attributes we only know later in the parser.
      • Comments and string literals can be seen as just a basic sequence of characters, until their end at the lexing and parsing stage (the escape sequences can be handled by later stages) while attributes do have a grammar that needs to be parsed.
       
      • Sergey Belyashov

        Can it be parsed later? By separate parser for example.

         
        • Philipp Klaus Krause

          I think that should be possible. Interaction between comments and attributes might still be a minor issue, but probably solveable.

           
      • Benedikt Freisen

        Can a sequence of two opening brackets occur anywhere else?
        I'm not sure, but I've never seen that in the wild.
        Maybe one could turn them into a separate token.

         
        • Philipp Klaus Krause

          I don't think there is another use for two subseqent opening brackets (unlike two subseqquent closing brackets, which is common).
          Just keep in mind that the two brackets are not trivial to recognize, as there could be whitespace or comments in between them.

           
          • Benedikt Freisen

            An arbitrary sequence of whitespace and comments would still be a regular language, though, wouldn't it?

             
            • Philipp Klaus Krause

              It would.

               

Log in to post a comment.

Auth0 Logo