Introduction

This chapter describes the syntactic grammar of Syntek. It is split up into declarations, expressions, and statements.

Structure

Each token has it's own page, which contains an introduction with information about the token, the grammar of the token, examples of the token, and links to other tokens that got referenced.

Grammar Notation

Grammar in this chapter is displayed in a codeblock. The syntax of the grammar blocks only show the possible combinations. Implementations of the grammar may vary.

Identifiers

The following example declares that Foo is Bar followed by Baz:

Foo = Bar Baz

Lexical tokens

'var'

Or

A | B

Quantifiers

  • ? optional
  • * zero or more
  • + one or more

Grouping

( A B )

Global Grammar

This chapter needs to reuse a lot of tokens. The most common tokens are listed on this page. These tokens are building blocks for other tokens and don't have much meaning on their own.

Variable Location

VarLoc = Identifier ( '.' Identifier )*
Number
a.b
x.y.z

Generic Parameters

Param = Identifier ( 'extends' Type )?
GenericParams = '<' Param ( ',' Param )* '>'
<T>
<T1, T2>
<A, B, C>

<A extends B>
<A extends B<C>>
<A, B extends Array<A>>

Generic Arguments

GenericArgs = '<' Type ( ',' Type )* '>'
<Number>
<Number, Number>
<x.y>
<a.b, x.y>
<Array<Number>>
<Array<Number>, Array<Number>>

Type

Type = VarLoc GenericArgs? '[]'*
Number
Number[]
Number[][]
x.y
x.y[]
x.y[][]
Array<Number>
Array<Optional<Number>>
Array<Optional<Number>>[]

Block

Block = '{' ( Declaration | Expression | Statement )* '}'

Parameter List

Param = Identifier ':' Type
ParamList = '(' ( Param ( ',' Param )* )? ')'

Function Signature

FuncSig = 'function' GenericParams? Identifier ParamList ( ':' Type )?

More info: Function Declaration