Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #148112

Re: How to parse attributes?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: How to parse attributes?
Date 2019-11-21 20:41 -0800
Organization None to speak of
Message-ID <lnwobsy12n.fsf@kst-u.example.com> (permalink)
References <qr2u7d$lo5$1@solani.org> <cded955b-2b9f-456b-84bc-4f2fb97aad9f@googlegroups.com> <qr5m0u$f6g$1@solani.org> <87blt47is6.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Philipp Klaus Krause <pkk@spth.de> writes:
>> I guess the main problem is that I am not really familiar with lex /
>> yacc. The situation with the attribute is a bit different from string
>> literals though:
>>
>> 1) Inside a string literal, everything is just text. The inside of the
>> attribute still should be tokenized.
>
> ... and parsed.
>
>> 2) [ is atoken that has many uses in C. We don't really know we're in an
>> attribute while in lex, that knowledge is only there yacc.
>
> It would have been simpler to handle if [[ had been made a new
> punctuator.  That would not be odd; both + and ++ are distinct tokens.
> However, it seems an attribute specification starts with two separate [
> tokens, so if you need to use lex start conditions to alter the lexing
> inside [[ and ]], you will need to use a yacc action to trigger that.
> Ask in a yacc/bison group to get the details.

Two consecutive [ tokens can't appear in a valid C program (prior to the
presumed introduction of attributes in C20), but two consecutive ]
tokens can.  Making [[ but not ]] a single token would have been odd.
Making both [[ and ]] single token without any other changes would break
expressions like a[b[i]].

There is precedent in C++ for dealing with nested <> template
delimiters, but that was needed because >> is already a token.  Any
problems with [[ and ]] didn't require such a solution.

> But I am not 100% sure you have to do this.  What is your source for
> keywords being regarded as identifiers?  In the usual C grammar, the
> rule for "identifier" is very general (the usual letters and digits
> definitions), but keywords are considered to be a separate category.
> Thus the grammar item "identifier" really means "things that have the
> right form but which aren't keywords".

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2455.pdf (C20 draft)
6.7.11.1p3:

    An attribute specifier that contains no attributes has no
    effect. The order in which attribute tokens appear in an
    attribute list is not significant. 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.
    A strictly conforming program using a standard attribute remains
    strictly conforming in the

N2454 is the newest working draft, released November 18, 2019.
N2455 is the same thing with markings for changes relative to C17.

I'm not sure why they didn't just forbid keywords in attribute tokens.
Perhaps there are attributes in existing implementations (as extensions)
that use keywords.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to parse attributes? Philipp Klaus Krause <pkk@spth.de> - 2019-11-20 09:41 +0100
  Re: How to parse attributes? David Brown <david.brown@hesbynett.no> - 2019-11-20 10:05 +0100
    Re: How to parse attributes? Philipp Klaus Krause <pkk@spth.de> - 2019-11-20 11:05 +0100
      Re: How to parse attributes? David Brown <david.brown@hesbynett.no> - 2019-11-20 12:35 +0100
  Re: How to parse attributes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-20 11:06 +0000
  Re: How to parse attributes? Öö Tiib <ootiib@hot.ee> - 2019-11-20 23:16 -0800
    Re: How to parse attributes? Philipp Klaus Krause <pkk@spth.de> - 2019-11-21 10:39 +0100
      Re: How to parse attributes? Öö Tiib <ootiib@hot.ee> - 2019-11-21 02:51 -0800
        Re: How to parse attributes? James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-11-21 05:00 -0800
      Re: How to parse attributes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-22 02:21 +0000
        Re: How to parse attributes? Keith Thompson <kst-u@mib.org> - 2019-11-21 20:41 -0800
          Re: How to parse attributes? Philipp Klaus Krause <pkk@spth.de> - 2019-11-22 09:15 +0100
          Re: How to parse attributes? David Brown <david.brown@hesbynett.no> - 2019-11-22 09:48 +0100
            Re: How to parse attributes? "A. K." <minforth@arcor.de> - 2019-11-22 02:00 -0800
              Re: How to parse attributes? David Brown <david.brown@hesbynett.no> - 2019-11-22 11:41 +0100
              Re: How to parse attributes? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-11-24 14:02 +0000
                Re: How to parse attributes? raltbos@xs4all.nl (Richard Bos) - 2019-11-25 16:21 +0000
            Re: How to parse attributes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-22 17:46 +0000
              Re: How to parse attributes? Keith Thompson <kst-u@mib.org> - 2019-11-22 10:53 -0800
                Re: How to parse attributes? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-23 00:08 +0000
    Re: How to parse attributes? scott@slp53.sl.home (Scott Lurndal) - 2019-11-21 15:57 +0000
    Re: How to parse attributes? Bonita Montero <Bonita.Montero@gmail.com> - 2019-11-22 08:21 +0100
    Re: How to parse attributes? Bart <bc@freeuk.com> - 2019-11-22 12:11 +0000

csiph-web