-
Notifications
You must be signed in to change notification settings - Fork 0
Syntax
Literals are special immutable values. Any operation which might change the literal value means an error (e.g. 5++
).
The language support following types of expressions. Expression evaluation can yield a value of specified type, a reference to value or nothing. Some expression types might require sub-expressions which yields specific types. The syntax doesn't define operator priority.
Base expression type for constant value which can be used in complex expression.
Variable or constant name which references to some value.
Expression which consists two expressions and operator which will use the expressions. Required types of expression are dependent on operator itself.
binary_expression:
expression operator expression
Expression which consists an expression and operator which will be applied to the expression. Operator can be before expression (prefix) or after (suffix).
unary_expression:
expression
operator expression
expression operator
Expression for priority evaluation. Yields the same type as the inner expression.
paren_expression:
'(' expression ')'
Performs a function call. The first expression must yield an object which can be used to select a function to call. The argument expressions must yield types according to the type expected by the called function.
call_expression:
expression '(' ')'
expression '(' expression_list ')'
expression_list:
expression
expression ',' expression_list
Expression statements consists an expression. Statement without expression is called null expression and in result code it does nothing.
expression_statement:
';'
expression ';'
Declaration statements consists a declaration.
declaration_statement:
declaration
This kind of statement creates a new scope for statements.
block_statement:
'{' '}'
'{' statement_list '}'
statement_list:
statement
statement_list statement
Statement added as an extension to the parser. The main requirement is it must have an identifier as first token. This identifier is used by parser to identify the statement which should be parsed. The identifier must be unique. The important requirement is the rule must not overflow and all parsing paths must yield a valid statement AST node so the parser can properly continue in parsing following code.
extension_statement:
identifier ...
All declarations have common structure where it begins with identifier. Each declaration type must have unique identifier because it's used by parser to determine which declaration should parse. The basic syntax doesn't have any declaration specified and all must be defined as an extension.
restricted_declaration:
declaration
access_specifier declaration
declaration:
identifier ...
The access specified allows to restrict access to defined symbol. Specifier public
allows to anyone access the symbol. The private
restricts access to the symbol only to scope and subscopes where the declaration is specified.
access_specifier:
'public'
'private'