String literal

Discussion in 'C Programming' started by h03Ein, Jan 20, 2008.

  1. h03Ein

    h03Ein Guest

    Hi!
    during my search on tokens in ANSI C I have found following
    specification for string literals based on regular expression in
    site http://www.lysator.liu.se/c/ANSI-C-grammar-l.html :
    L?\"(\\.|[^\\"])*\" which L stands for [a-zA-Z_] . can anyone explain
    what does it mean ? I know regex but I can't understand this
    specification. why L? . does it mean following input is correct:
    s"\a" for string literals. or what's exactly (\\.|[^\\"]) means. and
    so on...
    Thanks!
     
    h03Ein, Jan 20, 2008
    #1
    1. Advertising

  2. In article <>,
    h03Ein <> wrote:
    > during my search on tokens in ANSI C I have found following
    >specification for string literals based on regular expression in
    >site http://www.lysator.liu.se/c/ANSI-C-grammar-l.html :
    > L?\"(\\.|[^\\"])*\" which L stands for [a-zA-Z_] . can anyone explain
    >what does it mean ? I know regex but I can't understand this
    >specification. why L? . does it mean following input is correct:
    >s"\a" for string literals. or what's exactly (\\.|[^\\"]) means. and
    >so on...


    Notice that the L is not {L} like on the line

    {D}+{IS}? { count(); return(CONSTANT); }

    The L on the line is therefore not the meta variable standing
    for [a-zA-Z_] -- instead, in that location, it is a literal L. And the
    ? after the L indicates that the L is optional.

    \\ is the way that a literal backslash is specified. The . after
    that stands for any one character, so in a literal string, you can have
    \ followed by any character (including a double-quote that would normally
    end the string.)

    [^\\"] means any character except a backslash or a double-quote
    --
    "Any sufficiently advanced bug is indistinguishable from a feature."
    -- Rich Kulawiec
     
    Walter Roberson, Jan 20, 2008
    #2
    1. Advertising

  3. On Sun, 20 Jan 2008 09:12:37 -0800, h03Ein wrote:
    > Hi!
    > during my search on tokens in ANSI C I have found following
    > specification for string literals based on regular expression in site
    > http://www.lysator.liu.se/c/ANSI-C-grammar-l.html :
    > L?\"(\\.|[^\\"])*\" which L stands for [a-zA-Z_] .


    No, that's not what L stands for. I'm not sure why you thought that, but
    L just stands for the letter L.

    > can anyone explain
    > what does it mean ? I know regex but I can't understand this
    > specification. why L? . does it mean following input is correct: s"\a"


    Since s is not L, no, it does not mean that is correct.

    > for string literals. or what's exactly (\\.|[^\\"]) means. and so on...
    > Thanks!


    Try describing the syntax of string literals in words. For example, for
    an integer literal, I might write "a zero optionally followed by other
    octal digits, or a decimal non-zero digit optionally followed by other
    decimal digits, or 0x followed by hexadecimal digits, in any case
    optionally followed by a suffix which can be U, UL, ULL, L, or LL". (This
    is incomplete and so does not match the actual definition.) When you have
    done that, what do you get? Does it look a bit similar to the regex, or
    do you get something completely different?
     
    Harald van Dijk, Jan 20, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Prakash Prabhu

    String literal and String Object

    Prakash Prabhu, Aug 27, 2003, in forum: Java
    Replies:
    3
    Views:
    672
    John C. Bollinger
    Aug 27, 2003
  2. Replies:
    5
    Views:
    783
    Frank Schmitt
    Sep 22, 2003
  3. herrcho
    Replies:
    7
    Views:
    442
    Jack Klein
    Sep 26, 2003
  4. Replies:
    10
    Views:
    809
    Roland Pibinger
    Jan 24, 2007
  5. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    407
    Anonieko Ramos
    Sep 27, 2004
Loading...

Share This Page