Table of Contents

Control Codes

Control Codes are single non-displayable characters that appear in the input stream. They are typically used by the consuming application to modify its own behavior or internal state, or to initiate Escape Sequences, Control Sequences, and Control Strings.

Control codes have character encodings in the ranges 0x00...0x1f (C0 control codes) and 0x80...0x9f (C1 control codes). The C0 codes were originally defined in ISO/IEC 646 (ASCII), and the C1 codes were originally defined in ECMA-48. Most control codes are "solitary", meaning that they exist as independent characters in the input stream, and they do not have any impact on the parsing of subsequent characters.

Using an extended Backus-Naur form (EBNF), solitary control codes can be described as follows:

<solitary-control-code> ::= <solitary-C0-code> | <solitary-C1-code>
<solitary-C0-code>      ::= 0x00...0x1a | 0x1c...0x1f
<solitary-C1-code>      ::= 0x80...0x8f | 0x91...0x97 | 0x99...0x9a

The remaining control codes are "introducers" or "terminators", meaning that they indicate the beginning or end of a variable-length sequence or control string in the input. These control codes are not themselves represented as parsed elements. Rather, it is the sequences and control strings they introduce or terminate that will be produced as structured elements by the parser. These codes and the elements they produce are the following:

Control Code API Symbol Associated Elements Description
0x1b ControlCode.ESC AnsiEscapeSequence Escape Sequence
0x90 ControlCode.DCS AnsiControlString
AnsiControlStringInitiator
Device Control String
0x98 ControlCode.SOS AnsiControlString
AnsiControlStringInitiator
Start of String
0x9b ControlCode.CSI AnsiControlSequence Control Sequence Introducer
0x9c ControlCode.ST AnsiControlString
AnsiControlStringTerminator
String Terminator
0x9d ControlCode.OSC AnsiControlString
AnsiControlStringInitiator
Operating System Command
0x9e ControlCode.PM AnsiControlString
AnsiControlStringInitiator
Privacy Message
0x9f ControlCode.APC AnsiControlString
AnsiControlStringInitiator
Application Program Command

The API symbols allow you to reference the control codes as named constants when writing application code. These particular symbols probably won't be needed when parsing input sequences because the parser will interpret the codes for you. But they can be helpful when constructing strings that will be sent to the parser or to an ANSI-compatible terminal.