Skip to content

Latest commit

 

History

History
134 lines (105 loc) · 1.3 KB

SPEC.md

File metadata and controls

134 lines (105 loc) · 1.3 KB

Helium programming language

TODO

Grammar

Bool : 'true' | 'false' ;

Integer : 0 | [1-9][0-9]* ;

Real : Integer '.' [0-9]* ;

Identifier : [_a-zA-Z][_a-zA-Z0-9]* ;

ValidSymbol
: [^\n\t\r\'\"\\]
| Escape
;

// TODO
Escape
: '\' (ValidSymbol|'\''|'"'|'\\')
;

Space : '\n' | '\t' | '\r' ;

// TODO
String
: '"' (ValidSymbol|'\''|Space)* '"'
;

// TODO
Char
: '\'' (ValidSymbol|'"') '\''
;

Program : EOL* Decls? EOL* EOF ;

Decls
: Decl
| Decls EOL+ Decl
;

Decl
: Stmt
;

Stmt
: VarStmt
| Expr
;

Pattern
: TypedPattern
| InferredPattern
;

TypedPattern
: Identifier EOL* ':' EOL* Type
;

InferredPattern
: Identifier
;

// TODO: make type initializer optional
VarStmt
: 'var' Pattern EOL* '=' Expr
;

Type
: IDENTIFIER
;

Expr
: Assignment
;

// s.t. change
Assignment
: Assignable '=' Assignment
| Addition
;

Addition
: Multiplication (('+'|'-') Multiplication)*
;

Multiplication
: Unary (('*'|'/') Unary)*
;

Unary
: ('-'|'+') Unary
| Primary
;

Primary
: Identifier
| Integer
| Real
| String
| Bool
| Char
| '(' EOL* Expr EOL* ')'
| IfExpr
| BlockExpr
| WhileExpr
| UnitExpr
;

UnitExpr
: 'unit'
;

Assignable
: Identifier
;

IfExpr
: 'if' '(' EOL* Expr EOL* ')' Expr (EOL* 'else' Expr)?
;

BlockExpr
: '{' EOL* Stmts? EOL* '}'
;

Stmts
: Stmt
| Stmts EOL+ Stmt
;

WhileExpr
: 'while' '(' EOL* Expr EOL* ')' Expr
;