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. AB 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+0000U+D7FFU+E000U+10FFFF

Comments

LINE_COMMENT::=//  (U+000AEOF)BLOCK_COMMENT::=’/*’  (’*’’*’  [’/’]’/’’/’  [’*’]BLOCK_COMMENT)  ’*/’

White Spaces

WHITESPACE::=U+0009U+000BU+000DU+0020

Nil

NIL::=nil

Boolean

BOOLEAN::=truefalse

Number

There is no distinction between unsigned and signed integers.

INTEGER::=DEC_INTEGERBIN_INTEGEROCT_INTEGERHEX_INTEGERDEC_INTEGER::=(09)+BIN_INTEGER::=0b  (01)+OCT_INTEGER::=0o  (07)+HEX_INTEGER::=0x  (09afAF)+FLOAT::=DEC_INTEGER  ’.’  [’.’]DEC_INTEGER  ’.’  DEC_INTEGER’.’  DEC_INTEGER

String

STRING::=STRING_SINGLESTRING_DOUBLESTRING_SINGLE::=  STRING_SINGLE_CHAR  STRING_DOUBLE::="  STRING_DOUBLE_CHAR  "STRING_SINGLE_CHAR::=(\)\  (nrt\)STRING_DOUBLE_CHAR::=(\"#)’#’  [’{’]\  (nrt"\’#{’)

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::=NilLiteralBooleanLiteralIntegerLiteralFloatLiteralStringLiteralArrayLiteralRecordLiteralFunctionLiteralNilLiteral::=NILBooleanLiteral::=BOOLEANIntegerLiteral::=INTEGERFloatLiteral::=FLOATStringLiteral::=STRINGArrayLiteral::=[  Expr,’,’  ]RecordLiteral::=’(’  Ident  ’:’  Expr,’,’  ’)’

FunctionLiteral

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

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