sammine-lang
Loading...
Searching...
No Matches
Grammar.md: A markdown file describing the grammar

Conventions

Terminal is Capitalized if multi-word, ALLCAPS if single word.

Non-terminal is bolden.

Non-terminal is not capitalized and uses _ as seperator (if any)

Grammar

program ::= (var_def | func_def)* func_main?

typed_var ::= ID : type

type ::= ID

var_def ::= LET typed_var ASSIGN expr SemiColon

func_def ::= FN ID LeftParen (typed_var (COMMA typed_var)*)? RightParen -> type block

def_block ::= LeftCurly stmt*** **return_stmt? RightCurly

block ::= LeftCurly **stmt*** RightCurly

stmt ::= simple_stmt
  | IF expr COLON block [ ELSE IF ]

simple_stmt ::= (expr | assign_expr) SemiColon

return_stmt ::= RETURN expr SemiColon

assign_expr ::= target ASSIGN expr

expr ::= cexpr
  | NOT expr
  | expr [AND | OR] expr

cexpr ::= ID
  | StringLiteral
  | LeftParen expr RightParen
  | member_expr
  | member_expr LeftParen (expr (COMMA expr)*)? RightParen
  | index_expr
  | ID LeftParen (expr (COMMA expr)*)? RightParen
  | cexpr bin_op cexpr
  | un_op cexpr
  | cexpr un_op

member_expr ::= cexpr DOT ID

index_expr ::= LeftBracket expr RightBracket

bin_op ::= + | - | * | / | % | += | -=
  | *= | /= | && | DoublePipe | SingularPipe |
  | ^ | << | >> | == | < | > | <= | >= | ** |
  | /_ | /^

target ::= ID
  | member_expr
  | index_expr

un_op ::= ++ | – | -