String literal

H

h03Ein

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!
 
W

Walter Roberson

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
 
H

Harald van Dijk

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top