简体   繁体   中英

C# grammar: What character is the “new line” character?

I am implementing my own Lexer and just had a look at how C# handles char literals: https://msdn.microsoft.com/en-us/library/aa691087(v=vs.71).aspx

The C# char grammer is described in the link above
It specifies that the "new line" character is not allowed as a character literal.
But it doesn't state what the "new line" character is.
From my perspective it could be one of the following:

  1. CR + LF (windows)
  2. LF (unix & mac)
  3. CR (mac)
  4. CR || LF || CR + LF (all of them)

Since one file could be created on fe mac and then be compiled on windows I tend to believe that the "new line" character matches the grammer in case 4. I remember VS asking me if I'd like to convert my line endings to match the windows line endings in some cases. Since we can decline that option it is possible to stick with whatever endings the file contains.
Can someone confirm case 4 or tell me that I'm wrong?

Indeed, it can be either CR or LF, and a few more, according to spec:

https://msdn.microsoft.com/en-us/library/aa664812(v=vs.71).aspx

new-line-character:
    Carriage return character (U+000D)
    Line feed character (U+000A)
    Line separator character (U+2028)
    Paragraph separator character (U+2029)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM