Character literals are symbols that represent single characters, and can take one of three different forms:
Character literals can be formed by enclosing, the character being represented, in single quotes. NOTE: Single quote characters, in character literals enclosed in single quotes, are represented by a pair of single quote characters. So
'A' represents the character A
and
'''' represents the character '
Character literals are case-sensitive so 'X' is not equal to 'x'.
NOTE: In Standard Pascal (ISO/IEC 7185) character literals must be enclosed in single quotes (').
Character literals can be formed by enclosing, the character being represented, in double quotes. NOTE: Double quote characters, in character literals enclosed by double quotes, are represented as a pair of double quote characters. So
"A" represents the character A
and
"""" represents the character "
This second form of character literals, is an extension to Standard Pascal, and is provided mainly to make it easy to represent characters containing single quotes (i.e. you can enclose character literals representing single quotes with double quotes without using double single quotes like "'" instead of ''''.
Character literals can be formed by prefixing, the ordinal value of the character being represented, by the pound sign (#). So
#65 represents the character with ordinal value 65 (i.e. A)
and
#9 represents the character with ordinal value 9 (i.e. the tab character)
'A' '+' ' ' '''' '"'
"A" "+" " " "'" """"
#65 #43 #32 #39 #34
character-literal = ''' string-element-one ''' |
'"' string-element-two '"' |
'#' character-code
character-code = digit-sequence
digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
digit-sequence = digit { digit }
printable-character = any character (including a space) that has a visual representation.
string-element-one = '''' | printable-character
string-element-two = '""' | printable-character
NOTE: The production for printable-character doesn't use the usual notation because: