Character literals

Character literals are symbols that represent single characters, and can take one of three different forms:

  1. enclosed by single quotes (')
  2. enclosed by double quotes (")
  3. prefixed by the pound sign (#)

Character Literals Enclosed By Single Quotes

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 Enclosed By Double 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 prefixed By The Pound Sign

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)

Examples

   'A'    '+'    ' '    ''''     '"'
   "A"    "+"    " "    "'"      """"
   #65    #43    #32    #39      #34

Syntax

   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:

  1. it's tedious to write out every possible printable character and
  2. the definition for a printable character depends on the character set being used.