/* Syntactic Description Language grammar in EBNF syntax: https://www.w3.org/TR/xml/#sec-notation */ /* References are either to sub-clauses or rules appearing in 14496-34 */ /* Lines indented by 4 spaces have been wrapped from the previous line */ /* 5.1 Character set */ non_zero_digit_character ::= [1-9] digit_character ::= 0 | non_zero_digit_character latin_character ::= [a-zA-Z] sdl_compatible_ucs_character ::= [#x0020-#x10FFFF] - #xFEFF - #x0085 - #x2028 - #x2029 universal_character_name ::= ('\u' four_hexadecimal_characters) | ('\U' four_hexadecimal_characters four_hexadecimal_characters) multiple_character_literal_character ::= [#x0020-#x007E] /* 5.4 Comments */ /* Rule S.1: Comments - until the end of the line */ /* Comments are treated as whitespace and therefore not included in the grammar as a token */ /* however a suitable rule for tokenization would be as follows */ /* comment ::= '//' (sdl_compatible_ucs_character | universal_character_name)* */ /* 5.5 Identifiers */ identifier_character ::= digit_character | latin_character | '_' /* An identifier must include at least one alphabetic character. */ identifier ::= identifier_character* latin_character identifier_character* /* 5.6 Punctuators */ open_parenthesis ::= '(' close_parenthesis ::= ')' open_brace ::= '{' close_brace ::= '}' open_bracket ::= '[' close_bracket ::= ']' colon ::= ':' semicolon ::= ';' comma ::= ',' double_quote ::= '"' single_quote ::= "'" /* 5.7 Keywords */ abstract ::= 'abstract' aligned ::= 'aligned' base64string ::= 'base64string' bit ::= 'bit' break ::= 'break' case ::= 'case' class ::= 'class' computed ::= 'computed' const ::= 'const' default ::= 'default' do ::= 'do' else ::= 'else' expandable ::= 'expandable' extends ::= 'extends' float ::= 'float' for ::= 'for' if ::= 'if' int ::= 'int' legacy ::= 'legacy' lengthof ::= 'lengthof' map ::= 'map' reserved ::= 'reserved' switch ::= 'switch' unsigned ::= 'unsigned' utf16string ::= 'utf16string' utf8string ::= 'utf8string' utf8list ::= 'utf8list' utfstring ::= 'utfstring' while ::= 'while' /* 5.8 Operators */ /* . class member access defined as part of class_member_access */ /* [] array element access defined as part of array_element_access */ postfix_increment ::= '++' postfix_decrement ::= '--' unary_plus ::= '+' unary_negation ::= '-' multiplication ::= '*' division ::= '/' modulus ::= '%' addition ::= '+' subtraction ::= '-' bitwise_shift_left ::= '<<' bitwise_shift_right ::= '>>' relational_less_than ::= '<' relational_less_than_or_equal ::= '<=' relational_greater_than ::= '>' relational_greater_than_or_equal ::= '>=' relational_equal ::= '==' relational_not_equal ::= '!=' bitwise_and ::= '&' bitwise_or ::= '|' logical_and ::= '&&' logical_or ::= '||' assignment ::= '=' postfix_operator ::= postfix_increment | postfix_decrement unary_operator ::= unary_plus | unary_negation multiplicative_operator ::= multiplication | division | modulus additive_operator ::= addition | subtraction shift_operator ::= bitwise_shift_left | bitwise_shift_right relational_operator ::= relational_less_than | relational_less_than_or_equal | relational_greater_than | relational_greater_than_or_equal equality_operator ::= relational_equal | relational_not_equal bitwise_operator ::= bitwise_and | bitwise_or logical_operator ::= logical_and | logical_or /* 5.9 Expressions and evaluation */ class_member_access ::= '.' identifier array_element_access ::= open_bracket expression close_bracket primary_expression ::= identifier | number_literal | open_parenthesis expression close_parenthesis postfix_expression ::= expression (array_element_access | class_member_access | postfix_operator)? | primary_expression unary_expression ::= unary_operator? (postfix_expression | lengthof_expression) multiplicative_expression ::= unary_expression (multiplicative_operator multiplicative_expression)? additive_expression ::= multiplicative_expression (additive_operator additive_expression)? shift_expression ::= additive_expression (shift_operator shift_expression)? relational_expression ::= shift_expression (relational_operator relational_expression)? equality_expression ::= relational_expression (equality_operator equality_expression)? bitwise_expression ::= equality_expression (bitwise_operator bitwise_expression)? expression ::= bitwise_expression (logical_operator expression)? /* Left hand operand must evaluate to a parsed variable value target */ /* Right hand operand must evaluate to a value source */ assignment_expression ::= expression assignment expression /* 5.10 Statements */ expression_statement ::= (expression | assignment_expression) semicolon /* Block scoping */ compound_statement ::= open_brace statement* close_brace statement ::= expression_statement | compound_statement | elementary_type_definition | map_definition | string_definition | class_definition | array_definition | computed_elementary_type_definition | computed_array_definition | if_statement | switch_statement | for_statement | do_statement | while_statement /* 5.11 Built-in operators */ /* Rule O.1: lengthof() Operator */ lengthof_expression ::= lengthof open_parenthesis expression close_parenthesis /* Rule O.2: Range operator */ range_operator ::= '..' /* 5.14 Binary literal values */ /* Rule S.2: Binary literal value */ binary_character ::= 0 | 1 binary_character_string ::= binary_character* four_binary_characters ::= binary_character binary_character binary_character binary_character one_to_four_binary_characters ::= binary_character binary_character? binary_character? binary_character? period_separated_binary_character_string ::= four_binary_characters '.' (four_binary_characters '.')* one_to_four_binary_characters binary_literal ::= '0b' (period_separated_binary_character_string | binary_character_string) /* 5.15 Hexadecimal literal values */ /* Rule S.3: Hexadecimal literal value */ hexadecimal_character ::= [0-9A-F] hexadecimal_character_string ::= hexadecimal_character* four_hexadecimal_characters ::= hexadecimal_character hexadecimal_character hexadecimal_character hexadecimal_character one_to_four_hexadecimal_characters ::= hexadecimal_character hexadecimal_character? hexadecimal_character? hexadecimal_character? period_separated_hexadecimal_character_string ::= four_hexadecimal_characters '.' (four_hexadecimal_characters '.')* one_to_four_hexadecimal_characters hexadecimal_literal ::= '0x' (period_separated_hexadecimal_character_string | hexadecimal_character_string) /* 5.16 Multiple character literal values */ /* Rule S.4: Multiple character literal value */ escaped_multiple_character_literal_character ::= (multiple_character_literal_character - single_quote - '\') | ('\' single_quote) | '\\' multiple_character_literal ::= (single_quote escaped_multiple_character_literal_character+ single_quote)+ /* 5.17 Integer, decimal and floating-point literal values */ positive_integer ::= non_zero_digit_character digit_character* integer_literal ::= 0 | positive_integer decimal_literal ::= integer_literal '.' digit_character+ floating_point_literal ::= (integer_literal | decimal_literal) 'e' (0 | (('+' | '-')? positive_integer)) /* One or more multiple character literals to support concatenation */ number_literal ::= binary_literal | hexadecimal_literal | multiple_character_literal | integer_literal | decimal_literal | floating_point_literal /* 5.18 String literal values */ escaped_sdl_compatible_ucs_character ::= (sdl_compatible_ucs_character - double_quote - '\') | ('\' double_quote) | '\\' utf_string_literal ::= ('u' double_quote (escaped_sdl_compatible_ucs_character | universal_character_name)* double_quote)+ /* 5.19 Scope */ /* computed_elementary_type_definition can only be const */ Specification ::= (class_declaration | map_declaration | computed_elementary_type_definition)* /* 6.2 Constant-length direct representation bit fields */ /* Rule E.1: Elementary data types */ aligned_modifier ::= aligned (open_parenthesis ('8' | '16' | '32' | '64' | '128') close_parenthesis)? elementary_type ::= int | unsigned int | float | bit length_attribute ::= open_parenthesis expression close_parenthesis /* Rule E.2: Look-ahead parsing */ /* Rule E.3: Legacy keyword */ /* Rule E.4: Reserved keyword */ /* 6.3 Variable length direct representation bit fields */ elementary_type_definition ::= (reserved | legacy)? const? aligned_modifier? elementary_type length_attribute '*'? identifier (assignment expression (range_operator expression)?)? semicolon /* 6.4 Constant-length indirect representation bit fields */ /* Rule E.3: Maps */ /* Rule E.4: Mapped data types */ /* 6.5 Variable length indirect representation bit fields */ /* Rule E.5: Maps with escape codes */ output_value ::= number_literal | elementary_type_output_value | aggregate_output_value elementary_type_output_value ::= elementary_type length_attribute aggregate_output_value ::= open_brace (output_value comma)* output_value close_brace map_entry ::= binary_literal comma aggregate_output_value map_declaration ::= map identifier open_parenthesis (elementary_type | identifier) close_parenthesis open_brace (map_entry comma)+ map_entry close_brace map_definition ::= (reserved | legacy)? (elementary_type | identifier) '<' identifier '>' identifier semicolon /* 6.6 Variable length strings */ /* Rule E.6: String data types */ base64_character ::= digit_character | latin_character | '+' | '/' base64_string_literal ::= (double_quote base64_character* '='? '='? double_quote)+ /* 6.7 String value */ /* One or more string literals to support concatenation */ utf16_string_definition ::= utf16string identifier (assignment utf_string_literal)? utf8_string_definition ::= (utf8string | utf8list) identifier (assignment utf_string_literal)? utf_string_definition ::= utfstring identifier (assignment utf_string_literal)? base64_string_definition ::= base64string identifier (assignment base64_string_literal)? string_definition ::= (reserved | legacy)? const? aligned_modifier? (base64_string_definition | utf16_string_definition | utf8_string_definition | utf_string_definition) semicolon /* 7.1 Classes */ /* Rule C.1: Classes */ /* Rule C.2: Class data types */ /* 7.2 Base and derived classes */ /* RULE C.3: Derived classes */ /* 7.3 Abstract classes */ /* Rule C.4: Abstract classes */ /* 7.4 Polymorphism in class declaration */ /* Rule C.5: Class polymorphism */ class_id ::= integer_literal class_id_range ::= class_id range_operator class_id extended_class_id_range ::= class_id | class_id_range (comma (class_id | class_id_range))* bit_modifier ::= colon bit open_parenthesis positive_integer close_parenthesis (identifier assignment)? extended_class_id_range /* 7.5 Expandable classes */ /* Rule C.6: Expandable classes */ expandable_modifier ::= expandable (open_parenthesis positive_integer close_parenthesis)? /* 7.6 Parameter types */ /* Rule C.7: Class parameter types */ parameter ::= (identifier | elementary_type) identifier parameter_list ::= open_parenthesis (parameter comma)* parameter close_parenthesis parameter_value_list ::= open_parenthesis (expression comma)* expression close_parenthesis extends_modifier ::= extends identifier parameter_value_list? class_declaration ::= aligned_modifier? expandable_modifier? abstract? class identifier parameter_list? extends_modifier? bit_modifier? open_brace statement* close_brace /* Rule C.8: Parameterized class data types */ class_definition ::= legacy? identifier identifier parameter_value_list? semicolon /* 7.7 Arrays */ /* Rule A.1: Arrays */ /* 7.8 Multi-dimensional arrays */ /* Rule A.2: Multi-dimensional arrays */ /* 7.9 Partial arrays */ /* Rule A.3: Partial arrays */ /* Rule A.4: Partial multi-dimensional arrays */ explicit_array_dimension ::= open_bracket expression close_bracket partial_array_dimension ::= open_bracket open_bracket expression close_bracket close_bracket /* 7.10 Implicit arrays */ /* Rule A.5: Implicit arrays */ implicit_array_dimension ::= open_bracket (positive_integer range_operator positive_integer)? close_bracket array_definition ::= (reserved | legacy)? aligned_modifier? ((elementary_type length_attribute) | identifier) identifier (implicit_array_dimension | (explicit_array_dimension | partial_array_dimension)+) semicolon /* 8 Computed variables */ /* 8.2 Elementary data types */ /* Rule NP.1: Elementary data types */ computed_elementary_type_definition ::= computed const? elementary_type identifier (assignment expression)? semicolon /* 8.3 Arrays */ /* Rule NP.2: Arrays */ /* 8.4 Multi-dimensional arrays */ /* Rule NP.3: Multi-dimensional arrays */ computed_array_definition ::= computed elementary_type identifier (explicit_array_dimension)+ semicolon /* 9 Syntactic flow control */ /* 9.1 Conditionals */ /* Rule FC.1: Flow control using if-then-else */ if_statement ::= if open_parenthesis expression close_parenthesis statement (else statement)? /* Rule FC.2: Flow control using switch */ case_clause ::= case number_literal colon ((statement* (break semicolon)?) | (open_brace statement* break semicolon close_brace))? default_clause ::= default colon statement* switch_statement ::= switch open_parenthesis expression close_parenthesis open_brace case_clause* default_clause? close_brace /* 9.2 Loops */ /* Rule FC.3: Flow control using for */ for_statement ::= for open_parenthesis ((assignment_expression semicolon) | computed_elementary_type_definition | semicolon) expression? semicolon (assignment_expression | expression)? close_parenthesis statement /* Rule FC.4: Flow control using do */ do_statement ::= do compound_statement while open_parenthesis expression close_parenthesis semicolon /* Rule FC.5: Flow control using while */ while_statement ::= while open_parenthesis expression close_parenthesis statement