The components of MetaSL are listed on the left in the following
table with the definition of the component given on the right. The
possible alternative definitions of each component are preceded by a dot
(•). A term in red is a link to its definition. Text in this
style represents MetaSL reserved words (for example,
enum) and symbols (for example, + and
*).
The following grammar is an incomplete description of MetaSL,
defining a superset of all valid MetaSL programs. Further restrictions
required by valid MetaSL programs are included in corresponding chapters
of the MetaSL specification. This
grammar also condenses the syntax description in the MetaSL
specification to better display patterns in the language for programmers
learning MetaSL. In any case where this representation of the syntax is
ambiguous, the MetaSL specification is the final authority.
| compilation_unit |
• global_declarations-list* |
| global_declaration |
• enum_declaration
• enum_set_declaration
• struct_declaration
• type_declaration
• function_declaration
• function_definition
• annotation_declaration
• constructor_definition
• destructor_definition
• shader_declaration
• graph_declaration
• compound_shader_declaration
• compound_bsdf_declaration
• bsdf_declaration
• technique_declaration |
| enum_declaration |
• enum identifier { enum_item_declarationc-list+ } ; |
| enum_item_declaration |
• identifier [= integer_literal] |
| enum_set_declaration |
• enum set identifier { set_element_declarationc-list+ } ; |
| set_element_declaration |
• identifier |
| struct_declaration |
• struct identifier { field_declarations-list* } ; |
| field_declaration |
• qualified_type fieldc-list+ ; |
| field |
• identifier [[ [const_expression] ]] |
| type_declaration |
• typedef qualified_type identifier ; |
| function_declaration |
• [native] qualified_type identifier ( parameterc-list* ) ;
• qualified_type operator operator ( parameterc-list* ) ; |
| constructor_declaration |
• [const | uniform | varying] identifier ( ) ; |
| destructor_declaration |
• [const | uniform | varying] ~ identifier ( ) ; |
| function_definition |
• [native] qualified_type scoped_name ( parameterc-list* ) compound_statement
• qualified_type operator operator ( parameterc-list* ) compound_statement |
| constructor_definition |
• [const | uniform | varying] scoped_name ( ) compound_statement |
| destructor_definition |
• [const | uniform | varying] [scope] ~ identifier ( ) compound_statement |
| parameter |
• [in | out | inout] qualified_type identifier [[ [const_expression] ]] |
| shader_declaration |
• [native] shader identifier [: identifier] { shader_member_declarations-list+ } [annotation] ; |
| shader_member_declaration |
• enum_declaration
• enum_set_declaration
• struct_declaration
• method_declaration
• constructor_declaration
• destructor_declaration
• method_definition
• constructor_definition
• destructor_definition
• parameter_declaration
• input :
• output :
• member : |
| parameter_declaration |
• [const | uniform] qualified_type ( shader_parameter [annotation] )c-list+ ; |
| shader_parameter |
• identifier [[ [const_expression] ]] [extern string] [= expression]
• identifier [[ [const_expression] ]] [extern string] [= { expression }]
• identifier ( expression ) [extern string] |
| graph_declaration |
• graph identifier { graph_member_declarations-list+ } [annotation] ; |
| graph_member_declaration |
• enum_declaration
• struct_declaration
• parameter_declaration
• class_instantiation
• instance_variable_declaration
• input :
• node :
• export : |
| class_instantiation |
• qualified_type identifier [( input_argumentc-list+ )] [annotation] ; |
| anonymous_instantiation |
• qualified_type ( input_argumentc-list* ) ; |
| input_argument |
• [state ::] parameter_selector : expression [annotation] |
| parameter_selector |
• identifier
• parameter_selector . identifier
• parameter_selector [ integer_literal ] |
| instance_variable_declaration |
• ( shader | bsdf | graph ) instance_variablec-list+ ; |
| instance_variable |
• identifier = expression
• identifier ( expression ) |
| compound_shader_declaration |
• shader identifier graph { compound_shader_member_declarations-list+ } [annotation] ; |
| compound_shader_member_declaration |
• enum_declaration
• struct_declaration
• parameter_declaration
• class_instantiation
• instance_variable_declaration
• input :
• output :
• node : |
| bsdf_declaration |
• [native] bsdf identifier { bsdf_member_declarations-list+ } [annotation] ; |
| bsdf_member_declaration |
• enum_declaration
• struct_declaration
• method_declaration
• constructor_declaration
• destructor_declaration
• method_definition
• constructor_definition
• destructor_definition
• parameter_declaration
• input :
• member : |
| compound_bsdf_declaration |
• bsdf identifier graph { compound_bsdf_member_declarations-list+ } [annotation] ; |
| compound_bsdf_member_declaration |
• enum_declaration
• struct_declaration
• parameter_declaration
• class_instantiation
• instance_variable_declaration
• anonymous_instantiation
• input :
• node :
• export : |
| technique_declaration |
• technique identifier : replacement_rulec-list+ [annotation] ; |
| replacement_rule |
• rule_source -> rule_target |
| rule_source |
• identifier |
| rule_target |
• identifier |
| method_declaration |
• [native] qualified_type identifier ( parameterc-list* ) ; |
| method_definition |
• [native] qualified_type identifier ( parameterc-list* ) compound_statement |
| variable_declaration |
• qualified_type ( variable [annotation] )c-list+ ; |
| variable |
• identifier [[ [const_expression] ]] [= expression]
• identifier [[ [const_expression] ]] [= { expression }]
• identifier ( expression ) |
| local_declaration |
• variable_declaration |
| statement |
• empty_statement
• expression_statement
• conditional_statement
• switch_statement
• while_statement
• do_while_statement
• for_statement
• foreach_statement
• break_statement
• continue_statement
• return_statement
• compound_statement |
| empty_statement |
• ; |
| expression_statement |
• expression ; |
| conditional_statement |
• if ( expression ) statement [else statement] |
| switch_statement |
• switch ( expression ) { switch_cases-list* } |
| switch_case |
• case expression : statements-list*
• default : statements-list* |
| while_statement |
• while ( expression ) statement |
| do_while_statement |
• do statement while ( expression ) |
| for_statement |
• for ( [expression] ; [expression] ; [expression] ) statement
• for ( variable_declaration [expression] ; [expression] ) statement |
| foreach_statement |
• foreach ( expression ) statement |
| break_statement |
• break ; |
| continue_statement |
• continue ; |
| return_statement |
• return [expression] ; |
| compound_statement |
• { ( local_declaration | statement )s-list* } |
| scope |
• identifier :: |
| scoped_name |
• [scope] identifier |
| qualified_name |
• [[[::] identifier] ::] identifier
• [::] state :: identifier
• [::] bsdf :: identifier |
| qualified_type |
• [[[::] identifier] ::] typename [[ [const_expression] ]] |
| expression |
• boolean_literal
• integer_literal
• float_literal
• set_literal
• string
• qualified_name
• expression .~identifier
• expression .~identifier ( [argument_list] )
• expression [ [expression] ]
• qualified_type [ ] ( [expression] )
• qualified_type ( [expression] )
• qualified_name ( [argument_list] )
• anonymous_instantiation
• expression ++
• expression –
• ++ expression
• – expression
• + expression
• - expression
• ! expression
• ~ expression
• expression * expression
• expression / expression
• expression % expression
• expression + expression
• expression - expression
• expression & expression
• expression ^ expression
• expression | expression
• expression in expression
• expression && expression
• expression || expression
• expression <= expression
• expression < expression
• expression >= expression
• expression > expression
• expression == expression
• expression != expression
• expression = expression
• expression += expression
• expression -= expression
• expression *= expression
• expression /= expression
• expression %= expression
• expression &= expression
• expression ^= expression
• expression |= expression
• expression ? expression : expression
• expression , expression
• ( expression ) |
| argument_list |
• ( expression | named_argument ) ( , named_argument )s-list* |
| named_argument |
• [in | out] [state ::] parameter_selector : expression |
| const_expression |
• expression |
| string |
• string_literals-list+ |
| set_literal |
• qualified_type { identifierc-list* } |
| operator |
• ! | ~ | * | / | % | + | - | & | ^ | | | in | && | || | <= | < | >= | > | == | !=
• = | += | -= | *= | /= | %= | &= | ^= | |= |
| annotation |
• { ( identifier ( [expression] ) ; )s-list* } |
| annotation_declaration |
• annotation identifier ( parameterc-list* ) ; |
| identifier |
An identifier is an
alphabetic character followed by a possibly empty sequence of
alphabetic characters, decimal digits, and underscores, that is
neither a typename nor a reserved word. |
| typename |
A typename has the same
lexical structure as an identifier, but is the
name of a built-in type or a type defined by the user with a structure, enumeration, or typedef
declaration. |
| boolean_literal |
• true • false |
| integer_literal |
Integer literals can be given in octal, decimal, or hexadecimal base.
A decimal literal is a non-empty sequence of decimal digits.
An octal literal is the digit zero followed by a non-empty sequence
of octal digits (the digits from zero to seven inclusive).
A hexadecimal literal is the digit zero, followed by the character
x or X, followed by a non-empty sequence of hexadecimal
digits, i.e. the decimal digits and the letters
a, b, c, d, e, f,
A, B, C, D, E, and F. |
| float_literal |
A floating point literal is a possibly empty sequence of decimal
digits, optionally followed by a decimal point (the character period)
and a possibly empty sequence of decimal digits, optionally followed
by an exponent given by the letter e or E, an optional
sign (- or +) and a non-empty sequence of decimal digits,
optionally followed by a type suffix. Either the decimal point or the
exponent need to be present. There has to be at least one digit
preceding or following the decimal point. The type suffix can be the
letter h, H, f, F, d, or D.
A floating-point literal with type suffix h or H is of
type half. A floating-point literal with type suffix f or
F is of type float. A floating-point literal with type
suffix d or D is of type double. A floating-point
literal without type suffix is of type float. |
| string_literal |
A string literal is a possibly empty sequence of characters not
including a double quote or escape sequences, enclosed in double
quotes. A string literal may not include a line ending. String
literals can be concatenated by juxtaposition. An escape sequence is
a backslash (\) followed by one of the following escape codes:
a alert (e.g., bell)
b backspace
f form feed
n newline
t horizontal tab
bs backslash
' single quote
“ double quote
|