- Should have been like this from the start - About 9x performance increase
NEK-Lang
High level Components
- Lexer: Transforms text into Tokens
- Parser: Transforms Tokens into Abstract Syntax Tree
- Interpreter (tree-walk-interpreter): Walks the tree and evaluates the expressions / statements
- Abstract Syntax Tree Optimizer
Language features
- General expressions
- Arithmetic operations
- Addition
X+Y - Subtraction
X-Y - Multiplication
X*Y - Division
X/Y - Modulo
X%Y
- Addition
- Unary operators
- Negate
-X
- Negate
- Parentheses
(X+Y)*Z - Logical boolean operators
- Equal
== - Not equal
!= - Greater than
> - Less than
< - Greater than or equal
>= - Less than or equal
<=
- Equal
- Bitwise operators
- Bitwise AND
X&Y - Bitwise OR
X|Y - Bitwise XOR
X^Y - Bitwise NOT
~X - Bitwise left shift
X<<Y - Bitwise right shift
X>>Y
- Bitwise AND
- Arithmetic operations
- Variables
- Declaration
- Assignment
- Statements with semicolon & Multiline programs
- Control flow
- While loop
while X { ... } - If else statement
if X { ... } else { ... }- If Statement
- Else statement
- While loop
- Line comments
// - Strings
- IO Intrinsics
- ReadLine
Grammar
Expressions
expr_primary = LITERAL | IDENT | "(" expr ")" | "-" expr_primary | "~" expr_primary
expr_mul = expr_primary (("*" | "/" | "%") expr_primary)*
expr_add = expr_mul (("+" | "-") expr_mul)*
expr_shift = expr_add ((">>" | "<<") expr_add)*
expr_rel = expr_shift ((">" | ">=" | "<" | "<=") expr_shift)*
expr_equ = expr_rel (("==" | "!=") expr_rel)*
expr_band = expr_equ ("&" expr_equ)*
expr_bxor = expr_band ("^" expr_band)*
expr_bor = expr_bxor ("|" expr_bxor)*
expr = expr_bor
Statements
stmt_loop = "loop" expr (";" expr)? "{" stmt* "}"
stmt_expr = expr ";"
stmt = stmt_expr | stmt_loop
Description
Languages
Rust
100%