Skip to content

Syntax Specification ​

Conventions ​

  1. Terminal symbols are written in roman font.
  2. Some special terminal symbols can be enclosed in ’single quotes’, or can be represented as a unicode literal like U+2B7F.
  3. Non-terminal syntactic symbols are written in italic font.
  4. Every non-terminal syntactic symbol names follow PascaleCase naming rule.
  5. Non-terminal lexemes are written in typewritter font.
  6. Every non-terminal lexeme names follow SCREAMING_SNAKE_CASE naming rule.
  7. EOF is a special lexeme denoting the end of input.
  8. ϵ denotes the empty string.
  9. A  B means A followed by B.
  10. A∣B means either A or B.
  11. An is a sequence of n iterations of A.
  12. A∗ is a sequence of zero or more iterations of A, which is equivalent to P::=ϵ∣A  P.
  13. A+ is a sequence of one or more iterations of A, which is equivalent to AA∗.
  14. A? is an zero or one occurrence of A, which is equivalent to ϵ∣A.
  15. ∼A denotes any Char except A. (Char is defined here)
  16. A  [B] denotes positive lookahead of B, meaning A followed by B.
  17. A  ∼[B] denotes negative lookahead of B, meaning A not followed by B.
  18. ⟨A,B⟩ is a sequence of zero or more iterations of A separated by B, ending with optional B, which is equivalent to (A  B)∗  A?.
  19. Production rules are written in the form of A::=B.

Lexical Structure ​

Note that Dyn's lexical structure has context-free grammar.

Characters ​

Char::=U+0000∣…∣U+D7FF∣U+E000∣…∣U+10FFFF

Comments ​

LINE_COMMENT::=//  ∼(U+000A∣EOF)∗BLOCK_COMMENT::=’/*’  (∼’*’∣’*’  ∼[’/’]∣∼’/’∣’/’  ∼[’*’]∣BLOCK_COMMENT)∗  ’*/’

White Spaces ​

WHITESPACE::=U+0009∣U+000B∣U+000D∣U+0020

Nil ​

NIL::=nil

Boolean ​

BOOLEAN::=true∣false

Number ​

There is no distinction between unsigned and signed integers.

INTEGER::=DEC_INTEGER∣BIN_INTEGER∣OCT_INTEGER∣HEX_INTEGERDEC_INTEGER::=(0∣…∣9)+BIN_INTEGER::=0b  (0∣…∣1)+OCT_INTEGER::=0o  (0∣…∣7)+HEX_INTEGER::=0x  (0∣…∣9∣a∣…∣f∣A…∣F)+FLOAT::=DEC_INTEGER  ’.’  ∼[’.’]∣DEC_INTEGER  ’.’  DEC_INTEGER∣’.’  DEC_INTEGER

String ​

STRING::=STRING_SINGLE∣STRING_DOUBLESTRING_SINGLE::=’  STRING_SINGLE_CHAR∗  ’STRING_DOUBLE::="  STRING_DOUBLE_CHAR∗  "STRING_SINGLE_CHAR::=∼(\∣’)∣\  (n∣r∣t∣’∣\)STRING_DOUBLE_CHAR::=∼(\∣"∣#)∣’#’  ∼[’{’]∣\  (n∣r∣t∣"∣\∣’#{’)

Template String ​

TEMPLATE_STRING::=TEMPLATE_STRING_HEAD  Expr  (TEMPLATE_STRING_BODY  Expr)∗  TEMPLATE_STRING_TAILTEMPLATE_STRING_HEAD::="  STRING_DOUBLE_CHAR∗  ’#{’TEMPLATE_STRING_BODY::=’}’  STRING_DOUBLE_CHAR∗  ’#{’TEMPLATE_STRING_TAIL::=’}’  STRING_DOUBLE_CHAR∗  "

Identifiers ​

XID_START and XID_CONTINUE are defined in Unicode Standard Annex #31.[1]

IDENT_OR_KEYWORD::=XID_START  XID_CONTINUE∗

The below are every keyword in Dyn. Reserved keywrods are NOT used yet, but they are reserved for future use and treated as just normal keywords.

LexemeSymbolReserved
KW_BREAKbreakX
KW_CONTINUEcontinueX
KW_ELSEelseX
KW_EXPORTexportO
KW_FALSEfalseX
KW_IFifX
KW_ITERiterX
KW_LETletX
KW_NILnilX
KW_OFofX
KW_RETURNreturnX
KW_TRUEtrueX
KW_USEuseO

Punctuations ​

LexemeSymbolReserved
RightBrace}X
PipePipe||X
Pipe|X
LeftBrace{X
RightBracket]X
NewLine\nX
LeftBracket[X
At@O
RightAngledBracketEqual>=X
RightAngledBracket>X
EqualEqual==X
Equal=X
LeftAngledBracketEqual<=X
LeftAngledBracket<X
Colon:X
SlashEqual/=X
Slash/X
DotDot..X
Dot.X
Arrow->X
MinusEqual-=X
Minus-X
Comma,X
PlusEqual+=X
Plus+X
AsteriskEqual*=X
Asterisk*X
RightParenthesis)X
LeftParenthesis(X
AndAnd&&X
PercentEqual%=X
Percent%X
BangEqual!=X
Bang!X

Syntectic Structure ​

Literals ​

Literals::=NilLiteral∣BooleanLiteral∣IntegerLiteral∣FloatLiteral∣StringLiteral∣ArrayLiteral∣RecordLiteral∣FunctionLiteralNilLiteral::=NILBooleanLiteral::=BOOLEANIntegerLiteral::=INTEGERFloatLiteral::=FLOATStringLiteral::=STRINGArrayLiteral::=[  ⟨Expr,’,’⟩  ]RecordLiteral::=’(’  ⟨Ident  ’:’  Expr,’,’⟩  ’)’

FunctionLiteral ​

FunctionParameters::=⟨Ident,’,’⟩FunctionLiteral::=(  ’(’  FunctionParameters  ’)’  )?  ->  Expr

  1. https://www.unicode.org/reports/tr31/ ↩︎