Skip to content
Jiří Fatka edited this page May 7, 2018 · 15 revisions

Literals

Literals are special immutable values. Any operation which might change the literal value means an error (e.g. 5++).

Expressions

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.

Literal

Base expression type for constant value which can be used in complex expression.

Identifier

Variable or constant name which references to some value.

Binary

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

Unary

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

Paren

Expression for priority evaluation. Yields the same type as the inner expression.

paren_expression:
  '(' expression ')'

Function call

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

Statements

Expression statement

Expression statements consists an expression. Statement without expression is called null expression and in result code it does nothing.

expression_statement:
  ';'
  expression ';'

Declaration statement

Declaration statements consists a declaration.

declaration_statement:
  declaration

Block statement

This kind of statement creates a new scope for statements.

block_statement:
  '{' '}'
  '{' statement_list '}'

statement_list:
  statement
  statement_list statement

Other statements

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 ...

Declarations

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 ...

Access specifiers

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'